diff --git a/ChangeLog b/ChangeLog index 3314137..ae80078 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * Version 1.3.0 released ========================= + Add scalar addition and subtraction operators to matrix classes (#1990) Allow fitting of scale parameter in composite models (#1992) Add GCTAAeff::ebounds() method (#1989) Add GEbounds::emin() and GEbounds::emax() setter methods (#1989) diff --git a/NEWS b/NEWS index df13119..881d158 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,18 @@ The following methods have been added: - GEbounds::emax(int&, GEnergy&) - GEnergies::set(GEbounds&) - GFilename::type() +- GMatrix::operator+(double&) +- GMatrix::operator-(double&) +- GMatrix::operator+=(double&) +- GMatrix::operator-=(double&) +- GMatrixSymmetric::operator+(double&) +- GMatrixSymmetric::operator-(double&) +- GMatrixSymmetric::operator+=(double&) +- GMatrixSymmetric::operator-=(double&) +- GMatrixSparse::operator+(double&) +- GMatrixSparse::operator-(double&) +- GMatrixSparse::operator+=(double&) +- GMatrixSparse::operator-=(double&) - GCTAResponseIrf::rspname() - GCTARoi::contains(GCTAInstDir&) - GCTAEdisp2D::fetch() @@ -84,7 +96,8 @@ image of any type into a specific storage class (#1986). 7. Linear algebra module ------------------------ -None +Add operators for addition and subtraction of scalars to all matrix classes +(#1990). 8. Model module diff --git a/include/GMatrix.hpp b/include/GMatrix.hpp index 3939799..cab18b9 100644 --- a/include/GMatrix.hpp +++ b/include/GMatrix.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GMatrix.hpp - General matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2006-2014 by Juergen Knoedlseder * + * copyright (C) 2006-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -96,11 +96,15 @@ public: virtual GMatrix& operator=(const GMatrix& matrix); virtual GMatrix& operator=(const double& value); virtual GMatrix operator+(const GMatrix& matrix) const; + virtual GMatrix operator+(const double& scalar) const; virtual GMatrix operator-(const GMatrix& matrix) const; + virtual GMatrix operator-(const double& scalar) const; virtual GMatrix operator*(const GMatrix& matrix) const; virtual GMatrix operator-(void) const; virtual GMatrix& operator+=(const GMatrix& matrix); + virtual GMatrix& operator+=(const double& scalar); virtual GMatrix& operator-=(const GMatrix& matrix); + virtual GMatrix& operator-=(const double& scalar); virtual GMatrix& operator*=(const GMatrix& matrix); virtual GMatrix& operator*=(const double& scalar); virtual GMatrix& operator/=(const double& scalar); @@ -207,6 +211,23 @@ GMatrix GMatrix::operator+(const GMatrix& matrix) const /***********************************************************************//** + * @brief Binary matrix scalar addition + * + * @param[in] scalar Scalar. + * @return Matrix with @p scalar added. + * + * Returns a matrix where a @p scalar has been added to each matrix element. + ***************************************************************************/ +inline +GMatrix GMatrix::operator+(const double& scalar) const +{ + GMatrix result = *this; + result += scalar; + return result; +} + + +/***********************************************************************//** * @brief Binary matrix subtraction * * @param[in] matrix Matrix. @@ -225,6 +246,24 @@ GMatrix GMatrix::operator-(const GMatrix& matrix) const /***********************************************************************//** + * @brief Binary matrix scalar subtraction + * + * @param[in] scalar Scalar. + * @return Matrix with @p scalar subtracted. + * + * Returns a matrix where a @p scalar has been subtracted from each matrix + * element. + ***************************************************************************/ +inline +GMatrix GMatrix::operator-(const double& scalar) const +{ + GMatrix result = *this; + result -= scalar; + return result; +} + + +/***********************************************************************//** * @brief Binary matrix multiplication * * @param[in] matrix Matrix. diff --git a/include/GMatrixSparse.hpp b/include/GMatrixSparse.hpp index ddb0efa..8ce8ae7 100644 --- a/include/GMatrixSparse.hpp +++ b/include/GMatrixSparse.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GMatrixSparse.hpp - Sparse matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2006-2014 by Juergen Knoedlseder * + * copyright (C) 2006-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -221,11 +221,15 @@ public: virtual GMatrixSparse& operator=(const GMatrixSparse& matrix); virtual GMatrixSparse& operator=(const double& value); virtual GMatrixSparse operator+(const GMatrixSparse& matrix) const; + virtual GMatrixSparse operator+(const double& scalar) const; virtual GMatrixSparse operator-(const GMatrixSparse& matrix) const; + virtual GMatrixSparse operator-(const double& scalar) const; virtual GMatrixSparse operator*(const GMatrixSparse& matrix) const; virtual GMatrixSparse operator-(void) const; virtual GMatrixSparse& operator+=(const GMatrixSparse& matrix); + virtual GMatrixSparse& operator+=(const double& scalar); virtual GMatrixSparse& operator-=(const GMatrixSparse& matrix); + virtual GMatrixSparse& operator-=(const double& scalar); virtual GMatrixSparse& operator*=(const GMatrixSparse& matrix); virtual GMatrixSparse& operator*=(const double& scalar); virtual GMatrixSparse& operator/=(const double& scalar); @@ -359,6 +363,23 @@ GMatrixSparse GMatrixSparse::operator+(const GMatrixSparse& matrix) const /***********************************************************************//** + * @brief Binary matrix scalar addition + * + * @param[in] scalar Scalar. + * @return Matrix with @p scalar added. + * + * Returns a matrix where a @p scalar has been added to each matrix element. + ***************************************************************************/ +inline +GMatrixSparse GMatrixSparse::operator+(const double& scalar) const +{ + GMatrixSparse result = *this; + result += scalar; + return result; +} + + +/***********************************************************************//** * @brief Binary matrix subtraction * * @param[in] matrix Matrix. @@ -377,6 +398,24 @@ GMatrixSparse GMatrixSparse::operator-(const GMatrixSparse& matrix) const /***********************************************************************//** + * @brief Binary matrix scalar subtraction + * + * @param[in] scalar Scalar. + * @return Matrix with @p scalar subtracted. + * + * Returns a matrix where a @p scalar has been subtracted from each matrix + * element. + ***************************************************************************/ +inline +GMatrixSparse GMatrixSparse::operator-(const double& scalar) const +{ + GMatrixSparse result = *this; + result -= scalar; + return result; +} + + +/***********************************************************************//** * @brief Binary matrix multiplication * * @param[in] matrix Matrix. diff --git a/include/GMatrixSymmetric.hpp b/include/GMatrixSymmetric.hpp index 2a6ae83..4045216 100644 --- a/include/GMatrixSymmetric.hpp +++ b/include/GMatrixSymmetric.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GMatrixSymmetric.hpp - Symmetric matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2006-2014 by Juergen Knoedlseder * + * copyright (C) 2006-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -88,11 +88,15 @@ public: virtual GMatrixSymmetric& operator=(const GMatrixSymmetric& matrix); virtual GMatrixSymmetric& operator=(const double& value); virtual GMatrixSymmetric operator+(const GMatrixSymmetric& matrix) const; + virtual GMatrixSymmetric operator+(const double& scalar) const; virtual GMatrixSymmetric operator-(const GMatrixSymmetric& matrix) const; + virtual GMatrixSymmetric operator-(const double& scalar) const; virtual GMatrix operator*(const GMatrixSymmetric& matrix) const; virtual GMatrixSymmetric operator-(void) const; virtual GMatrixSymmetric& operator+=(const GMatrixSymmetric& matrix); + virtual GMatrixSymmetric& operator+=(const double& scalar); virtual GMatrixSymmetric& operator-=(const GMatrixSymmetric& matrix); + virtual GMatrixSymmetric& operator-=(const double& scalar); virtual GMatrixSymmetric& operator*=(const double& scaler); virtual GMatrixSymmetric& operator/=(const double& scalar); @@ -214,6 +218,23 @@ GMatrixSymmetric GMatrixSymmetric::operator+(const GMatrixSymmetric& matrix) con /***********************************************************************//** + * @brief Binary matrix scalar addition + * + * @param[in] scalar Scalar. + * @return Matrix with @p scalar added. + * + * Returns a matrix where a @p scalar has been added to each matrix element. + ***************************************************************************/ +inline +GMatrixSymmetric GMatrixSymmetric::operator+(const double& scalar) const +{ + GMatrixSymmetric result = *this; + result += scalar; + return result; +} + + +/***********************************************************************//** * @brief Binary matrix subtraction * * @param[in] matrix Matrix. @@ -232,6 +253,24 @@ GMatrixSymmetric GMatrixSymmetric::operator-(const GMatrixSymmetric& matrix) con /***********************************************************************//** + * @brief Binary matrix scalar subtraction + * + * @param[in] scalar Scalar. + * @return Matrix with @p scalar subtracted. + * + * Returns a matrix where a @p scalar has been subtracted from each matrix + * element. + ***************************************************************************/ +inline +GMatrixSymmetric GMatrixSymmetric::operator-(const double& scalar) const +{ + GMatrixSymmetric result = *this; + result -= scalar; + return result; +} + + +/***********************************************************************//** * @brief Scale matrix elements * * @param[in] scalar Scale factor. diff --git a/pyext/GMatrix.i b/pyext/GMatrix.i index 89b2cc8..1e42701 100755 --- a/pyext/GMatrix.i +++ b/pyext/GMatrix.i @@ -1,7 +1,7 @@ /*************************************************************************** * GMatrix.i - General Matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2016 by Juergen Knoedlseder * + * copyright (C) 2008-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -53,8 +53,12 @@ public: virtual GMatrix operator+(const GMatrix& matrix) const; virtual GMatrix operator-(const GMatrix& matrix) const; virtual GMatrix operator-(void) const; + virtual GMatrix operator+(const double& scalar) const; + virtual GMatrix operator-(const double& scalar) const; virtual GMatrix& operator+=(const GMatrix& matrix); + virtual GMatrix& operator+=(const double& scalar); virtual GMatrix& operator-=(const GMatrix& matrix); + virtual GMatrix& operator-=(const double& scalar); virtual GMatrix& operator*=(const GMatrix& matrix); virtual GMatrix& operator*=(const double& scalar); diff --git a/pyext/GMatrixSparse.i b/pyext/GMatrixSparse.i index 3bb0aa8..5ae9497 100644 --- a/pyext/GMatrixSparse.i +++ b/pyext/GMatrixSparse.i @@ -1,7 +1,7 @@ /*************************************************************************** * GMatrixSparse.i - Sparse matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2016 by Juergen Knoedlseder * + * copyright (C) 2008-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -55,10 +55,14 @@ public: // Other operators virtual GMatrixSparse operator+(const GMatrixSparse& matrix) const; + virtual GMatrixSparse operator+(const double& scalar) const; virtual GMatrixSparse operator-(const GMatrixSparse& matrix) const; + virtual GMatrixSparse operator-(const double& scalar) const; virtual GMatrixSparse operator-(void) const; virtual GMatrixSparse& operator+=(const GMatrixSparse& matrix); + virtual GMatrixSparse& operator+=(const double& scalar); virtual GMatrixSparse& operator-=(const GMatrixSparse& matrix); + virtual GMatrixSparse& operator-=(const double& scalar); virtual GMatrixSparse& operator*=(const GMatrixSparse& matrix); virtual GMatrixSparse& operator*=(const double& scalar); diff --git a/pyext/GMatrixSymmetric.i b/pyext/GMatrixSymmetric.i index bdeb8de..83a6cdb 100644 --- a/pyext/GMatrixSymmetric.i +++ b/pyext/GMatrixSymmetric.i @@ -1,7 +1,7 @@ /*************************************************************************** * GMatrixSymmetric.i - Symmetric matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2016 by Juergen Knoedlseder * + * copyright (C) 2008-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -50,10 +50,14 @@ public: // Other operators virtual GMatrixSymmetric operator+(const GMatrixSymmetric& matrix) const; + virtual GMatrixSymmetric operator+(const double& scalar) const; virtual GMatrixSymmetric operator-(const GMatrixSymmetric& matrix) const; + virtual GMatrixSymmetric operator-(const double& scalar) const; virtual GMatrixSymmetric operator-(void) const; virtual GMatrixSymmetric& operator+=(const GMatrixSymmetric& matrix); + virtual GMatrixSymmetric& operator+=(const double& scalar); virtual GMatrixSymmetric& operator-=(const GMatrixSymmetric& matrix); + virtual GMatrixSymmetric& operator-=(const double& scalar); virtual GMatrixSymmetric& operator*=(const double& scaler); // Implemented pure virtual base class methods diff --git a/src/linalg/GMatrix.cpp b/src/linalg/GMatrix.cpp index 7ccc856..f38874b 100644 --- a/src/linalg/GMatrix.cpp +++ b/src/linalg/GMatrix.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GMatrix.cpp - General matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2006-2013 by Juergen Knoedlseder * + * copyright (C) 2006-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -362,6 +362,26 @@ GMatrix& GMatrix::operator+=(const GMatrix& matrix) /***********************************************************************//** + * @brief Unary matrix scalar addition operator + * + * @param[in] scaler Scalar. + * + * Adds a @p scalar to each matrix element. + ***************************************************************************/ +GMatrix& GMatrix::operator+=(const double& scalar) +{ + // Add all matrix elements + double* dst = m_data; + for (int i = 0; i < m_elements; ++i) { + *dst++ += scalar; + } + + // Return result + return *this; +} + + +/***********************************************************************//** * @brief Unary matrix subtraction operator * * @param[in] matrix Matrix. @@ -394,6 +414,26 @@ GMatrix& GMatrix::operator-=(const GMatrix& matrix) /***********************************************************************//** + * @brief Unary matrix scalar subtraction operator + * + * @param[in] scalar Scalar. + * + * Subtracts a @p scalar from each matrix element. + ***************************************************************************/ +GMatrix& GMatrix::operator-=(const double& scalar) +{ + // Add all matrix elements + double* dst = m_data; + for (int i = 0; i < m_elements; ++i) { + *dst++ -= scalar; + } + + // Return result + return *this; +} + + +/***********************************************************************//** * @brief Unary matrix multiplication operator * * @param[in] matrix Matrix. diff --git a/src/linalg/GMatrixSparse.cpp b/src/linalg/GMatrixSparse.cpp index 888154b..fab598a 100644 --- a/src/linalg/GMatrixSparse.cpp +++ b/src/linalg/GMatrixSparse.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GMatrixSparse.cpp - Sparse matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2006-2013 by Juergen Knoedlseder * + * copyright (C) 2006-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -572,6 +572,27 @@ GMatrixSparse& GMatrixSparse::operator+=(const GMatrixSparse& matrix) /***********************************************************************//** + * @brief Unary matrix scalar addition operator + * + * @param[in] scaler Scalar. + * + * Adds a @p scalar to each matrix element. + ***************************************************************************/ +GMatrixSparse& GMatrixSparse::operator+=(const double& scalar) +{ + // Perform inplace matrix addition using vectors + for (int col = 0; col < m_cols; ++col) { + GVector vector = column(col); + vector += scalar; + column(col, vector); + } + + // Return result + return *this; +} + + +/***********************************************************************//** * @brief Unary matrix subtraction operator * * @param[in] matrix Matrix. @@ -607,6 +628,27 @@ GMatrixSparse& GMatrixSparse::operator-=(const GMatrixSparse& matrix) /***********************************************************************//** + * @brief Unary matrix scalar subtraction operator + * + * @param[in] scalar Scalar. + * + * Subtracts a @p scalar from each matrix element. + ***************************************************************************/ +GMatrixSparse& GMatrixSparse::operator-=(const double& scalar) +{ + // Perform inplace matrix subtraction + for (int col = 0; col < m_cols; ++col) { + GVector vector = column(col); + vector -= scalar; + column(col, vector); + } + + // Return result + return *this; +} + + +/***********************************************************************//** * @brief Unary matrix multiplication operator * * @param[in] matrix Matrix. diff --git a/src/linalg/GMatrixSymmetric.cpp b/src/linalg/GMatrixSymmetric.cpp index 75c50bd..3d44722 100644 --- a/src/linalg/GMatrixSymmetric.cpp +++ b/src/linalg/GMatrixSymmetric.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GMatrixSymmetric.cpp - Symmetric matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2006-2013 by Juergen Knoedlseder * + * copyright (C) 2006-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -412,6 +412,26 @@ GMatrixSymmetric& GMatrixSymmetric::operator+=(const GMatrixSymmetric& matrix) /***********************************************************************//** + * @brief Unary matrix scalar addition operator + * + * @param[in] scaler Scalar. + * + * Adds a @p scalar to each matrix element. + ***************************************************************************/ +GMatrixSymmetric& GMatrixSymmetric::operator+=(const double& scalar) +{ + // Add all matrix elements + double* dst = m_data; + for (int i = 0; i < m_elements; ++i) { + *dst++ += scalar; + } + + // Return result + return *this; +} + + +/***********************************************************************//** * @brief Unary matrix subtraction operator * * @param[in] matrix Matrix. @@ -443,6 +463,26 @@ GMatrixSymmetric& GMatrixSymmetric::operator-=(const GMatrixSymmetric& matrix) } +/***********************************************************************//** + * @brief Unary matrix scalar subtraction operator + * + * @param[in] scalar Scalar. + * + * Subtracts a @p scalar from each matrix element. + ***************************************************************************/ +GMatrixSymmetric& GMatrixSymmetric::operator-=(const double& scalar) +{ + // Add all matrix elements + double* dst = m_data; + for (int i = 0; i < m_elements; ++i) { + *dst++ -= scalar; + } + + // Return result + return *this; +} + + /*========================================================================== = = = Public methods = diff --git a/test/Makefile.am b/test/Makefile.am index eafa18e..32b3fb4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -205,6 +205,7 @@ all-local: # Files to be removed in build directory clean-local: rm -rf $(top_builddir)/test/*.fits + rm -rf $(top_builddir)/test/*.csv rm -rf $(top_builddir)/test/*.log rm -rf $(top_builddir)/test/*.html rm -rf $(top_builddir)/test/*.xml diff --git a/test/test_GMatrix.cpp b/test/test_GMatrix.cpp index 31d7c90..f4ac07c 100644 --- a/test/test_GMatrix.cpp +++ b/test/test_GMatrix.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * test_GMatrix.cpp - Test generic matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2006-2013 by Juergen Knoedlseder * + * copyright (C) 2006-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -532,6 +532,32 @@ void TestGMatrix::matrix_arithmetics(void) test_assert(check_matrix(m_test), "Test source matrix"); test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GMatrix / 3.0", "Unexpected result matrix:\n"+test.print()); + + // GMatrix + 3.0 + test = m_test + 3.0; + test_assert(check_matrix(m_test), "Test source matrix"); + test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrix + 3.0", + "Unexpected result matrix:\n"+test.print()); + + // GMatrix += 3.0 + test = m_test; + test += 3.0; + test_assert(check_matrix(m_test), "Test source matrix"); + test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrix + 3.0", + "Unexpected result matrix:\n"+test.print()); + + // GMatrix - 5.0 + test = m_test - 5.0; + test_assert(check_matrix(m_test), "Test source matrix"); + test_assert(check_matrix(test, 1.0, -5.0), "Test GMatrix -= 5.0", + "Unexpected result matrix:\n"+test.print()); + + // GMatrix -= 3.0 + test = m_test; + test -= 3.0; + test_assert(check_matrix(m_test), "Test source matrix"); + test_assert(check_matrix(test, 1.0, -3.0), "Test GMatrix -= 3.0", + "Unexpected result matrix:\n"+test.print()); // Test invalid matrix addition test_try("Test invalid matrix addition"); diff --git a/test/test_GMatrixSparse.cpp b/test/test_GMatrixSparse.cpp index 178ca4b..2c55d53 100644 --- a/test/test_GMatrixSparse.cpp +++ b/test/test_GMatrixSparse.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * test_GMatrixSparse.cpp - Test sparse matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2006-2016 by Juergen Knoedlseder * + * copyright (C) 2006-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -861,6 +861,32 @@ void TestGMatrixSparse::matrix_arithmetics(void) test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GMatrixSparse / 3.0", "Unexpected result matrix:\n"+test.print()); + // GMatrixSparse + 3.0 + test = m_test + 3.0; + test_assert(check_matrix(m_test), "Test source matrix"); + test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrixSparse + 3.0", + "Unexpected result matrix:\n"+test.print()); + + // GMatrixSparse += 3.0 + test = m_test; + test += 3.0; + test_assert(check_matrix(m_test), "Test source matrix"); + test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrixSparse + 3.0", + "Unexpected result matrix:\n"+test.print()); + + // GMatrixSparse - 5.0 + test = m_test - 5.0; + test_assert(check_matrix(m_test), "Test source matrix"); + test_assert(check_matrix(test, 1.0, -5.0), "Test GMatrixSparse -= 5.0", + "Unexpected result matrix:\n"+test.print()); + + // GMatrixSparse -= 3.0 + test = m_test; + test -= 3.0; + test_assert(check_matrix(m_test), "Test source matrix"); + test_assert(check_matrix(test, 1.0, -3.0), "Test GMatrixSparse -= 3.0", + "Unexpected result matrix:\n"+test.print()); + // Test invalid matrix addition test_try("Test invalid matrix addition"); try { diff --git a/test/test_GMatrixSymmetric.cpp b/test/test_GMatrixSymmetric.cpp index db7fdd3..3c241a8 100644 --- a/test/test_GMatrixSymmetric.cpp +++ b/test/test_GMatrixSymmetric.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * test_GMatrixSymmetric.cpp - Test symmetric matrix class * * ----------------------------------------------------------------------- * - * copyright (C) 2006-2013 by Juergen Knoedlseder * + * copyright (C) 2006-2017 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -537,6 +537,32 @@ void TestGMatrixSymmetric::matrix_arithmetics(void) test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GMatrixSymmetric / 3.0", test.print()); + // GMatrixSymmetric + 3.0 + test = m_test + 3.0; + test_assert(check_matrix(m_test), "Test source matrix"); + test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrixSymmetric + 3.0", + "Unexpected result matrix:\n"+test.print()); + + // GMatrixSymmetric += 3.0 + test = m_test; + test += 3.0; + test_assert(check_matrix(m_test), "Test source matrix"); + test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrixSymmetric + 3.0", + "Unexpected result matrix:\n"+test.print()); + + // GMatrixSymmetric - 5.0 + test = m_test - 5.0; + test_assert(check_matrix(m_test), "Test source matrix"); + test_assert(check_matrix(test, 1.0, -5.0), "Test GMatrixSymmetric -= 5.0", + "Unexpected result matrix:\n"+test.print()); + + // GMatrixSymmetric -= 3.0 + test = m_test; + test -= 3.0; + test_assert(check_matrix(m_test), "Test source matrix"); + test_assert(check_matrix(test, 1.0, -3.0), "Test GMatrixSymmetric -= 3.0", + "Unexpected result matrix:\n"+test.print()); + // Test invalid matrix addition test_try("Test invalid matrix addition"); try {