41 #define G_CONSTRUCTOR "GMatrix::GMatrix(int&, int&)"
42 #define G_OP_MUL_VEC "GMatrix::operator*(GVector&)"
43 #define G_OP_ADD "GMatrix::operator+=(GMatrix&)"
44 #define G_OP_SUB "GMatrix::operator-=(GMatrix&)"
45 #define G_OP_MAT_MUL "GMatrix::operator*=(GMatrix&)"
46 #define G_AT "GMatrix::at(int&, int&)"
47 #define G_EXTRACT_ROW "GMatrix::row(int&)"
48 #define G_SET_ROW "GMatrix::row(int&, GVector&)"
49 #define G_EXTRACT_COLUMN "GMatrix::column(int&)"
50 #define G_SET_COLUMN "GMatrix::column(int&, GVector&)"
51 #define G_ADD_TO_ROW "GMatrix::add_to_row(int&, GVector&)"
52 #define G_ADD_TO_COLUMN "GMatrix::add_to_column(int&, GVector&)"
53 #define G_INVERT "GMatrix::invert()"
54 #define G_SOLVE "GMatrix::solve(GVector&)"
55 #define G_EXTRACT_LOWER "GMatrix::extract_lower_triangle()"
56 #define G_EXTRACT_UPPER "GMatrix::extract_upper_triangle()"
96 #if defined(G_RANGE_CHECK)
98 std::string msg =
"Number of rows "+
gammalib::str(rows)+
" is negative. "
99 "Please specify a non-negative number of rows.";
103 std::string msg =
"Number of columns "+
gammalib::str(columns)+
" is "
104 "negative. Please specify a non-negative number of "
159 for (
int col = 0; col <
m_cols; ++col) {
161 double value = matrix(
row, col);
162 (*this)(
row, col) = value;
163 (*this)(col,
row) = value;
190 for (
int col = 0; col <
m_cols; ++col) {
192 (*this)(
row, col) = matrix(row, col);
231 if (
this != &matrix) {
295 "Please specify a vector of size "+
306 sum += *src * vector[col];
330 double* ptr = matrix.
m_data;
331 for (
int i = 0; i < matrix.
m_elements; ++i, ++ptr) {
356 " differs from the expected number of "+
363 " differs from the expected number of "+
370 const double* src = matrix.
m_data;
417 " differs from the expected number of "+
424 " differs from the expected number of "+
431 const double* src = matrix.
m_data;
484 "the first matrix differs from number of "+
486 "matrix. Please specify a second matrix with "+
495 for (
int col = 0; col <
m_cols; ++col) {
497 for (
int i = 0; i <
m_cols; ++i) {
498 sum += v_row[i] * matrix(i,col);
500 (*this)(
row,col) = sum;
513 for (
int col = 0; col < matrix.
m_cols; ++col) {
515 for (
int i = 0; i <
m_cols; ++i) {
516 sum += (*this)(
row,i) * matrix(i,col);
583 if (row < 0 || row >=
m_rows) {
586 if (column < 0 || column >=
m_cols) {
609 const double&
GMatrix::at(
const int& row,
const int& column)
const
612 if (row < 0 || row >=
m_rows) {
615 if (column < 0 || column >=
m_cols) {
640 #if defined(G_RANGE_CHECK)
641 if (row < 0 || row >=
m_rows) {
652 for (
int col = 0, i = row; col <
m_cols; ++col, i +=
m_rows) {
679 #if defined(G_RANGE_CHECK)
680 if (row < 0 || row >=
m_rows) {
690 "columns. Please specify a vector of size "+
698 for (
int col = 0, i = row; col <
m_cols; ++col, i +=
m_rows) {
721 #if defined(G_RANGE_CHECK)
722 if (column < 0 || column >=
m_cols) {
766 #if defined(G_RANGE_CHECK)
767 if (column < 0 || column >=
m_cols) {
778 "rows. Please specify a vector of size "+
815 #if defined(G_RANGE_CHECK)
816 if (row < 0 || row >=
m_rows) {
827 "columns. Please specify a vector of size "+
835 for (
int col = 0, i = row; col <
m_cols; ++col, i +=
m_rows) {
860 #if defined(G_RANGE_CHECK)
861 if (column < 0 || column >=
m_cols) {
873 "rows. Please specify a vector of size "+
910 for (
int col = 0; col <
m_cols; ++col) {
911 matrix(col,
row) = (*this)(
row, col);
990 double* dst = matrix.
m_data;
1014 double result = 0.0;
1028 result = 1.0-double(zero)/double(m_elements);
1054 " differs from number of matrix columns "+
1056 "on square matrices.";
1064 for (
int col = 0; col <
m_cols; ++col) {
1093 " differs from number of matrix columns "+
1095 "on square matrices.";
1103 for (
int col = 0; col <
m_cols; ++col) {
1105 for (
int row = 0;
row <= col; ++
row, ++i) {
1141 (*this)(1,1) = cosangle;
1142 (*this)(1,2) = -sinangle;
1144 (*this)(2,1) = sinangle;
1145 (*this)(2,2) = cosangle;
1174 (*this)(0,0) = cosangle;
1176 (*this)(0,2) = sinangle;
1180 (*this)(2,0) = -sinangle;
1182 (*this)(2,2) = cosangle;
1211 (*this)(0,0) = cosangle;
1212 (*this)(0,1) = -sinangle;
1214 (*this)(1,0) = sinangle;
1215 (*this)(1,1) = cosangle;
1241 result.append(
"=== GMatrix ===");
1327 int elements = rows *
columns;
1337 m_data =
new double[elements];
1348 for (
int col = 1; col <=
m_cols; ++col) {
Abstract matrix base class interface definition.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print matrix.
std::string print_row_compression(const GChatter &chatter=NORMAL) const
Print row compression scheme if it exists.
void init_members(void)
Initialise class members.
Sparse matrix class interface definition.
GMatrix invert(void) const
Return inverted matrix.
GVector abs(const GVector &vector)
Computes absolute of vector elements.
virtual double & at(const int &row, const int &column)
Return reference to matrix element.
GVector cos(const GVector &vector)
Computes cosine of vector elements.
Generic matrix class definition.
virtual void add_to_row(const int &row, const GVector &vector)
Add row to matrix elements.
int m_rows
Number of rows.
virtual GMatrix operator-(void) const
Negate matrix elements.
virtual GVector column(const int &column) const
Extract column as vector from matrix.
Symmetric matrix class interface definition.
int m_num_colsel
Number of selected columns (for compressed decomposition)
void copy_members(const GMatrix &matrix)
Copy class members.
virtual void add_to_column(const int &column, const GVector &vector)
Add vector column into matrix.
virtual GVector row(const int &row) const
Extract row as vector from matrix.
void eulery(const double &angle)
Set Euler rotation matrix around y axis.
virtual void clear(void)
Clear matrix.
void init_members(void)
Initialise class members.
virtual GMatrix & operator=(const GMatrix &matrix)
Matrix assignment operator.
std::string print_elements(const GChatter &chatter=NORMAL, const int &num=15) const
Print all matrix elements.
void eulerx(const double &angle)
Set Euler rotation matrix around x axis.
double * m_data
Matrix data.
const int & rows(void) const
Return number of matrix rows.
GMatrix transpose(void) const
Return transposed matrix.
GVector solve(const GVector &vector) const
Solves linear matrix equation.
void eulerz(const double &angle)
Set Euler rotation matrix around z axis.
virtual GVector operator*(const GVector &vector) const
Vector multiplication.
int m_cols
Number of columns.
virtual GMatrix & operator-=(const GMatrix &matrix)
Unary matrix subtraction operator.
double angle(const GVector &a, const GVector &b)
Computes angle between vectors.
int m_alloc
Size of allocated matrix memory.
std::string print_col_compression(const GChatter &chatter=NORMAL) const
Print column compression scheme if it exists.
Vector class interface definition.
virtual double fill(void) const
Return fill of matrix.
virtual GMatrix & operator*=(const GMatrix &matrix)
Unary matrix multiplication operator.
virtual GMatrix * clone(void) const
Clone matrix.
Symmetric matrix class definition.
void free_members(void)
Delete class members.
int m_elements
Number of elements stored in matrix.
GMatrix(void)
Void matrix constructor.
virtual ~GMatrix(void)
Destructor.
virtual double sum(void) const
Return matrix element sum.
GMatrix extract_lower_triangle(void) const
Extract lower triangle of matrix.
Sparse matrix class definition.
GVector sin(const GVector &vector)
Computes sine of vector elements.
GMatrix abs(void) const
Return absolute of matrix.
Exception handler interface definition.
virtual GMatrixBase & operator=(const GMatrixBase &matrix)
Assignment operator.
const int & size(void) const
Return size of vector.
void free_members(void)
Delete class members.
Generic matrix class definition.
int m_num_rowsel
Number of selected rows (for compressed decomposition)
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
int * m_colstart
Column start indices (m_cols+1)
int * m_rowsel
Row selection (for compressed decomposition)
const int & columns(void) const
Return number of matrix columns.
virtual GMatrix & operator+=(const GMatrix &matrix)
Unary matrix addition operator.
int * m_colsel
Column selection (for compressed decomposition)
GMatrix extract_upper_triangle(void) const
Extract upper triangle of matrix.
void alloc_members(const int &rows, const int &columns)
Allocate matrix memory.
Mathematical function definitions.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.