Commit 6dc5de9cdd26e1c4e1aef67de897d16eb8c965c7
1 parent
a2451996
Add GRmf arithmetic operators
Showing
10 changed files
with
420 additions
and
45 deletions
ChangeLog
| ... | ... | @@ -5,6 +5,7 @@ |
| 5 | 5 | |
| 6 | 6 | Add GPha arithmetic operators and scale access methods |
| 7 | 7 | Add GArf arithmetic operators |
| 8 | + Add GRmf arithmetic operators | |
| 8 | 9 | Add GEbounds equality and inequality operators |
| 9 | 10 | Fix OpenMP segfault issue when fetching CTA events (#2192) |
| 10 | 11 | Correct GModelSpatialComposite::copy_members() bug. | ... | ... |
NEWS
| ... | ... | @@ -66,6 +66,15 @@ The following methods have been added: |
| 66 | 66 | - operator*(GArf&, double&) |
| 67 | 67 | - operator*(double&, double&) |
| 68 | 68 | - operator/(GArf&, double&) |
| 69 | +- GRmf::operator+=(GRmf&) | |
| 70 | +- GRmf::operator-=(GRmf&) | |
| 71 | +- GRmf::operator*=(double&) | |
| 72 | +- GRmf::operator/=(double&) | |
| 73 | +- operator+(GRmf&, GRmf&) | |
| 74 | +- operator-(GRmf&, GRmf&) | |
| 75 | +- operator*(GRmf&, double&) | |
| 76 | +- operator*(double&, double&) | |
| 77 | +- operator/(GRmf&, double&) | |
| 69 | 78 | |
| 70 | 79 | The following methods have been removed: |
| 71 | 80 | - n.a. |
| ... | ... | @@ -176,6 +185,9 @@ factors. |
| 176 | 185 | Added arithmetic operatirs for GArf class to add, subtract, scale and divide |
| 177 | 186 | Auxiliary Response Files. |
| 178 | 187 | |
| 188 | +Added arithmetic operatirs for GRmf class to add, subtract, scale and divide | |
| 189 | +Redistribution Matrix Files. | |
| 190 | + | |
| 179 | 191 | |
| 180 | 192 | 17. Test module |
| 181 | 193 | --------------- | ... | ... |
doc/source/admin/release_history/1.5.rst
| ... | ... | @@ -30,8 +30,10 @@ Bug fixes |
| 30 | 30 | Improvements |
| 31 | 31 | ------------ |
| 32 | 32 | |
| 33 | +* Add ``GPha`` arithmetic operators and scale access methods | |
| 34 | +* Add ``GArf`` arithmetic operators | |
| 35 | +* Add ``GRmf`` arithmetic operators | |
| 33 | 36 | * Add ``GEbounds`` equality and inequality operators |
| 34 | -* Add ``GPha`` arithmetic operators | |
| 35 | 37 | * Improve efficiency of ``GGti::contains()`` method |
| 36 | 38 | * [`2191 <https://cta-redmine.irap.omp.eu/issues/2191>`_] - |
| 37 | 39 | Add ``GFitsTableCol::scale()`` method | ... | ... |
include/GRmf.hpp
| ... | ... | @@ -53,6 +53,13 @@ namespace gammalib { |
| 53 | 53 | ***************************************************************************/ |
| 54 | 54 | class GRmf : public GBase { |
| 55 | 55 | |
| 56 | + // Operator friends | |
| 57 | + friend GRmf operator+(const GRmf& a, const GRmf& b); | |
| 58 | + friend GRmf operator-(const GRmf& a, const GRmf& b); | |
| 59 | + friend GRmf operator*(const GRmf& rmf, const double& scale); | |
| 60 | + friend GRmf operator*(const double& scale, const GRmf& rmf); | |
| 61 | + friend GRmf operator/(const GRmf& rmf, const double& scale); | |
| 62 | + | |
| 56 | 63 | public: |
| 57 | 64 | // Constructors and destructors |
| 58 | 65 | GRmf(void); |
| ... | ... | @@ -63,6 +70,10 @@ public: |
| 63 | 70 | |
| 64 | 71 | // Operators |
| 65 | 72 | GRmf& operator=(const GRmf& rmf); |
| 73 | + GRmf& operator+=(const GRmf& rmf); | |
| 74 | + GRmf& operator-=(const GRmf& rmf); | |
| 75 | + GRmf& operator*=(const double& scale); | |
| 76 | + GRmf& operator/=(const double& scale); | |
| 66 | 77 | double& operator()(const int& itrue, const int& imeasured); |
| 67 | 78 | const double& operator()(const int& itrue, const int& imeasured) const; |
| 68 | 79 | |
| ... | ... | @@ -281,4 +292,84 @@ const GFilename& GRmf::filename(void) const |
| 281 | 292 | return (m_filename); |
| 282 | 293 | } |
| 283 | 294 | |
| 295 | + | |
| 296 | +/***********************************************************************//** | |
| 297 | + * @brief Redistribution Matrix File addition operator friend | |
| 298 | + * | |
| 299 | + * @param[in] a First Redistribution Matrix File. | |
| 300 | + * @param[in] b Second Redistribution Matrix File. | |
| 301 | + * @return Sum of Redistribution Matrix Files. | |
| 302 | + ***************************************************************************/ | |
| 303 | +inline | |
| 304 | +GRmf operator+(const GRmf& a, const GRmf& b) | |
| 305 | +{ | |
| 306 | + GRmf result = a; | |
| 307 | + result += b; | |
| 308 | + return result; | |
| 309 | +} | |
| 310 | + | |
| 311 | + | |
| 312 | +/***********************************************************************//** | |
| 313 | + * @brief Redistribution Matrix File subtraction operator friend | |
| 314 | + * | |
| 315 | + * @param[in] a First Redistribution Matrix File. | |
| 316 | + * @param[in] b Second Redistribution Matrix File. | |
| 317 | + * @return Difference of Redistribution Matrix Files. | |
| 318 | + ***************************************************************************/ | |
| 319 | +inline | |
| 320 | +GRmf operator-(const GRmf& a, const GRmf& b) | |
| 321 | +{ | |
| 322 | + GRmf result = a; | |
| 323 | + result -= b; | |
| 324 | + return result; | |
| 325 | +} | |
| 326 | + | |
| 327 | + | |
| 328 | +/***********************************************************************//** | |
| 329 | + * @brief Redistribution Matrix File scaling operator friend | |
| 330 | + * | |
| 331 | + * @param[in] rmf Redistribution Matrix File. | |
| 332 | + * @param[in] scale Scale factor. | |
| 333 | + * @return Scaled Redistribution Matrix File. | |
| 334 | + ***************************************************************************/ | |
| 335 | +inline | |
| 336 | +GRmf operator*(const GRmf& rmf, const double& scale) | |
| 337 | +{ | |
| 338 | + GRmf result = rmf; | |
| 339 | + result *= scale; | |
| 340 | + return result; | |
| 341 | +} | |
| 342 | + | |
| 343 | + | |
| 344 | +/***********************************************************************//** | |
| 345 | + * @brief Redistribution Matrix File scaling operator friend | |
| 346 | + * | |
| 347 | + * @param[in] scale Scale factor. | |
| 348 | + * @param[in] rmf Redistribution Matrix File. | |
| 349 | + * @return Scaled Redistribution Matrix File. | |
| 350 | + ***************************************************************************/ | |
| 351 | +inline | |
| 352 | +GRmf operator*(const double& scale, const GRmf& rmf) | |
| 353 | +{ | |
| 354 | + GRmf result = rmf; | |
| 355 | + result *= scale; | |
| 356 | + return result; | |
| 357 | +} | |
| 358 | + | |
| 359 | + | |
| 360 | +/***********************************************************************//** | |
| 361 | + * @brief Redistribution Matrix File vision operator friend | |
| 362 | + * | |
| 363 | + * @param[in] rmf Redistribution Matrix File. | |
| 364 | + * @param[in] scale Division factor. | |
| 365 | + * @return Divided Redistribution Matrix File. | |
| 366 | + ***************************************************************************/ | |
| 367 | +inline | |
| 368 | +GRmf operator/(const GRmf& rmf, const double& scale) | |
| 369 | +{ | |
| 370 | + GRmf result = rmf; | |
| 371 | + result /= scale; | |
| 372 | + return result; | |
| 373 | +} | |
| 374 | + | |
| 284 | 375 | #endif /* GRMF_HPP */ | ... | ... |
pyext/GRmf.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GRmf.i - XSPEC Redistribution Matrix File class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2013-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -46,6 +46,12 @@ public: |
| 46 | 46 | GRmf(const GRmf& rmf); |
| 47 | 47 | virtual ~GRmf(void); |
| 48 | 48 | |
| 49 | + // Operators | |
| 50 | + GRmf& operator=(const GRmf& rmf); | |
| 51 | + GRmf& operator+=(const GRmf& rmf); | |
| 52 | + GRmf& operator-=(const GRmf& rmf); | |
| 53 | + GRmf& operator*=(const double& scale); | |
| 54 | + | |
| 49 | 55 | // Methods |
| 50 | 56 | void clear(void); |
| 51 | 57 | GRmf* clone(void) const; |
| ... | ... | @@ -83,6 +89,31 @@ public: |
| 83 | 89 | int __len__() { |
| 84 | 90 | return (self->size()); |
| 85 | 91 | } |
| 92 | + GRmf __add__(const GRmf& rmf) const { | |
| 93 | + return ((*self) + rmf); | |
| 94 | + } | |
| 95 | + GRmf __sub__(const GRmf& rmf) const { | |
| 96 | + return ((*self) - rmf); | |
| 97 | + } | |
| 98 | + GRmf __mul__(const double& scale) const { | |
| 99 | + return ((*self) * scale); | |
| 100 | + } | |
| 101 | + // Python 2.x | |
| 102 | + GRmf __div__(const double& scale) const { | |
| 103 | + return ((*self) / scale); | |
| 104 | + } | |
| 105 | + GRmf __idiv__(const double& scale) { | |
| 106 | + self->operator/=(scale); | |
| 107 | + return (*self); | |
| 108 | + } | |
| 109 | + // Python 3.x | |
| 110 | + GRmf __truediv__(const double& scale) const { | |
| 111 | + return ((*self) / scale); | |
| 112 | + } | |
| 113 | + GRmf __itruediv__(const double& scale) { | |
| 114 | + self->operator/=(scale); | |
| 115 | + return (*self); | |
| 116 | + } | |
| 86 | 117 | GRmf copy() { |
| 87 | 118 | return (*self); |
| 88 | 119 | } | ... | ... |
src/sky/GSkyRegionMap.cpp
| ... | ... | @@ -455,7 +455,7 @@ void GSkyRegionMap::init_members(void) |
| 455 | 455 | /***********************************************************************//** |
| 456 | 456 | * @brief Copy class members |
| 457 | 457 | * |
| 458 | - * @param[in] region Sky region map. | |
| 458 | + * @param[in] map Sky region map. | |
| 459 | 459 | ***************************************************************************/ |
| 460 | 460 | void GSkyRegionMap::copy_members(const GSkyRegionMap& map) |
| 461 | 461 | { | ... | ... |
src/xspec/GArf.cpp
| ... | ... | @@ -39,6 +39,8 @@ |
| 39 | 39 | #include "GFitsTableFloatCol.hpp" |
| 40 | 40 | |
| 41 | 41 | /* __ Method name definitions ____________________________________________ */ |
| 42 | +#define G_OPERATOR_PLUS "GArf::operator+=(GArf&)" | |
| 43 | +#define G_OPERATOR_MINUS "GArf::operator-=(GArf&)" | |
| 42 | 44 | #define G_OPERATOR "GArf::operator[](std::string&)" |
| 43 | 45 | #define G_AT1 "GArf::at(int&)" |
| 44 | 46 | #define G_AT2 "GArf::at(int&, int&)" |
| ... | ... | @@ -187,11 +189,9 @@ GArf& GArf::operator=(const GArf& arf) |
| 187 | 189 | * The operator only works if the provide Auxiliary Response File has the |
| 188 | 190 | * same energy binning than the current Auxiliary Response File. |
| 189 | 191 | ***************************************************************************/ |
| 190 | -#define G_OPERATOR_PLUS "GArf::operator+=(GArf&)" | |
| 191 | -#define G_OPERATOR_MINUS "GArf::operator-=(GArf&)" | |
| 192 | 192 | GArf& GArf::operator+=(const GArf& arf) |
| 193 | 193 | { |
| 194 | - // Throw an exception if the spectra are not compatible | |
| 194 | + // Throw an exception if the ARF are not compatible | |
| 195 | 195 | if (this->ebounds() != arf.ebounds()) { |
| 196 | 196 | std::string msg = "Incompatible energy binning of Auxiliary " |
| 197 | 197 | "Response File."; |
| ... | ... | @@ -225,7 +225,7 @@ GArf& GArf::operator+=(const GArf& arf) |
| 225 | 225 | ***************************************************************************/ |
| 226 | 226 | GArf& GArf::operator-=(const GArf& arf) |
| 227 | 227 | { |
| 228 | - // Throw an exception if the spectra are not compatible | |
| 228 | + // Throw an exception if the ARF are not compatible | |
| 229 | 229 | if (this->ebounds() != arf.ebounds()) { |
| 230 | 230 | std::string msg = "Incompatible energy binning of Auxiliary " |
| 231 | 231 | "Response File."; | ... | ... |
src/xspec/GRmf.cpp
| ... | ... | @@ -39,6 +39,8 @@ |
| 39 | 39 | #include "GFitsTableFloatCol.hpp" |
| 40 | 40 | |
| 41 | 41 | /* __ Method name definitions ____________________________________________ */ |
| 42 | +#define G_OPERATOR_PLUS "GRmf::operator+=(GRmf&)" | |
| 43 | +#define G_OPERATOR_MINUS "GRmf::operator-=(GRmf&)" | |
| 42 | 44 | #define G_AT "GRmf::at(int&, int&)" |
| 43 | 45 | |
| 44 | 46 | /* __ Macros _____________________________________________________________ */ |
| ... | ... | @@ -172,6 +174,133 @@ GRmf& GRmf::operator=(const GRmf& rmf) |
| 172 | 174 | } |
| 173 | 175 | |
| 174 | 176 | |
| 177 | +/***********************************************************************//** | |
| 178 | + * @brief Add Redistribution Matrix File | |
| 179 | + * | |
| 180 | + * @param[in] rmf Redistribution Matrix File. | |
| 181 | + * @return Sum of Redistribution Matrix File. | |
| 182 | + * | |
| 183 | + * @exception GException::invalid_value | |
| 184 | + * Incompatible Redistribution Matrix Files. | |
| 185 | + * | |
| 186 | + * Adds the RMF values of an Redistribution Matrix File to the current | |
| 187 | + * values. | |
| 188 | + * | |
| 189 | + * The operator only works if the provide Redistribution Matrix File has the | |
| 190 | + * same energy binning than the current Redistribution Matrix File. | |
| 191 | + ***************************************************************************/ | |
| 192 | +GRmf& GRmf::operator+=(const GRmf& rmf) | |
| 193 | +{ | |
| 194 | + // Throw an exception if the RMF are not compatible | |
| 195 | + if (this->etrue() != rmf.etrue()) { | |
| 196 | + std::string msg = "Incompatible true energy binning of " | |
| 197 | + "Redistribution Matrix File."; | |
| 198 | + throw GException::invalid_value(G_OPERATOR_PLUS, msg); | |
| 199 | + } | |
| 200 | + if (this->emeasured() != rmf.emeasured()) { | |
| 201 | + std::string msg = "Incompatible measured energy binning of " | |
| 202 | + "Redistribution Matrix File."; | |
| 203 | + throw GException::invalid_value(G_OPERATOR_PLUS, msg); | |
| 204 | + } | |
| 205 | + | |
| 206 | + // Add RMF values | |
| 207 | + for (int itrue = 0; itrue < ntrue(); ++itrue) { | |
| 208 | + for (int imeasured = 0; imeasured < nmeasured(); ++imeasured) { | |
| 209 | + m_matrix(itrue, imeasured) += rmf.m_matrix(itrue, imeasured); | |
| 210 | + } | |
| 211 | + } | |
| 212 | + | |
| 213 | + // Return | |
| 214 | + return *this; | |
| 215 | +} | |
| 216 | + | |
| 217 | + | |
| 218 | +/***********************************************************************//** | |
| 219 | + * @brief Subtract Redistribution Matrix File | |
| 220 | + * | |
| 221 | + * @param[in] rmf Redistribution Matrix File. | |
| 222 | + * @return Difference of Redistribution Matrix File. | |
| 223 | + * | |
| 224 | + * @exception GException::invalid_value | |
| 225 | + * Incompatible Redistribution Matrix Files. | |
| 226 | + * | |
| 227 | + * Subtracts the RMF values of an Redistribution Matrix File from the current | |
| 228 | + * values. | |
| 229 | + * | |
| 230 | + * The operator only works if the provide Redistribution Matrix File has the | |
| 231 | + * same energy binning than the current Redistribution Matrix File. | |
| 232 | + ***************************************************************************/ | |
| 233 | +GRmf& GRmf::operator-=(const GRmf& rmf) | |
| 234 | +{ | |
| 235 | + // Throw an exception if the RMF are not compatible | |
| 236 | + if (this->etrue() != rmf.etrue()) { | |
| 237 | + std::string msg = "Incompatible true energy binning of " | |
| 238 | + "Redistribution Matrix File."; | |
| 239 | + throw GException::invalid_value(G_OPERATOR_MINUS, msg); | |
| 240 | + } | |
| 241 | + if (this->emeasured() != rmf.emeasured()) { | |
| 242 | + std::string msg = "Incompatible measured energy binning of " | |
| 243 | + "Redistribution Matrix File."; | |
| 244 | + throw GException::invalid_value(G_OPERATOR_MINUS, msg); | |
| 245 | + } | |
| 246 | + | |
| 247 | + // Subtract RMF values | |
| 248 | + for (int itrue = 0; itrue < ntrue(); ++itrue) { | |
| 249 | + for (int imeasured = 0; imeasured < nmeasured(); ++imeasured) { | |
| 250 | + m_matrix(itrue, imeasured) -= rmf.m_matrix(itrue, imeasured); | |
| 251 | + } | |
| 252 | + } | |
| 253 | + | |
| 254 | + // Return | |
| 255 | + return *this; | |
| 256 | +} | |
| 257 | + | |
| 258 | + | |
| 259 | +/***********************************************************************//** | |
| 260 | + * @brief Scale Redistribution Matrix File values | |
| 261 | + * | |
| 262 | + * @param[in] scale Scale factor. | |
| 263 | + * @return Scaled Redistribution Matrix File. | |
| 264 | + * | |
| 265 | + * Multiplies the values of the Redistribution Matrix File with a scale | |
| 266 | + * factor. | |
| 267 | + ***************************************************************************/ | |
| 268 | +GRmf& GRmf::operator*=(const double& scale) | |
| 269 | +{ | |
| 270 | + // Scale RMF values | |
| 271 | + for (int itrue = 0; itrue < ntrue(); ++itrue) { | |
| 272 | + for (int imeasured = 0; imeasured < nmeasured(); ++imeasured) { | |
| 273 | + m_matrix(itrue, imeasured) *= scale; | |
| 274 | + } | |
| 275 | + } | |
| 276 | + | |
| 277 | + // Return | |
| 278 | + return *this; | |
| 279 | +} | |
| 280 | + | |
| 281 | + | |
| 282 | +/***********************************************************************//** | |
| 283 | + * @brief Divide Redistribution Matrix File values | |
| 284 | + * | |
| 285 | + * @param[in] scale Division factor. | |
| 286 | + * @return Divided Redistribution Matrix File. | |
| 287 | + * | |
| 288 | + * Divides the values of the Redistribution Matrix File by a division factor. | |
| 289 | + ***************************************************************************/ | |
| 290 | +GRmf& GRmf::operator/=(const double& scale) | |
| 291 | +{ | |
| 292 | + // Divide RMF values | |
| 293 | + for (int itrue = 0; itrue < ntrue(); ++itrue) { | |
| 294 | + for (int imeasured = 0; imeasured < nmeasured(); ++imeasured) { | |
| 295 | + m_matrix(itrue, imeasured) /= scale; | |
| 296 | + } | |
| 297 | + } | |
| 298 | + | |
| 299 | + // Return | |
| 300 | + return *this; | |
| 301 | +} | |
| 302 | + | |
| 303 | + | |
| 175 | 304 | /*========================================================================== |
| 176 | 305 | = = |
| 177 | 306 | = Public methods = | ... | ... |
test/test_GXspec.cpp
| ... | ... | @@ -194,36 +194,55 @@ void TestGXspec::test_GPha(void) |
| 194 | 194 | test_value(pha6.overflow(), 2.0, 1.0e-6); |
| 195 | 195 | test_value(pha6.outflow(), 0.0, 1.0e-6); |
| 196 | 196 | |
| 197 | - // Test unary addition operator | |
| 198 | - GPha pha7 = pha2; | |
| 199 | - pha7 += pha2; | |
| 200 | - test_value(pha7[0], 10.0, 1.0e-6); | |
| 201 | - test_value(pha7[1], 7.4, 1.0e-6); | |
| 202 | - test_value(pha7.counts(), 23.4, 1.0e-6); | |
| 203 | - test_value(pha7.underflow(), 2.0, 1.0e-6); | |
| 204 | - test_value(pha7.overflow(), 2.0, 1.0e-6); | |
| 197 | + // Test division operator | |
| 198 | + GPha pha7 = pha2 / 2.0; | |
| 199 | + test_value(pha7[0], 2.5, 1.0e-6); | |
| 200 | + test_value(pha7[1], 1.85, 1.0e-6); | |
| 201 | + test_value(pha7.counts(), 5.85, 1.0e-6); | |
| 202 | + test_value(pha7.underflow(), 0.5, 1.0e-6); | |
| 203 | + test_value(pha7.overflow(), 0.5, 1.0e-6); | |
| 205 | 204 | test_value(pha7.outflow(), 0.0, 1.0e-6); |
| 206 | 205 | |
| 207 | - // Test unary subtraction operator | |
| 206 | + // Test unary addition operator | |
| 208 | 207 | GPha pha8 = pha2; |
| 209 | - pha8 -= pha2; | |
| 210 | - test_value(pha8[0], 0.0, 1.0e-6); | |
| 211 | - test_value(pha8[1], 0.0, 1.0e-6); | |
| 212 | - test_value(pha8.counts(), 0.0, 1.0e-6); | |
| 213 | - test_value(pha8.underflow(), 0.0, 1.0e-6); | |
| 214 | - test_value(pha8.overflow(), 0.0, 1.0e-6); | |
| 208 | + pha8 += pha2; | |
| 209 | + test_value(pha8[0], 10.0, 1.0e-6); | |
| 210 | + test_value(pha8[1], 7.4, 1.0e-6); | |
| 211 | + test_value(pha8.counts(), 23.4, 1.0e-6); | |
| 212 | + test_value(pha8.underflow(), 2.0, 1.0e-6); | |
| 213 | + test_value(pha8.overflow(), 2.0, 1.0e-6); | |
| 215 | 214 | test_value(pha8.outflow(), 0.0, 1.0e-6); |
| 216 | 215 | |
| 217 | - // Test unary scale operator | |
| 216 | + // Test unary subtraction operator | |
| 218 | 217 | GPha pha9 = pha2; |
| 219 | - pha9 *= 2.0; | |
| 220 | - test_value(pha9[0], 10.0, 1.0e-6); | |
| 221 | - test_value(pha9[1], 7.4, 1.0e-6); | |
| 222 | - test_value(pha9.counts(), 23.4, 1.0e-6); | |
| 223 | - test_value(pha9.underflow(), 2.0, 1.0e-6); | |
| 224 | - test_value(pha9.overflow(), 2.0, 1.0e-6); | |
| 218 | + pha9 -= pha2; | |
| 219 | + test_value(pha9[0], 0.0, 1.0e-6); | |
| 220 | + test_value(pha9[1], 0.0, 1.0e-6); | |
| 221 | + test_value(pha9.counts(), 0.0, 1.0e-6); | |
| 222 | + test_value(pha9.underflow(), 0.0, 1.0e-6); | |
| 223 | + test_value(pha9.overflow(), 0.0, 1.0e-6); | |
| 225 | 224 | test_value(pha9.outflow(), 0.0, 1.0e-6); |
| 226 | 225 | |
| 226 | + // Test unary scale operator | |
| 227 | + GPha pha10 = pha2; | |
| 228 | + pha10 *= 2.0; | |
| 229 | + test_value(pha10[0], 10.0, 1.0e-6); | |
| 230 | + test_value(pha10[1], 7.4, 1.0e-6); | |
| 231 | + test_value(pha10.counts(), 23.4, 1.0e-6); | |
| 232 | + test_value(pha10.underflow(), 2.0, 1.0e-6); | |
| 233 | + test_value(pha10.overflow(), 2.0, 1.0e-6); | |
| 234 | + test_value(pha10.outflow(), 0.0, 1.0e-6); | |
| 235 | + | |
| 236 | + // Test unary division operator | |
| 237 | + GPha pha11 = pha2; | |
| 238 | + pha11 /= 2.0; | |
| 239 | + test_value(pha11[0], 2.5, 1.0e-6); | |
| 240 | + test_value(pha11[1], 1.85, 1.0e-6); | |
| 241 | + test_value(pha11.counts(), 5.85, 1.0e-6); | |
| 242 | + test_value(pha11.underflow(), 0.5, 1.0e-6); | |
| 243 | + test_value(pha11.overflow(), 0.5, 1.0e-6); | |
| 244 | + test_value(pha11.outflow(), 0.0, 1.0e-6); | |
| 245 | + | |
| 227 | 246 | // Return |
| 228 | 247 | return; |
| 229 | 248 | } |
| ... | ... | @@ -306,8 +325,55 @@ void TestGXspec::test_GArf(void) |
| 306 | 325 | test_value(arf2.at(i), 0.0); |
| 307 | 326 | test_value(arf2[i], 0.0); |
| 308 | 327 | } |
| 309 | - //std::cout << arf << std::endl; | |
| 310 | - //std::cout << arf2 << std::endl; | |
| 328 | + | |
| 329 | + // Test addition operator | |
| 330 | + GArf arf3 = arf2 + arf2; | |
| 331 | + test_value(arf3[0], 10.0, 1.0e-6); | |
| 332 | + test_value(arf3[1], 7.4, 1.0e-6); | |
| 333 | + | |
| 334 | + // Test subtraction operator | |
| 335 | + GArf arf4 = arf2 - arf2; | |
| 336 | + test_value(arf4[0], 0.0, 1.0e-6); | |
| 337 | + test_value(arf4[1], 0.0, 1.0e-6); | |
| 338 | + | |
| 339 | + // Test scale operator | |
| 340 | + GArf arf5 = arf2 * 2.0; | |
| 341 | + test_value(arf5[0], 10.0, 1.0e-6); | |
| 342 | + test_value(arf5[1], 7.4, 1.0e-6); | |
| 343 | + | |
| 344 | + // Test scale operator | |
| 345 | + GArf arf6 = 2.0 * arf2; | |
| 346 | + test_value(arf6[0], 10.0, 1.0e-6); | |
| 347 | + test_value(arf6[1], 7.4, 1.0e-6); | |
| 348 | + | |
| 349 | + // Test division operator | |
| 350 | + GArf arf7 = arf2 / 2.0; | |
| 351 | + test_value(arf7[0], 2.5, 1.0e-6); | |
| 352 | + test_value(arf7[1], 1.85, 1.0e-6); | |
| 353 | + | |
| 354 | + // Test unary addition operator | |
| 355 | + GArf arf8 = arf2; | |
| 356 | + arf8 += arf2; | |
| 357 | + test_value(arf8[0], 10.0, 1.0e-6); | |
| 358 | + test_value(arf8[1], 7.4, 1.0e-6); | |
| 359 | + | |
| 360 | + // Test unary subtraction operator | |
| 361 | + GArf arf9 = arf2; | |
| 362 | + arf9 -= arf2; | |
| 363 | + test_value(arf9[0], 0.0, 1.0e-6); | |
| 364 | + test_value(arf9[1], 0.0, 1.0e-6); | |
| 365 | + | |
| 366 | + // Test unary scale operator | |
| 367 | + GArf arf10 = arf2; | |
| 368 | + arf10 *= 2.0; | |
| 369 | + test_value(arf10[0], 10.0, 1.0e-6); | |
| 370 | + test_value(arf10[1], 7.4, 1.0e-6); | |
| 371 | + | |
| 372 | + // Test unary divisison operator | |
| 373 | + GArf arf11 = arf2; | |
| 374 | + arf11 /= 2.0; | |
| 375 | + test_value(arf11[0], 2.5, 1.0e-6); | |
| 376 | + test_value(arf11[1], 1.85, 1.0e-6); | |
| 311 | 377 | |
| 312 | 378 | // Return |
| 313 | 379 | return; |
| ... | ... | @@ -381,14 +447,6 @@ void TestGXspec::test_GRmf(void) |
| 381 | 447 | rmf.load("rmf.fits"); |
| 382 | 448 | test_assert(rmf.filename().url() == "rmf.fits", |
| 383 | 449 | "Unexpected filename \""+rmf.filename().url()+"\"."); |
| 384 | - /* | |
| 385 | - for (int i = 0; i < 9; ++i) { | |
| 386 | - for (int k = 0; k < 9; ++k) { | |
| 387 | - std::cout << rmf(i,k) << " "; | |
| 388 | - } | |
| 389 | - std::cout << std::endl; | |
| 390 | - } | |
| 391 | - */ | |
| 392 | 450 | for (int i = 0; i < 9; ++i) { |
| 393 | 451 | int k = 0; |
| 394 | 452 | for (; k < i; ++k) { |
| ... | ... | @@ -424,8 +482,55 @@ void TestGXspec::test_GRmf(void) |
| 424 | 482 | test_value(rmf(i,k), 0.0); |
| 425 | 483 | } |
| 426 | 484 | } |
| 427 | - //std::cout << rmf << std::endl; | |
| 428 | - //std::cout << rmf2 << std::endl; | |
| 485 | + | |
| 486 | + // Test addition operator | |
| 487 | + GRmf rmf3 = rmf2 + rmf2; | |
| 488 | + test_value(rmf3(0,0), 2.0, 1.0e-6); | |
| 489 | + test_value(rmf3(1,1), 2.0, 1.0e-6); | |
| 490 | + | |
| 491 | + // Test subtraction operator | |
| 492 | + GRmf rmf4 = rmf2 - rmf2; | |
| 493 | + test_value(rmf4(0,0), 0.0, 1.0e-6); | |
| 494 | + test_value(rmf4(1,1), 0.0, 1.0e-6); | |
| 495 | + | |
| 496 | + // Test scale operator | |
| 497 | + GRmf rmf5 = rmf2 * 2.0; | |
| 498 | + test_value(rmf5(0,0), 2.0, 1.0e-6); | |
| 499 | + test_value(rmf5(1,1), 2.0, 1.0e-6); | |
| 500 | + | |
| 501 | + // Test scale operator | |
| 502 | + GRmf rmf6 = 2.0 * rmf2; | |
| 503 | + test_value(rmf6(0,0), 2.0, 1.0e-6); | |
| 504 | + test_value(rmf6(1,1), 2.0, 1.0e-6); | |
| 505 | + | |
| 506 | + // Test division operator | |
| 507 | + GRmf rmf7 = rmf2 / 2.0; | |
| 508 | + test_value(rmf7(0,0), 0.5, 1.0e-6); | |
| 509 | + test_value(rmf7(1,1), 0.5, 1.0e-6); | |
| 510 | + | |
| 511 | + // Test unary addition operator | |
| 512 | + GRmf rmf8 = rmf2; | |
| 513 | + rmf8 += rmf2; | |
| 514 | + test_value(rmf8(0,0), 2.0, 1.0e-6); | |
| 515 | + test_value(rmf8(1,1), 2.0, 1.0e-6); | |
| 516 | + | |
| 517 | + // Test unary subtraction operator | |
| 518 | + GRmf rmf9 = rmf2; | |
| 519 | + rmf9 -= rmf2; | |
| 520 | + test_value(rmf9(0,0), 0.0, 1.0e-6); | |
| 521 | + test_value(rmf9(1,1), 0.0, 1.0e-6); | |
| 522 | + | |
| 523 | + // Test unary scale operator | |
| 524 | + GRmf rmf10 = rmf2; | |
| 525 | + rmf10 *= 2.0; | |
| 526 | + test_value(rmf10(0,0), 2.0, 1.0e-6); | |
| 527 | + test_value(rmf10(1,1), 2.0, 1.0e-6); | |
| 528 | + | |
| 529 | + // Test unary divisison operator | |
| 530 | + GRmf rmf11 = rmf2; | |
| 531 | + rmf11 /= 2.0; | |
| 532 | + test_value(rmf11(0,0), 0.5, 1.0e-6); | |
| 533 | + test_value(rmf11(1,1), 0.5, 1.0e-6); | |
| 429 | 534 | |
| 430 | 535 | // Return |
| 431 | 536 | return; | ... | ... |
test/test_GXspec.py
| ... | ... | @@ -61,7 +61,8 @@ class Test(gammalib.GPythonTestSuite): |
| 61 | 61 | """ |
| 62 | 62 | # Allocate GPha object and check its size |
| 63 | 63 | nmeasured = 10 |
| 64 | - emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, "TeV"), gammalib.GEnergy(10.0, "TeV")) | |
| 64 | + emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, "TeV"), | |
| 65 | + gammalib.GEnergy(10.0, "TeV")) | |
| 65 | 66 | pha = gammalib.GPha(emeasured) |
| 66 | 67 | self.test_value(pha.size(), nmeasured) |
| 67 | 68 | |
| ... | ... | @@ -80,7 +81,8 @@ class Test(gammalib.GPythonTestSuite): |
| 80 | 81 | """ |
| 81 | 82 | # Allocate GArf object and check its size |
| 82 | 83 | nmeasured = 10 |
| 83 | - emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, "TeV"), gammalib.GEnergy(10.0, "TeV")) | |
| 84 | + emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, "TeV"), | |
| 85 | + gammalib.GEnergy(10.0, "TeV")) | |
| 84 | 86 | arf = gammalib.GArf(emeasured) |
| 85 | 87 | self.test_value(arf.size(), nmeasured) |
| 86 | 88 | |
| ... | ... | @@ -100,8 +102,10 @@ class Test(gammalib.GPythonTestSuite): |
| 100 | 102 | # Allocate GRmf object and check its size |
| 101 | 103 | ntrue = 20 |
| 102 | 104 | nmeasured = 10 |
| 103 | - etrue = gammalib.GEbounds(ntrue, gammalib.GEnergy(1.0, "TeV"), gammalib.GEnergy(10.0, "TeV")) | |
| 104 | - emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, "TeV"), gammalib.GEnergy(10.0, "TeV")) | |
| 105 | + etrue = gammalib.GEbounds(ntrue, gammalib.GEnergy(1.0, "TeV"), | |
| 106 | + gammalib.GEnergy(10.0, "TeV")) | |
| 107 | + emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, "TeV"), | |
| 108 | + gammalib.GEnergy(10.0, "TeV")) | |
| 105 | 109 | rmf = gammalib.GRmf(etrue, emeasured) |
| 106 | 110 | self.test_value(rmf.size(), ntrue*nmeasured) |
| 107 | 111 | self.test_value(rmf.ntrue(), ntrue) | ... | ... |