Commit 8dd626dee8c81596abf558ce75c57644f6c573ef
1 parent
079bc894
Remove matrix tools.
The matrix tools module is not needed anymore as the conversion constructors were put back into the matrix classes.
Showing
10 changed files
with
180 additions
and
369 deletions
include/GMatrixTools.hpp deleted
| 1 | -/*************************************************************************** | |
| 2 | - * GMatrixTools.hpp - Matrix tools * | |
| 3 | - * ----------------------------------------------------------------------- * | |
| 4 | - * copyright (C) 2009 by Jurgen Knodlseder * | |
| 5 | - * ----------------------------------------------------------------------- * | |
| 6 | - * * | |
| 7 | - * This program is free software: you can redistribute it and/or modify * | |
| 8 | - * it under the terms of the GNU General Public License as published by * | |
| 9 | - * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | - * (at your option) any later version. * | |
| 11 | - * * | |
| 12 | - * This program is distributed in the hope that it will be useful, * | |
| 13 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | - * GNU General Public License for more details. * | |
| 16 | - * * | |
| 17 | - * You should have received a copy of the GNU General Public License * | |
| 18 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | - * * | |
| 20 | - ***************************************************************************/ | |
| 21 | - | |
| 22 | -#ifndef GMATRIXTOOLS_HPP | |
| 23 | -#define GMATRIXTOOLS_HPP | |
| 24 | - | |
| 25 | -/* __ Includes ___________________________________________________________ */ | |
| 26 | -#include "GMatrix.hpp" | |
| 27 | -#include "GSymMatrix.hpp" | |
| 28 | -#include "GSparseMatrix.hpp" | |
| 29 | - | |
| 30 | -/* __ Namespaces _________________________________________________________ */ | |
| 31 | - | |
| 32 | -/* __ Constants __________________________________________________________ */ | |
| 33 | - | |
| 34 | -/* __ Prototypes _________________________________________________________ */ | |
| 35 | -GMatrix matrix(const GSymMatrix& m); | |
| 36 | -GMatrix matrix(const GSparseMatrix& m); | |
| 37 | -GSymMatrix sym_matrix(const GMatrix& m); | |
| 38 | -GSymMatrix sym_matrix(const GSparseMatrix& m); | |
| 39 | -GSparseMatrix sparse_matrix(const GMatrix& m); | |
| 40 | -GSparseMatrix sparse_matrix(const GSymMatrix& m); | |
| 41 | - | |
| 42 | - | |
| 43 | -#endif /* GMATRIXTOOLS_HPP */ |
include/GammaLib.hpp
| ... | ... | @@ -38,7 +38,6 @@ |
| 38 | 38 | /* __ Numerics module ____________________________________________________ */ |
| 39 | 39 | #include "GVector.hpp" |
| 40 | 40 | #include "GMatrixBase.hpp" |
| 41 | -#include "GMatrixTools.hpp" | |
| 42 | 41 | #include "GMatrix.hpp" |
| 43 | 42 | #include "GSymMatrix.hpp" |
| 44 | 43 | #include "GSparseMatrix.hpp" | ... | ... |
include/Makefile.am
| ... | ... | @@ -111,7 +111,6 @@ pkginclude_HEADERS = GammaLib.hpp \ |
| 111 | 111 | GFits.hpp \ |
| 112 | 112 | GVector.hpp \ |
| 113 | 113 | GMatrixBase.hpp \ |
| 114 | - GMatrixTools.hpp \ | |
| 115 | 114 | GMatrix.hpp \ |
| 116 | 115 | GSymMatrix.hpp \ |
| 117 | 116 | GSparseMatrix.hpp \ |
| ... | ... | @@ -123,6 +122,6 @@ pkginclude_HEADERS = GammaLib.hpp \ |
| 123 | 122 | GOptimizerLM.hpp \ |
| 124 | 123 | GOptimizerPars.hpp \ |
| 125 | 124 | GOptimizerFunction.hpp \ |
| 126 | - GTestSuite.hpp \ | |
| 125 | + GTestSuite.hpp \ | |
| 127 | 126 | GTestSuites.hpp \ |
| 128 | 127 | GTestCase.hpp |
| 129 | 128 | \ No newline at end of file | ... | ... |
pyext/GMatrix.i
| ... | ... | @@ -18,13 +18,17 @@ |
| 18 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 19 | 19 | * * |
| 20 | 20 | ***************************************************************************/ |
| 21 | +/** | |
| 22 | + * @file GMatrix.i | |
| 23 | + * @brief Generic matrix class definition. | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | + */ | |
| 21 | 26 | %{ |
| 22 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 23 | 28 | #include "GMatrix.hpp" |
| 24 | 29 | #include "GTools.hpp" |
| 25 | 30 | %} |
| 26 | 31 | |
| 27 | -//%feature("notabstract") GMatrix; | |
| 28 | 32 | |
| 29 | 33 | /***********************************************************************//** |
| 30 | 34 | * @class GMatrix |
| ... | ... | @@ -38,39 +42,45 @@ class GMatrix : public GMatrixBase { |
| 38 | 42 | public: |
| 39 | 43 | // Constructors and destructors |
| 40 | 44 | GMatrix(void); |
| 41 | - GMatrix(int rows, int cols); | |
| 42 | - GMatrix(const GMatrix& m); | |
| 45 | + GMatrix(const int& rows, const int& cols); | |
| 46 | + GMatrix(const GMatrix& matrix); | |
| 47 | + GMatrix(const GSymMatrix& matrix); | |
| 48 | + GMatrix(const GSparseMatrix& matrix); | |
| 43 | 49 | virtual ~GMatrix(void); |
| 44 | 50 | |
| 45 | - // Operators | |
| 46 | - GMatrix operator+ (const GMatrix& m) const; | |
| 47 | - GMatrix operator- (const GMatrix& m) const; | |
| 48 | - GMatrix operator* (const GMatrix& m) const; | |
| 49 | - GVector operator* (const GVector& v) const; | |
| 50 | - GMatrix operator- () const; | |
| 51 | - GMatrix& operator+= (const GMatrix& m); | |
| 52 | - GMatrix& operator-= (const GMatrix& m); | |
| 53 | - GMatrix& operator*= (const GMatrix& m); | |
| 54 | - GMatrix& operator*= (const double& s); | |
| 55 | - GMatrix& operator/= (const double& s); | |
| 51 | + // Implemented pure virtual base class operators | |
| 52 | + GVector operator*(const GVector& vector) const; | |
| 56 | 53 | |
| 57 | - // Methods | |
| 58 | - void clear(void); | |
| 59 | - void transpose(void); | |
| 60 | - void invert(void); | |
| 61 | - void add_col(const GVector& v, int col); | |
| 62 | - void insert_col(const GVector& v, int col); | |
| 63 | - GVector extract_row(int row) const; | |
| 64 | - GVector extract_col(int col) const; | |
| 65 | - GMatrix extract_lower_triangle(void) const; | |
| 66 | - GMatrix extract_upper_triangle(void) const; | |
| 67 | - double fill(void) const; | |
| 68 | - double min(void) const; | |
| 69 | - double max(void) const; | |
| 70 | - double sum(void) const; | |
| 71 | - void eulerx(const double& angle); | |
| 72 | - void eulery(const double& angle); | |
| 73 | - void eulerz(const double& angle); | |
| 54 | + // Other operators | |
| 55 | + GMatrix operator+(const GMatrix& matrix) const; | |
| 56 | + GMatrix operator-(const GMatrix& matrix) const; | |
| 57 | + GMatrix operator*(const GMatrix& matrix) const; | |
| 58 | + GMatrix operator-(void) const; | |
| 59 | + GMatrix& operator+=(const GMatrix& matrix); | |
| 60 | + GMatrix& operator-=(const GMatrix& matrix); | |
| 61 | + GMatrix& operator*=(const GMatrix& matrix); | |
| 62 | + GMatrix& operator*=(const double& scalar); | |
| 63 | + GMatrix& operator/=(const double& scalar); | |
| 64 | + | |
| 65 | + // Implemented pure virtual base class methods | |
| 66 | + void clear(void); | |
| 67 | + void transpose(void); | |
| 68 | + void invert(void); | |
| 69 | + void add_col(const GVector& vector, const int& col); | |
| 70 | + void insert_col(const GVector& vector, const int& col); | |
| 71 | + GVector extract_row(const int& row) const; | |
| 72 | + GVector extract_col(const int& col) const; | |
| 73 | + double fill(void) const; | |
| 74 | + double min(void) const; | |
| 75 | + double max(void) const; | |
| 76 | + double sum(void) const; | |
| 77 | + | |
| 78 | + // Other methods | |
| 79 | + GMatrix extract_lower_triangle(void) const; | |
| 80 | + GMatrix extract_upper_triangle(void) const; | |
| 81 | + void eulerx(const double& angle); | |
| 82 | + void eulery(const double& angle); | |
| 83 | + void eulerz(const double& angle); | |
| 74 | 84 | }; |
| 75 | 85 | |
| 76 | 86 | ... | ... |
pyext/GMatrixBase.i
| 1 | 1 | /*************************************************************************** |
| 2 | - * GMatrixBase.hpp - Matrix abstract base class SWIG file * | |
| 2 | + * GMatrixBase.i - Abstract matrix base class * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright : (C) 2006 by Jurgen Knodlseder * | |
| 4 | + * copyright (C) 2006-2012 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -18,60 +18,54 @@ |
| 18 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 19 | 19 | * * |
| 20 | 20 | ***************************************************************************/ |
| 21 | +/** | |
| 22 | + * @file GMatrixBase.i | |
| 23 | + * @brief Abstract matrix base class definition | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | + */ | |
| 21 | 26 | %{ |
| 22 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 23 | 28 | #include "GMatrixBase.hpp" |
| 24 | 29 | %} |
| 25 | 30 | |
| 26 | 31 | |
| 27 | -/*************************************************************************** | |
| 28 | - * GMatrixBase class definition * | |
| 29 | - * ----------------------------------------------------------------------- * | |
| 30 | - * GMatrixBase is an abstract base class for all matrix classes. It * | |
| 31 | - * defines the common interfaces of the matrix objects and provides some * | |
| 32 | - * common services to the derived classes. * | |
| 32 | +/***********************************************************************//** | |
| 33 | + * @class GMatrixBase | |
| 34 | + * | |
| 35 | + * @brief Abstract matrix base class interface defintion | |
| 36 | + * | |
| 37 | + * This is an abstract base class for all matrix classes. It defines the | |
| 38 | + * common interface of the matrix objects and provides some common services | |
| 39 | + * to the derived classes. | |
| 33 | 40 | ***************************************************************************/ |
| 34 | 41 | class GMatrixBase { |
| 35 | - | |
| 36 | -// Methods that are available to everybody | |
| 37 | 42 | public: |
| 38 | - // Constructors and destructors | |
| 39 | - GMatrixBase(); | |
| 40 | - GMatrixBase(const GMatrixBase& m); | |
| 41 | - virtual ~GMatrixBase(); | |
| 43 | + // Constructors and destructors | |
| 44 | + GMatrixBase(void); | |
| 45 | + GMatrixBase(const GMatrixBase& matrix); | |
| 46 | + virtual ~GMatrixBase(void); | |
| 47 | + | |
| 48 | + // Pure virtual operators | |
| 49 | + virtual GVector operator*(const GVector& vector) const = 0; | |
| 50 | + | |
| 51 | + // Implemented base class operators | |
| 52 | + virtual bool operator==(const GMatrixBase& matrix) const; | |
| 53 | + virtual bool operator!=(const GMatrixBase& matrix) const; | |
| 42 | 54 | |
| 43 | - // Operators (first virtual, then pure virtual) | |
| 44 | - virtual int operator== (const GMatrixBase& m) const; | |
| 45 | - virtual int operator!= (const GMatrixBase& m) const; | |
| 46 | - // | |
| 47 | - //virtual GMatrixBase operator+ (const GMatrixBase& m) const = 0; | |
| 48 | - //virtual GMatrixBase operator- (const GMatrixBase& m) const = 0; | |
| 49 | - //virtual GMatrixBase operator* (const GMatrixBase& m) const = 0; | |
| 50 | - virtual GVector operator* (const GVector& v) const = 0; | |
| 51 | - //virtual GMatrixBase operator- () const = 0; | |
| 52 | - //virtual GMatrixBase& operator+= (const GMatrixBase& m) = 0; | |
| 53 | - //virtual GMatrixBase& operator-= (const GMatrixBase& m) = 0; | |
| 54 | - //virtual GMatrixBase& operator*= (const GMatrixBase& m) = 0; | |
| 55 | - //virtual GMatrixBase& operator*= (const double& s) = 0; | |
| 56 | - //virtual GMatrixBase& operator/= (const double& s) = 0; | |
| 55 | + // Pure virtual methods | |
| 56 | + virtual void clear() = 0; | |
| 57 | + virtual void transpose() = 0; | |
| 58 | + virtual void invert() = 0; | |
| 59 | + virtual void add_col(const GVector& vector, const int& col) = 0; | |
| 60 | + virtual void insert_col(const GVector& vector, const int& col) = 0; | |
| 61 | + virtual GVector extract_row(const int& row) const = 0; | |
| 62 | + virtual GVector extract_col(const int& col) const = 0; | |
| 63 | + virtual double fill(void) const = 0; | |
| 64 | + virtual double min(void) const = 0; | |
| 65 | + virtual double max(void) const = 0; | |
| 66 | + virtual double sum(void) const = 0; | |
| 57 | 67 | |
| 58 | - // Methods (first virtual, then pure virtual) | |
| 59 | - virtual int cols(void) const { return m_cols; } | |
| 60 | - virtual int rows(void) const { return m_rows; } | |
| 61 | - // | |
| 62 | - //virtual void add_col(const GVector& v, int col) = 0; | |
| 63 | - //virtual void cholesky_decompose(int compress = 1) = 0; | |
| 64 | - //virtual GVector cholesky_solver(const GVector& v, int compress = 1) = 0; | |
| 65 | - //virtual void cholesky_invert(int compress = 1) = 0; | |
| 66 | - virtual void clear() = 0; | |
| 67 | - virtual GVector extract_row(int row) const = 0; | |
| 68 | - virtual GVector extract_col(int col) const = 0; | |
| 69 | - //virtual GMatrix extract_lower_triangle() const = 0; | |
| 70 | - //virtual GMatrix extract_upper_triangle() const = 0; | |
| 71 | - //virtual void insert_col(const GVector& v, int col) = 0; | |
| 72 | - virtual double fill() const = 0; | |
| 73 | - virtual double min() const = 0; | |
| 74 | - virtual double max() const = 0; | |
| 75 | - virtual double sum() const = 0; | |
| 76 | - virtual void transpose() = 0; | |
| 68 | + // Implemented base class methods | |
| 69 | + virtual int cols(void) const; | |
| 70 | + virtual int rows(void) const; | |
| 77 | 71 | }; | ... | ... |
pyext/GSparseMatrix.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GSparseMatrix.i - Sparse Matrix class SWIG file * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2011 by Jurgen Knodlseder * | |
| 4 | + * copyright (C) 2008-2012 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -18,13 +18,17 @@ |
| 18 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 19 | 19 | * * |
| 20 | 20 | ***************************************************************************/ |
| 21 | +/** | |
| 22 | + * @file GSparseMatrix.i | |
| 23 | + * @brief Sparse matrix class definition. | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | + */ | |
| 21 | 26 | %{ |
| 22 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 23 | 28 | #include "GSparseMatrix.hpp" |
| 24 | 29 | #include "GTools.hpp" |
| 25 | 30 | %} |
| 26 | 31 | |
| 27 | -%feature("notabstract") GSparseMatrix; | |
| 28 | 32 | |
| 29 | 33 | /*************************************************************************** |
| 30 | 34 | * GSparseMatrix class definition * |
| ... | ... | @@ -35,64 +39,70 @@ |
| 35 | 39 | class GSparseMatrix : public GMatrixBase { |
| 36 | 40 | public: |
| 37 | 41 | // Constructors and destructors |
| 38 | - GSparseMatrix(int rows, int cols, int elements = 0); | |
| 39 | - GSparseMatrix(const GSparseMatrix& m); | |
| 40 | - virtual ~GSparseMatrix(); | |
| 42 | + GSparseMatrix(void); | |
| 43 | + GSparseMatrix(const int& rows, const int& cols, const int& elements = 0); | |
| 44 | + GSparseMatrix(const GMatrix& matrix); | |
| 45 | + GSparseMatrix(const GSymMatrix& matrix); | |
| 46 | + GSparseMatrix(const GSparseMatrix& matrix); | |
| 47 | + virtual ~GSparseMatrix(void); | |
| 41 | 48 | |
| 42 | - // Operators | |
| 43 | - //GSparseMatrix& operator= (const GSparseMatrix& m); | |
| 44 | - //double& operator() (int row, int col); | |
| 45 | - //const double& operator() (int row, int col) const; | |
| 46 | - GSparseMatrix operator+ (const GSparseMatrix& m) const; | |
| 47 | - GSparseMatrix operator- (const GSparseMatrix& m) const; | |
| 48 | - GSparseMatrix operator* (const GSparseMatrix& m) const; | |
| 49 | - GVector operator* (const GVector& v) const; | |
| 50 | - int operator== (const GSparseMatrix& m) const; | |
| 51 | - int operator!= (const GSparseMatrix& m) const; | |
| 52 | - GSparseMatrix operator- () const; | |
| 53 | - GSparseMatrix& operator+= (const GSparseMatrix& m); | |
| 54 | - GSparseMatrix& operator-= (const GSparseMatrix& m); | |
| 55 | - GSparseMatrix& operator*= (const GSparseMatrix& m); | |
| 56 | - GSparseMatrix& operator*= (const double& d); | |
| 57 | - GSparseMatrix& operator/= (const double& d); | |
| 49 | + // Implemented pure virtual base class operators | |
| 50 | + GVector operator*(const GVector& vector) const; | |
| 58 | 51 | |
| 59 | - // Matrix methods | |
| 60 | - void add_col(const GVector& v, int col); | |
| 61 | - void add_col(const double* values, const int* rows, int number, int col); | |
| 62 | - void cholesky_decompose(int compress = 1); | |
| 63 | - GVector cholesky_solver(const GVector& v, int compress = 1); | |
| 64 | - void cholesky_invert(int compress = 1); | |
| 65 | - void clear(); | |
| 66 | - GVector extract_row(int row) const; | |
| 67 | - GVector extract_col(int col) const; | |
| 68 | - //TBD GSparseMatrix extract_lower_triangle() const; | |
| 69 | - //TBD GSparseMatrix extract_upper_triangle() const; | |
| 70 | - double fill() const; | |
| 71 | - void insert_col(const GVector& v, int col); | |
| 72 | - void insert_col(const double* values, const int* rows, int number, int col); | |
| 73 | - double min() const; | |
| 74 | - double max() const; | |
| 75 | - void set_mem_block(int block); | |
| 76 | - void stack_init(int size = 0, int entries = 0); | |
| 77 | - int stack_push_column(const GVector& v, int col); | |
| 78 | - int stack_push_column(const double* values, const int* rows, | |
| 79 | - int number, int col); | |
| 80 | - void stack_flush(void); | |
| 81 | - void stack_destroy(void); | |
| 82 | - double sum() const; | |
| 83 | - void transpose(); | |
| 52 | + // Overloaded virtual base class operators | |
| 53 | + bool operator==(const GSparseMatrix& matrix) const; | |
| 54 | + bool operator!=(const GSparseMatrix& matrix) const; | |
| 55 | + | |
| 56 | + // Other operators | |
| 57 | + GSparseMatrix operator+(const GSparseMatrix& matrix) const; | |
| 58 | + GSparseMatrix operator-(const GSparseMatrix& matrix) const; | |
| 59 | + GSparseMatrix operator*(const GSparseMatrix& matrix) const; | |
| 60 | + GSparseMatrix operator-(void) const; | |
| 61 | + GSparseMatrix& operator+=(const GSparseMatrix& matrix); | |
| 62 | + GSparseMatrix& operator-=(const GSparseMatrix& matrix); | |
| 63 | + GSparseMatrix& operator*=(const GSparseMatrix& matrix); | |
| 64 | + GSparseMatrix& operator*=(const double& scalar); | |
| 65 | + GSparseMatrix& operator/=(const double& scalar); | |
| 66 | + | |
| 67 | + // Implemented pure virtual base class methods | |
| 68 | + void clear(void); | |
| 69 | + void transpose(void); | |
| 70 | + void invert(void); | |
| 71 | + void add_col(const GVector& vector, const int& col); | |
| 72 | + void insert_col(const GVector& vector, const int& col); | |
| 73 | + GVector extract_row(const int& row) const; | |
| 74 | + GVector extract_col(const int& col) const; | |
| 75 | + double fill(void) const; | |
| 76 | + double min(void) const; | |
| 77 | + double max(void) const; | |
| 78 | + double sum(void) const; | |
| 79 | + | |
| 80 | + // Other methods | |
| 81 | + void add_col(const double* values, const int* rows, | |
| 82 | + int number, const int& col); | |
| 83 | + void insert_col(const double* values, const int* rows, | |
| 84 | + int number, const int& col); | |
| 85 | + void cholesky_decompose(bool compress = true); | |
| 86 | + GVector cholesky_solver(const GVector& vector, bool compress = true); | |
| 87 | + void cholesky_invert(bool compress = true); | |
| 88 | + void set_mem_block(const int& block); | |
| 89 | + void stack_init(const int& size = 0, const int& entries = 0); | |
| 90 | + int stack_push_column(const GVector& vector, const int& col); | |
| 91 | + int stack_push_column(const double* values, const int* rows, | |
| 92 | + const int& number, const int& col); | |
| 93 | + void stack_flush(void); | |
| 94 | + void stack_destroy(void); | |
| 84 | 95 | }; |
| 85 | 96 | |
| 86 | 97 | |
| 87 | 98 | /*************************************************************************** |
| 88 | 99 | * GSparseMatrix class SWIG extension * |
| 100 | + * | |
| 101 | + * @todo Use typemap to allow for a [row,col] matrix access | |
| 89 | 102 | ***************************************************************************/ |
| 90 | 103 | %extend GSparseMatrix { |
| 91 | 104 | char *__str__() { |
| 92 | - std::ostringstream buffer; | |
| 93 | - buffer << *self; | |
| 94 | - std::string str = buffer.str(); | |
| 95 | - return tochar(str); | |
| 105 | + return tochar(self->print()); | |
| 96 | 106 | } |
| 97 | 107 | double __getslice__(int row, int col) { |
| 98 | 108 | if (row >=0 && row < (int)self->rows() && col >= 0 && col < (int)self->cols()) | ... | ... |
pyext/GSymMatrix.i
| ... | ... | @@ -18,13 +18,17 @@ |
| 18 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 19 | 19 | * * |
| 20 | 20 | ***************************************************************************/ |
| 21 | +/** | |
| 22 | + * @file GSymMatrix.i | |
| 23 | + * @brief SYmmetric matrix class definition. | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | + */ | |
| 21 | 26 | %{ |
| 22 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 23 | 28 | #include "GSymMatrix.hpp" |
| 24 | 29 | #include "GTools.hpp" |
| 25 | 30 | %} |
| 26 | 31 | |
| 27 | -%feature("notabstract") GSymMatrix; | |
| 28 | 32 | |
| 29 | 33 | /***********************************************************************//** |
| 30 | 34 | * @class GSymMatrix |
| ... | ... | @@ -38,40 +42,44 @@ class GSymMatrix : public GMatrixBase { |
| 38 | 42 | public: |
| 39 | 43 | // Constructors and destructors |
| 40 | 44 | GSymMatrix(void); |
| 41 | - GSymMatrix(int rows, int cols); | |
| 45 | + GSymMatrix(const int& rows, const int& cols); | |
| 42 | 46 | GSymMatrix(const GMatrix& matrix); |
| 43 | 47 | GSymMatrix(const GSymMatrix& matrix); |
| 44 | 48 | GSymMatrix(const GSparseMatrix& matrix); |
| 45 | 49 | virtual ~GSymMatrix(void); |
| 46 | 50 | |
| 47 | - // Operators | |
| 48 | - GSymMatrix operator+ (const GSymMatrix& m) const; | |
| 49 | - GSymMatrix operator- (const GSymMatrix& m) const; | |
| 50 | - GSymMatrix operator* (const GSymMatrix& m) const; | |
| 51 | - GVector operator* (const GVector& v) const; | |
| 52 | - GSymMatrix operator- () const; | |
| 53 | - GSymMatrix& operator+= (const GSymMatrix& m); | |
| 54 | - GSymMatrix& operator-= (const GSymMatrix& m); | |
| 55 | - GSymMatrix& operator*= (const GSymMatrix& m); | |
| 56 | - GSymMatrix& operator*= (const double& d); | |
| 57 | - GSymMatrix& operator/= (const double& d); | |
| 51 | + // Implemented pure virtual base class operators | |
| 52 | + virtual GVector operator*(const GVector& v) const; | |
| 58 | 53 | |
| 59 | - // Methods | |
| 60 | - virtual void add_col(const GVector& v, int col); | |
| 61 | - virtual void cholesky_decompose(int compress = 1); | |
| 62 | - virtual GVector cholesky_solver(const GVector& v, int compress = 1); | |
| 63 | - virtual void cholesky_invert(int compress = 1); | |
| 64 | - virtual void clear(void); | |
| 65 | - virtual GVector extract_row(int row) const; | |
| 66 | - virtual GVector extract_col(int col) const; | |
| 67 | - virtual GMatrix extract_lower_triangle() const; | |
| 68 | - virtual GMatrix extract_upper_triangle() const; | |
| 69 | - virtual void insert_col(const GVector& v, int col); | |
| 70 | - virtual double fill(void) const; | |
| 71 | - virtual double min(void) const; | |
| 72 | - virtual double max(void) const; | |
| 73 | - virtual double sum(void) const; | |
| 74 | - virtual void transpose(void); | |
| 54 | + // Other operators | |
| 55 | + virtual GSymMatrix operator+(const GSymMatrix& matrix) const; | |
| 56 | + virtual GSymMatrix operator-(const GSymMatrix& matrix) const; | |
| 57 | + virtual GMatrix operator*(const GSymMatrix& matrix) const; | |
| 58 | + virtual GSymMatrix operator-(void) const; | |
| 59 | + virtual GSymMatrix& operator+=(const GSymMatrix& matrix); | |
| 60 | + virtual GSymMatrix& operator-=(const GSymMatrix& matrix); | |
| 61 | + virtual GSymMatrix& operator*=(const double& scaler); | |
| 62 | + virtual GSymMatrix& operator/=(const double& scalar); | |
| 63 | + | |
| 64 | + // Implemented pure virtual base class methods | |
| 65 | + virtual void clear(void); | |
| 66 | + virtual void transpose(void); | |
| 67 | + virtual void invert(void); | |
| 68 | + virtual void add_col(const GVector& vector, const int& col); | |
| 69 | + virtual void insert_col(const GVector& vector, const int& col); | |
| 70 | + virtual GVector extract_row(const int& row) const; | |
| 71 | + virtual GVector extract_col(const int& col) const; | |
| 72 | + virtual double fill(void) const; | |
| 73 | + virtual double min(void) const; | |
| 74 | + virtual double max(void) const; | |
| 75 | + virtual double sum(void) const; | |
| 76 | + | |
| 77 | + // Other methods | |
| 78 | + virtual GMatrix extract_lower_triangle(void) const; | |
| 79 | + virtual GMatrix extract_upper_triangle(void) const; | |
| 80 | + virtual void cholesky_decompose(bool compress = true); | |
| 81 | + virtual GVector cholesky_solver(const GVector& vector, bool compress = true); | |
| 82 | + virtual void cholesky_invert(bool compress = true); | |
| 75 | 83 | }; |
| 76 | 84 | |
| 77 | 85 | ... | ... |
pyext/gammalib/linalg.i
src/linalg/GMatrixTools.cpp deleted
| 1 | -/*************************************************************************** | |
| 2 | - * GMatrixTools.cpp - Matrix tools * | |
| 3 | - * ----------------------------------------------------------------------- * | |
| 4 | - * copyright (C) 2009 by Jurgen Knodlseder * | |
| 5 | - * ----------------------------------------------------------------------- * | |
| 6 | - * * | |
| 7 | - * This program is free software: you can redistribute it and/or modify * | |
| 8 | - * it under the terms of the GNU General Public License as published by * | |
| 9 | - * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | - * (at your option) any later version. * | |
| 11 | - * * | |
| 12 | - * This program is distributed in the hope that it will be useful, * | |
| 13 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | - * GNU General Public License for more details. * | |
| 16 | - * * | |
| 17 | - * You should have received a copy of the GNU General Public License * | |
| 18 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | - * * | |
| 20 | - ***************************************************************************/ | |
| 21 | - | |
| 22 | -/* __ Includes ___________________________________________________________ */ | |
| 23 | -#include "GMatrixTools.hpp" | |
| 24 | - | |
| 25 | -/* __ Method name definitions ____________________________________________ */ | |
| 26 | -#define G_SYM_1 "GSymMatrix sym_matrix(const GMatrix&)" | |
| 27 | -#define G_SYM_2 "GSymMatrix sym_matrix(const GMatrixSparse&)" | |
| 28 | - | |
| 29 | - | |
| 30 | -/***********************************************************************//** | |
| 31 | - * @brief GSymMatrix to GMatrix storage class convertor | |
| 32 | - * | |
| 33 | - * @param[in] m GSymMatrix to be converted | |
| 34 | - ***************************************************************************/ | |
| 35 | -GMatrix matrix(const GSymMatrix& m) | |
| 36 | -{ | |
| 37 | - // Allocate matrix | |
| 38 | - GMatrix result = GMatrix(m.rows(), m.cols()); | |
| 39 | - | |
| 40 | - // Fill matrix | |
| 41 | - for (int col = 0; col < m.cols(); ++col) { | |
| 42 | - for (int row = 0; row < m.rows(); ++row) | |
| 43 | - result(row, col) = m(row, col); | |
| 44 | - } | |
| 45 | - | |
| 46 | - // Return | |
| 47 | - return result; | |
| 48 | -} | |
| 49 | - | |
| 50 | - | |
| 51 | -/***********************************************************************//** | |
| 52 | - * @brief GSparseMatrix to GMatrix storage class convertor | |
| 53 | - * | |
| 54 | - * @param[in] m GSparseMatrix to be converted | |
| 55 | - ***************************************************************************/ | |
| 56 | -GMatrix matrix(const GSparseMatrix& m) | |
| 57 | -{ | |
| 58 | - // Allocate matrix | |
| 59 | - GMatrix result = GMatrix(m.rows(), m.cols()); | |
| 60 | - | |
| 61 | - // Fill matrix | |
| 62 | - for (int col = 0; col < m.cols(); ++col) { | |
| 63 | - for (int row = 0; row < m.rows(); ++row) | |
| 64 | - result(row, col) = m(row, col); | |
| 65 | - } | |
| 66 | - | |
| 67 | - // Return | |
| 68 | - return result; | |
| 69 | -} | |
| 70 | - | |
| 71 | - | |
| 72 | -/***********************************************************************//** | |
| 73 | - * @brief GMatrix to GSymMatrix storage class convertor | |
| 74 | - * | |
| 75 | - * @param[in] m GMatrix to be converted | |
| 76 | - ***************************************************************************/ | |
| 77 | -GSymMatrix sym_matrix(const GMatrix& m) | |
| 78 | -{ | |
| 79 | - // Allocate matrix | |
| 80 | - GSymMatrix result = GSymMatrix(m.rows(), m.cols()); | |
| 81 | - | |
| 82 | - // Fill matrix | |
| 83 | - for (int col = 0; col < m.cols(); ++col) { | |
| 84 | - for (int row = col; row < m.rows(); ++row) { | |
| 85 | - double value_ll = m(row,col); | |
| 86 | - double value_ur = m(col,row); | |
| 87 | - if (value_ll != value_ur) | |
| 88 | - throw GException::matrix_not_symmetric(G_SYM_1, m.rows(), m.cols()); | |
| 89 | - result(row, col) = m(row, col); | |
| 90 | - } | |
| 91 | - } | |
| 92 | - | |
| 93 | - // Return | |
| 94 | - return result; | |
| 95 | -} | |
| 96 | - | |
| 97 | - | |
| 98 | -/***********************************************************************//** | |
| 99 | - * @brief GSparseMatrix to GSymMatrix storage class convertor | |
| 100 | - * | |
| 101 | - * @param[in] m GSparseMatrix to be converted | |
| 102 | - ***************************************************************************/ | |
| 103 | -GSymMatrix sym_matrix(const GSparseMatrix& m) | |
| 104 | -{ | |
| 105 | - // Allocate matrix | |
| 106 | - GSymMatrix result = GSymMatrix(m.rows(), m.cols()); | |
| 107 | - | |
| 108 | - // Fill matrix | |
| 109 | - for (int col = 0; col < m.cols(); ++col) { | |
| 110 | - for (int row = col; row < m.rows(); ++row) { | |
| 111 | - double value_ll = m(row,col); | |
| 112 | - double value_ur = m(col,row); | |
| 113 | - if (value_ll != value_ur) | |
| 114 | - throw GException::matrix_not_symmetric(G_SYM_2, m.rows(), m.cols()); | |
| 115 | - result(row, col) = m(row, col); | |
| 116 | - } | |
| 117 | - } | |
| 118 | - | |
| 119 | - // Return | |
| 120 | - return result; | |
| 121 | -} | |
| 122 | - | |
| 123 | - | |
| 124 | -/***********************************************************************//** | |
| 125 | - * @brief GMatrix to GSparseMatrix storage class convertor | |
| 126 | - * | |
| 127 | - * @param[in] m GMatrix to be converted | |
| 128 | - ***************************************************************************/ | |
| 129 | -GSparseMatrix sparse_matrix(const GMatrix& m) | |
| 130 | -{ | |
| 131 | - // Allocate matrix | |
| 132 | - GSparseMatrix result = GSparseMatrix(m.rows(), m.cols()); | |
| 133 | - | |
| 134 | - // Fill matrix | |
| 135 | - for (int col = 0; col < m.cols(); ++col) { | |
| 136 | - for (int row = 0; row < m.rows(); ++row) | |
| 137 | - result(row, col) = m(row, col); | |
| 138 | - } | |
| 139 | - | |
| 140 | - // Return | |
| 141 | - return result; | |
| 142 | -} | |
| 143 | - | |
| 144 | - | |
| 145 | -/***********************************************************************//** | |
| 146 | - * @brief GSymMatrix to GSparseMatrix storage class convertor | |
| 147 | - * | |
| 148 | - * @param[in] m GSymMatrix to be converted | |
| 149 | - ***************************************************************************/ | |
| 150 | -GSparseMatrix sparse_matrix(const GSymMatrix& m) | |
| 151 | -{ | |
| 152 | - // Allocate matrix | |
| 153 | - GSparseMatrix result = GSparseMatrix(m.rows(), m.cols()); | |
| 154 | - | |
| 155 | - // Fill matrix | |
| 156 | - for (int col = 0; col < m.cols(); ++col) { | |
| 157 | - for (int row = 0; row < m.rows(); ++row) | |
| 158 | - result(row, col) = m(row, col); | |
| 159 | - } | |
| 160 | - | |
| 161 | - // Return | |
| 162 | - return result; | |
| 163 | -} | |
| 164 | - |