Commit d258022e7e83b3f262f310d5d274f8d785604b97
1 parent
ef231310
Add scalar addition and subtraction operators to all matrix classes (#1990)
Showing
13 changed files
with
252 additions
and
33 deletions
include/GMatrix.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GMatrix.hpp - General matrix class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2006-2014 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2006-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -213,11 +213,10 @@ GMatrix GMatrix::operator+(const GMatrix& matrix) const |
| 213 | 213 | /***********************************************************************//** |
| 214 | 214 | * @brief Binary matrix scalar addition |
| 215 | 215 | * |
| 216 | - * @param[in] double Scalar. | |
| 217 | - * @return Result of matrix addition. | |
| 216 | + * @param[in] scalar Scalar. | |
| 217 | + * @return Matrix with @p scalar added. | |
| 218 | 218 | * |
| 219 | - * Returns the sum of the matrix with another matrix were all entries have | |
| 220 | - * the value of scalar. The method makes use of the unary addition operator. | |
| 219 | + * Returns a matrix where a @p scalar has been added to each matrix element. | |
| 221 | 220 | ***************************************************************************/ |
| 222 | 221 | inline |
| 223 | 222 | GMatrix GMatrix::operator+(const double& scalar) const |
| ... | ... | @@ -249,11 +248,11 @@ GMatrix GMatrix::operator-(const GMatrix& matrix) const |
| 249 | 248 | /***********************************************************************//** |
| 250 | 249 | * @brief Binary matrix scalar subtraction |
| 251 | 250 | * |
| 252 | - * @param[in] double Scalar. | |
| 253 | - * @return Result of matrix subtraction. | |
| 251 | + * @param[in] scalar Scalar. | |
| 252 | + * @return Matrix with @p scalar subtracted. | |
| 254 | 253 | * |
| 255 | - * Returns the difference of the matrix with another matrix were all entries have | |
| 256 | - * the value of scalar. The method makes use of the unary subtraction operator. | |
| 254 | + * Returns a matrix where a @p scalar has been subtracted from each matrix | |
| 255 | + * element. | |
| 257 | 256 | ***************************************************************************/ |
| 258 | 257 | inline |
| 259 | 258 | GMatrix GMatrix::operator-(const double& scalar) const | ... | ... |
include/GMatrixSparse.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GMatrixSparse.hpp - Sparse matrix class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2006-2014 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2006-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -221,11 +221,15 @@ public: |
| 221 | 221 | virtual GMatrixSparse& operator=(const GMatrixSparse& matrix); |
| 222 | 222 | virtual GMatrixSparse& operator=(const double& value); |
| 223 | 223 | virtual GMatrixSparse operator+(const GMatrixSparse& matrix) const; |
| 224 | + virtual GMatrixSparse operator+(const double& scalar) const; | |
| 224 | 225 | virtual GMatrixSparse operator-(const GMatrixSparse& matrix) const; |
| 226 | + virtual GMatrixSparse operator-(const double& scalar) const; | |
| 225 | 227 | virtual GMatrixSparse operator*(const GMatrixSparse& matrix) const; |
| 226 | 228 | virtual GMatrixSparse operator-(void) const; |
| 227 | 229 | virtual GMatrixSparse& operator+=(const GMatrixSparse& matrix); |
| 230 | + virtual GMatrixSparse& operator+=(const double& scalar); | |
| 228 | 231 | virtual GMatrixSparse& operator-=(const GMatrixSparse& matrix); |
| 232 | + virtual GMatrixSparse& operator-=(const double& scalar); | |
| 229 | 233 | virtual GMatrixSparse& operator*=(const GMatrixSparse& matrix); |
| 230 | 234 | virtual GMatrixSparse& operator*=(const double& scalar); |
| 231 | 235 | virtual GMatrixSparse& operator/=(const double& scalar); |
| ... | ... | @@ -359,6 +363,23 @@ GMatrixSparse GMatrixSparse::operator+(const GMatrixSparse& matrix) const |
| 359 | 363 | |
| 360 | 364 | |
| 361 | 365 | /***********************************************************************//** |
| 366 | + * @brief Binary matrix scalar addition | |
| 367 | + * | |
| 368 | + * @param[in] scalar Scalar. | |
| 369 | + * @return Matrix with @p scalar added. | |
| 370 | + * | |
| 371 | + * Returns a matrix where a @p scalar has been added to each matrix element. | |
| 372 | + ***************************************************************************/ | |
| 373 | +inline | |
| 374 | +GMatrixSparse GMatrixSparse::operator+(const double& scalar) const | |
| 375 | +{ | |
| 376 | + GMatrixSparse result = *this; | |
| 377 | + result += scalar; | |
| 378 | + return result; | |
| 379 | +} | |
| 380 | + | |
| 381 | + | |
| 382 | +/***********************************************************************//** | |
| 362 | 383 | * @brief Binary matrix subtraction |
| 363 | 384 | * |
| 364 | 385 | * @param[in] matrix Matrix. |
| ... | ... | @@ -377,6 +398,24 @@ GMatrixSparse GMatrixSparse::operator-(const GMatrixSparse& matrix) const |
| 377 | 398 | |
| 378 | 399 | |
| 379 | 400 | /***********************************************************************//** |
| 401 | + * @brief Binary matrix scalar subtraction | |
| 402 | + * | |
| 403 | + * @param[in] scalar Scalar. | |
| 404 | + * @return Matrix with @p scalar subtracted. | |
| 405 | + * | |
| 406 | + * Returns a matrix where a @p scalar has been subtracted from each matrix | |
| 407 | + * element. | |
| 408 | + ***************************************************************************/ | |
| 409 | +inline | |
| 410 | +GMatrixSparse GMatrixSparse::operator-(const double& scalar) const | |
| 411 | +{ | |
| 412 | + GMatrixSparse result = *this; | |
| 413 | + result -= scalar; | |
| 414 | + return result; | |
| 415 | +} | |
| 416 | + | |
| 417 | + | |
| 418 | +/***********************************************************************//** | |
| 380 | 419 | * @brief Binary matrix multiplication |
| 381 | 420 | * |
| 382 | 421 | * @param[in] matrix Matrix. | ... | ... |
include/GMatrixSymmetric.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GMatrixSymmetric.hpp - Symmetric matrix class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2006-2014 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2006-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -88,11 +88,15 @@ public: |
| 88 | 88 | virtual GMatrixSymmetric& operator=(const GMatrixSymmetric& matrix); |
| 89 | 89 | virtual GMatrixSymmetric& operator=(const double& value); |
| 90 | 90 | virtual GMatrixSymmetric operator+(const GMatrixSymmetric& matrix) const; |
| 91 | + virtual GMatrixSymmetric operator+(const double& scalar) const; | |
| 91 | 92 | virtual GMatrixSymmetric operator-(const GMatrixSymmetric& matrix) const; |
| 93 | + virtual GMatrixSymmetric operator-(const double& scalar) const; | |
| 92 | 94 | virtual GMatrix operator*(const GMatrixSymmetric& matrix) const; |
| 93 | 95 | virtual GMatrixSymmetric operator-(void) const; |
| 94 | 96 | virtual GMatrixSymmetric& operator+=(const GMatrixSymmetric& matrix); |
| 97 | + virtual GMatrixSymmetric& operator+=(const double& scalar); | |
| 95 | 98 | virtual GMatrixSymmetric& operator-=(const GMatrixSymmetric& matrix); |
| 99 | + virtual GMatrixSymmetric& operator-=(const double& scalar); | |
| 96 | 100 | virtual GMatrixSymmetric& operator*=(const double& scaler); |
| 97 | 101 | virtual GMatrixSymmetric& operator/=(const double& scalar); |
| 98 | 102 | |
| ... | ... | @@ -214,6 +218,23 @@ GMatrixSymmetric GMatrixSymmetric::operator+(const GMatrixSymmetric& matrix) con |
| 214 | 218 | |
| 215 | 219 | |
| 216 | 220 | /***********************************************************************//** |
| 221 | + * @brief Binary matrix scalar addition | |
| 222 | + * | |
| 223 | + * @param[in] scalar Scalar. | |
| 224 | + * @return Matrix with @p scalar added. | |
| 225 | + * | |
| 226 | + * Returns a matrix where a @p scalar has been added to each matrix element. | |
| 227 | + ***************************************************************************/ | |
| 228 | +inline | |
| 229 | +GMatrixSymmetric GMatrixSymmetric::operator+(const double& scalar) const | |
| 230 | +{ | |
| 231 | + GMatrixSymmetric result = *this; | |
| 232 | + result += scalar; | |
| 233 | + return result; | |
| 234 | +} | |
| 235 | + | |
| 236 | + | |
| 237 | +/***********************************************************************//** | |
| 217 | 238 | * @brief Binary matrix subtraction |
| 218 | 239 | * |
| 219 | 240 | * @param[in] matrix Matrix. |
| ... | ... | @@ -232,6 +253,24 @@ GMatrixSymmetric GMatrixSymmetric::operator-(const GMatrixSymmetric& matrix) con |
| 232 | 253 | |
| 233 | 254 | |
| 234 | 255 | /***********************************************************************//** |
| 256 | + * @brief Binary matrix scalar subtraction | |
| 257 | + * | |
| 258 | + * @param[in] scalar Scalar. | |
| 259 | + * @return Matrix with @p scalar subtracted. | |
| 260 | + * | |
| 261 | + * Returns a matrix where a @p scalar has been subtracted from each matrix | |
| 262 | + * element. | |
| 263 | + ***************************************************************************/ | |
| 264 | +inline | |
| 265 | +GMatrixSymmetric GMatrixSymmetric::operator-(const double& scalar) const | |
| 266 | +{ | |
| 267 | + GMatrixSymmetric result = *this; | |
| 268 | + result -= scalar; | |
| 269 | + return result; | |
| 270 | +} | |
| 271 | + | |
| 272 | + | |
| 273 | +/***********************************************************************//** | |
| 235 | 274 | * @brief Scale matrix elements |
| 236 | 275 | * |
| 237 | 276 | * @param[in] scalar Scale factor. | ... | ... |
pyext/GMatrix.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GMatrix.i - General Matrix class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -53,12 +53,12 @@ public: |
| 53 | 53 | virtual GMatrix operator+(const GMatrix& matrix) const; |
| 54 | 54 | virtual GMatrix operator-(const GMatrix& matrix) const; |
| 55 | 55 | virtual GMatrix operator-(void) const; |
| 56 | - virtual GMatrix operator+(const double scalar) const; | |
| 57 | - virtual GMatrix operator-(const double scalar) const; | |
| 56 | + virtual GMatrix operator+(const double& scalar) const; | |
| 57 | + virtual GMatrix operator-(const double& scalar) const; | |
| 58 | 58 | virtual GMatrix& operator+=(const GMatrix& matrix); |
| 59 | - virtual GMatrix& operator+=(const double scalar); | |
| 59 | + virtual GMatrix& operator+=(const double& scalar); | |
| 60 | 60 | virtual GMatrix& operator-=(const GMatrix& matrix); |
| 61 | - virtual GMatrix& operator-=(const double scalar); | |
| 61 | + virtual GMatrix& operator-=(const double& scalar); | |
| 62 | 62 | virtual GMatrix& operator*=(const GMatrix& matrix); |
| 63 | 63 | virtual GMatrix& operator*=(const double& scalar); |
| 64 | 64 | ... | ... |
pyext/GMatrixSparse.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GMatrixSparse.i - Sparse matrix class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -55,10 +55,14 @@ public: |
| 55 | 55 | |
| 56 | 56 | // Other operators |
| 57 | 57 | virtual GMatrixSparse operator+(const GMatrixSparse& matrix) const; |
| 58 | + virtual GMatrixSparse operator+(const double& scalar) const; | |
| 58 | 59 | virtual GMatrixSparse operator-(const GMatrixSparse& matrix) const; |
| 60 | + virtual GMatrixSparse operator-(const double& scalar) const; | |
| 59 | 61 | virtual GMatrixSparse operator-(void) const; |
| 60 | 62 | virtual GMatrixSparse& operator+=(const GMatrixSparse& matrix); |
| 63 | + virtual GMatrixSparse& operator+=(const double& scalar); | |
| 61 | 64 | virtual GMatrixSparse& operator-=(const GMatrixSparse& matrix); |
| 65 | + virtual GMatrixSparse& operator-=(const double& scalar); | |
| 62 | 66 | virtual GMatrixSparse& operator*=(const GMatrixSparse& matrix); |
| 63 | 67 | virtual GMatrixSparse& operator*=(const double& scalar); |
| 64 | 68 | ... | ... |
pyext/GMatrixSymmetric.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GMatrixSymmetric.i - Symmetric matrix class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -50,10 +50,14 @@ public: |
| 50 | 50 | |
| 51 | 51 | // Other operators |
| 52 | 52 | virtual GMatrixSymmetric operator+(const GMatrixSymmetric& matrix) const; |
| 53 | + virtual GMatrixSymmetric operator+(const double& scalar) const; | |
| 53 | 54 | virtual GMatrixSymmetric operator-(const GMatrixSymmetric& matrix) const; |
| 55 | + virtual GMatrixSymmetric operator-(const double& scalar) const; | |
| 54 | 56 | virtual GMatrixSymmetric operator-(void) const; |
| 55 | 57 | virtual GMatrixSymmetric& operator+=(const GMatrixSymmetric& matrix); |
| 58 | + virtual GMatrixSymmetric& operator+=(const double& scalar); | |
| 56 | 59 | virtual GMatrixSymmetric& operator-=(const GMatrixSymmetric& matrix); |
| 60 | + virtual GMatrixSymmetric& operator-=(const double& scalar); | |
| 57 | 61 | virtual GMatrixSymmetric& operator*=(const double& scaler); |
| 58 | 62 | |
| 59 | 63 | // Implemented pure virtual base class methods | ... | ... |
src/linalg/GMatrix.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GMatrix.cpp - General matrix class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2006-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2006-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -364,9 +364,9 @@ GMatrix& GMatrix::operator+=(const GMatrix& matrix) |
| 364 | 364 | /***********************************************************************//** |
| 365 | 365 | * @brief Unary matrix scalar addition operator |
| 366 | 366 | * |
| 367 | - * @param[in] double Scalar. | |
| 367 | + * @param[in] scaler Scalar. | |
| 368 | 368 | * |
| 369 | - * This method adds a given scalar to each matrix element. | |
| 369 | + * Adds a @p scalar to each matrix element. | |
| 370 | 370 | ***************************************************************************/ |
| 371 | 371 | GMatrix& GMatrix::operator+=(const double& scalar) |
| 372 | 372 | { |
| ... | ... | @@ -416,9 +416,9 @@ GMatrix& GMatrix::operator-=(const GMatrix& matrix) |
| 416 | 416 | /***********************************************************************//** |
| 417 | 417 | * @brief Unary matrix scalar subtraction operator |
| 418 | 418 | * |
| 419 | - * @param[in] double Scalar. | |
| 419 | + * @param[in] scalar Scalar. | |
| 420 | 420 | * |
| 421 | - * This method subtracts a given scalar from each matrix element. | |
| 421 | + * Subtracts a @p scalar from each matrix element. | |
| 422 | 422 | ***************************************************************************/ |
| 423 | 423 | GMatrix& GMatrix::operator-=(const double& scalar) |
| 424 | 424 | { | ... | ... |
src/linalg/GMatrixSparse.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GMatrixSparse.cpp - Sparse matrix class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2006-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2006-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -572,6 +572,27 @@ GMatrixSparse& GMatrixSparse::operator+=(const GMatrixSparse& matrix) |
| 572 | 572 | |
| 573 | 573 | |
| 574 | 574 | /***********************************************************************//** |
| 575 | + * @brief Unary matrix scalar addition operator | |
| 576 | + * | |
| 577 | + * @param[in] scaler Scalar. | |
| 578 | + * | |
| 579 | + * Adds a @p scalar to each matrix element. | |
| 580 | + ***************************************************************************/ | |
| 581 | +GMatrixSparse& GMatrixSparse::operator+=(const double& scalar) | |
| 582 | +{ | |
| 583 | + // Perform inplace matrix addition using vectors | |
| 584 | + for (int col = 0; col < m_cols; ++col) { | |
| 585 | + GVector vector = column(col); | |
| 586 | + vector += scalar; | |
| 587 | + column(col, vector); | |
| 588 | + } | |
| 589 | + | |
| 590 | + // Return result | |
| 591 | + return *this; | |
| 592 | +} | |
| 593 | + | |
| 594 | + | |
| 595 | +/***********************************************************************//** | |
| 575 | 596 | * @brief Unary matrix subtraction operator |
| 576 | 597 | * |
| 577 | 598 | * @param[in] matrix Matrix. |
| ... | ... | @@ -607,6 +628,27 @@ GMatrixSparse& GMatrixSparse::operator-=(const GMatrixSparse& matrix) |
| 607 | 628 | |
| 608 | 629 | |
| 609 | 630 | /***********************************************************************//** |
| 631 | + * @brief Unary matrix scalar subtraction operator | |
| 632 | + * | |
| 633 | + * @param[in] scalar Scalar. | |
| 634 | + * | |
| 635 | + * Subtracts a @p scalar from each matrix element. | |
| 636 | + ***************************************************************************/ | |
| 637 | +GMatrixSparse& GMatrixSparse::operator-=(const double& scalar) | |
| 638 | +{ | |
| 639 | + // Perform inplace matrix subtraction | |
| 640 | + for (int col = 0; col < m_cols; ++col) { | |
| 641 | + GVector vector = column(col); | |
| 642 | + vector -= scalar; | |
| 643 | + column(col, vector); | |
| 644 | + } | |
| 645 | + | |
| 646 | + // Return result | |
| 647 | + return *this; | |
| 648 | +} | |
| 649 | + | |
| 650 | + | |
| 651 | +/***********************************************************************//** | |
| 610 | 652 | * @brief Unary matrix multiplication operator |
| 611 | 653 | * |
| 612 | 654 | * @param[in] matrix Matrix. | ... | ... |
src/linalg/GMatrixSymmetric.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GMatrixSymmetric.cpp - Symmetric matrix class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2006-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2006-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -412,6 +412,26 @@ GMatrixSymmetric& GMatrixSymmetric::operator+=(const GMatrixSymmetric& matrix) |
| 412 | 412 | |
| 413 | 413 | |
| 414 | 414 | /***********************************************************************//** |
| 415 | + * @brief Unary matrix scalar addition operator | |
| 416 | + * | |
| 417 | + * @param[in] scaler Scalar. | |
| 418 | + * | |
| 419 | + * Adds a @p scalar to each matrix element. | |
| 420 | + ***************************************************************************/ | |
| 421 | +GMatrixSymmetric& GMatrixSymmetric::operator+=(const double& scalar) | |
| 422 | +{ | |
| 423 | + // Add all matrix elements | |
| 424 | + double* dst = m_data; | |
| 425 | + for (int i = 0; i < m_elements; ++i) { | |
| 426 | + *dst++ += scalar; | |
| 427 | + } | |
| 428 | + | |
| 429 | + // Return result | |
| 430 | + return *this; | |
| 431 | +} | |
| 432 | + | |
| 433 | + | |
| 434 | +/***********************************************************************//** | |
| 415 | 435 | * @brief Unary matrix subtraction operator |
| 416 | 436 | * |
| 417 | 437 | * @param[in] matrix Matrix. |
| ... | ... | @@ -443,6 +463,26 @@ GMatrixSymmetric& GMatrixSymmetric::operator-=(const GMatrixSymmetric& matrix) |
| 443 | 463 | } |
| 444 | 464 | |
| 445 | 465 | |
| 466 | +/***********************************************************************//** | |
| 467 | + * @brief Unary matrix scalar subtraction operator | |
| 468 | + * | |
| 469 | + * @param[in] scalar Scalar. | |
| 470 | + * | |
| 471 | + * Subtracts a @p scalar from each matrix element. | |
| 472 | + ***************************************************************************/ | |
| 473 | +GMatrixSymmetric& GMatrixSymmetric::operator-=(const double& scalar) | |
| 474 | +{ | |
| 475 | + // Add all matrix elements | |
| 476 | + double* dst = m_data; | |
| 477 | + for (int i = 0; i < m_elements; ++i) { | |
| 478 | + *dst++ -= scalar; | |
| 479 | + } | |
| 480 | + | |
| 481 | + // Return result | |
| 482 | + return *this; | |
| 483 | +} | |
| 484 | + | |
| 485 | + | |
| 446 | 486 | /*========================================================================== |
| 447 | 487 | = = |
| 448 | 488 | = Public methods = | ... | ... |
test/Makefile.am
| ... | ... | @@ -205,6 +205,7 @@ all-local: |
| 205 | 205 | # Files to be removed in build directory |
| 206 | 206 | clean-local: |
| 207 | 207 | rm -rf $(top_builddir)/test/*.fits |
| 208 | + rm -rf $(top_builddir)/test/*.csv | |
| 208 | 209 | rm -rf $(top_builddir)/test/*.log |
| 209 | 210 | rm -rf $(top_builddir)/test/*.html |
| 210 | 211 | rm -rf $(top_builddir)/test/*.xml | ... | ... |
test/test_GMatrix.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * test_GMatrix.cpp - Test generic matrix class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2006-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2006-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -540,8 +540,8 @@ void TestGMatrix::matrix_arithmetics(void) |
| 540 | 540 | "Unexpected result matrix:\n"+test.print()); |
| 541 | 541 | |
| 542 | 542 | // GMatrix += 3.0 |
| 543 | - test = m_test; | |
| 544 | - test += 3.0; | |
| 543 | + test = m_test; | |
| 544 | + test += 3.0; | |
| 545 | 545 | test_assert(check_matrix(m_test), "Test source matrix"); |
| 546 | 546 | test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrix + 3.0", |
| 547 | 547 | "Unexpected result matrix:\n"+test.print()); |
| ... | ... | @@ -553,13 +553,12 @@ void TestGMatrix::matrix_arithmetics(void) |
| 553 | 553 | "Unexpected result matrix:\n"+test.print()); |
| 554 | 554 | |
| 555 | 555 | // GMatrix -= 3.0 |
| 556 | - test = m_test; | |
| 557 | - test -= 3.0; | |
| 556 | + test = m_test; | |
| 557 | + test -= 3.0; | |
| 558 | 558 | test_assert(check_matrix(m_test), "Test source matrix"); |
| 559 | 559 | test_assert(check_matrix(test, 1.0, -3.0), "Test GMatrix -= 3.0", |
| 560 | 560 | "Unexpected result matrix:\n"+test.print()); |
| 561 | 561 | |
| 562 | - | |
| 563 | 562 | // Test invalid matrix addition |
| 564 | 563 | test_try("Test invalid matrix addition"); |
| 565 | 564 | try { | ... | ... |
test/test_GMatrixSparse.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * test_GMatrixSparse.cpp - Test sparse matrix class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2006-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2006-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -861,6 +861,32 @@ void TestGMatrixSparse::matrix_arithmetics(void) |
| 861 | 861 | test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GMatrixSparse / 3.0", |
| 862 | 862 | "Unexpected result matrix:\n"+test.print()); |
| 863 | 863 | |
| 864 | + // GMatrixSparse + 3.0 | |
| 865 | + test = m_test + 3.0; | |
| 866 | + test_assert(check_matrix(m_test), "Test source matrix"); | |
| 867 | + test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrixSparse + 3.0", | |
| 868 | + "Unexpected result matrix:\n"+test.print()); | |
| 869 | + | |
| 870 | + // GMatrixSparse += 3.0 | |
| 871 | + test = m_test; | |
| 872 | + test += 3.0; | |
| 873 | + test_assert(check_matrix(m_test), "Test source matrix"); | |
| 874 | + test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrixSparse + 3.0", | |
| 875 | + "Unexpected result matrix:\n"+test.print()); | |
| 876 | + | |
| 877 | + // GMatrixSparse - 5.0 | |
| 878 | + test = m_test - 5.0; | |
| 879 | + test_assert(check_matrix(m_test), "Test source matrix"); | |
| 880 | + test_assert(check_matrix(test, 1.0, -5.0), "Test GMatrixSparse -= 5.0", | |
| 881 | + "Unexpected result matrix:\n"+test.print()); | |
| 882 | + | |
| 883 | + // GMatrixSparse -= 3.0 | |
| 884 | + test = m_test; | |
| 885 | + test -= 3.0; | |
| 886 | + test_assert(check_matrix(m_test), "Test source matrix"); | |
| 887 | + test_assert(check_matrix(test, 1.0, -3.0), "Test GMatrixSparse -= 3.0", | |
| 888 | + "Unexpected result matrix:\n"+test.print()); | |
| 889 | + | |
| 864 | 890 | // Test invalid matrix addition |
| 865 | 891 | test_try("Test invalid matrix addition"); |
| 866 | 892 | try { | ... | ... |
test/test_GMatrixSymmetric.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * test_GMatrixSymmetric.cpp - Test symmetric matrix class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2006-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2006-2017 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -537,6 +537,32 @@ void TestGMatrixSymmetric::matrix_arithmetics(void) |
| 537 | 537 | test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GMatrixSymmetric / 3.0", |
| 538 | 538 | test.print()); |
| 539 | 539 | |
| 540 | + // GMatrixSymmetric + 3.0 | |
| 541 | + test = m_test + 3.0; | |
| 542 | + test_assert(check_matrix(m_test), "Test source matrix"); | |
| 543 | + test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrixSymmetric + 3.0", | |
| 544 | + "Unexpected result matrix:\n"+test.print()); | |
| 545 | + | |
| 546 | + // GMatrixSymmetric += 3.0 | |
| 547 | + test = m_test; | |
| 548 | + test += 3.0; | |
| 549 | + test_assert(check_matrix(m_test), "Test source matrix"); | |
| 550 | + test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrixSymmetric + 3.0", | |
| 551 | + "Unexpected result matrix:\n"+test.print()); | |
| 552 | + | |
| 553 | + // GMatrixSymmetric - 5.0 | |
| 554 | + test = m_test - 5.0; | |
| 555 | + test_assert(check_matrix(m_test), "Test source matrix"); | |
| 556 | + test_assert(check_matrix(test, 1.0, -5.0), "Test GMatrixSymmetric -= 5.0", | |
| 557 | + "Unexpected result matrix:\n"+test.print()); | |
| 558 | + | |
| 559 | + // GMatrixSymmetric -= 3.0 | |
| 560 | + test = m_test; | |
| 561 | + test -= 3.0; | |
| 562 | + test_assert(check_matrix(m_test), "Test source matrix"); | |
| 563 | + test_assert(check_matrix(test, 1.0, -3.0), "Test GMatrixSymmetric -= 3.0", | |
| 564 | + "Unexpected result matrix:\n"+test.print()); | |
| 565 | + | |
| 540 | 566 | // Test invalid matrix addition |
| 541 | 567 | test_try("Test invalid matrix addition"); |
| 542 | 568 | try { | ... | ... |