GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GMatrix Class Reference

Generic matrix class definition. More...

#include <GMatrix.hpp>

Inheritance diagram for GMatrix:
GMatrixBase GBase

Public Member Functions

 GMatrix (void)
 Void matrix constructor. More...
 
 GMatrix (const int &rows, const int &columns)
 Matrix constructor. More...
 
 GMatrix (const GMatrix &matrix)
 Copy constructor. More...
 
 GMatrix (const GMatrixSymmetric &matrix)
 GMatrixSymmetric to GMatrix storage class convertor. More...
 
 GMatrix (const GMatrixSparse &matrix)
 GMatrixSparse to GMatrix storage class convertor. More...
 
virtual ~GMatrix (void)
 Destructor. More...
 
virtual double & operator() (const int &row, const int &column)
 Return reference to matrix element. More...
 
virtual const double & operator() (const int &row, const int &column) const
 Return reference to matrix element (const version) More...
 
virtual GVector operator* (const GVector &vector) const
 Vector multiplication. More...
 
virtual GMatrixoperator= (const GMatrix &matrix)
 Matrix assignment operator. More...
 
virtual GMatrixoperator= (const double &value)
 Value assignment operator. More...
 
virtual GMatrix operator+ (const GMatrix &matrix) const
 Binary matrix addition. More...
 
virtual GMatrix operator+ (const double &scalar) const
 Binary matrix scalar addition. More...
 
virtual GMatrix operator- (const GMatrix &matrix) const
 Binary matrix subtraction. More...
 
virtual GMatrix operator- (const double &scalar) const
 Binary matrix scalar subtraction. More...
 
virtual GMatrix operator* (const GMatrix &matrix) const
 Binary matrix multiplication. More...
 
virtual GMatrix operator- (void) const
 Negate matrix elements. More...
 
virtual GMatrixoperator+= (const GMatrix &matrix)
 Unary matrix addition operator. More...
 
virtual GMatrixoperator+= (const double &scalar)
 Unary matrix scalar addition operator. More...
 
virtual GMatrixoperator-= (const GMatrix &matrix)
 Unary matrix subtraction operator. More...
 
virtual GMatrixoperator-= (const double &scalar)
 Unary matrix scalar subtraction operator. More...
 
virtual GMatrixoperator*= (const GMatrix &matrix)
 Unary matrix multiplication operator. More...
 
virtual GMatrixoperator*= (const double &scalar)
 Scale matrix elements. More...
 
virtual GMatrixoperator/= (const double &scalar)
 Divide matrix elements. More...
 
virtual void clear (void)
 Clear matrix. More...
 
virtual GMatrixclone (void) const
 Clone matrix. More...
 
virtual std::string classname (void) const
 Return class name. More...
 
virtual double & at (const int &row, const int &column)
 Return reference to matrix element. More...
 
virtual const double & at (const int &row, const int &column) const
 Return reference to matrix element (const version) More...
 
virtual GVector row (const int &row) const
 Extract row as vector from matrix. More...
 
virtual void row (const int &row, const GVector &vector)
 Set row in matrix. More...
 
virtual GVector column (const int &column) const
 Extract column as vector from matrix. More...
 
virtual void column (const int &column, const GVector &vector)
 Set matrix column from vector. More...
 
virtual void add_to_row (const int &row, const GVector &vector)
 Add row to matrix elements. More...
 
virtual void add_to_column (const int &column, const GVector &vector)
 Add vector column into matrix. More...
 
virtual double fill (void) const
 Return fill of matrix. More...
 
virtual double min (void) const
 Return minimum matrix element. More...
 
virtual double max (void) const
 Return maximum matrix element. More...
 
virtual double sum (void) const
 Return matrix element sum. More...
 
virtual std::string print (const GChatter &chatter=NORMAL) const
 Print matrix. More...
 
GMatrix transpose (void) const
 Return transposed matrix. More...
 
GMatrix invert (void) const
 Return inverted matrix. More...
 
GVector solve (const GVector &vector) const
 Solves linear matrix equation. More...
 
GMatrix abs (void) const
 Return absolute of matrix. More...
 
GMatrix extract_lower_triangle (void) const
 Extract lower triangle of matrix. More...
 
GMatrix extract_upper_triangle (void) const
 Extract upper triangle of matrix. More...
 
void eulerx (const double &angle)
 Set Euler rotation matrix around x axis. More...
 
void eulery (const double &angle)
 Set Euler rotation matrix around y axis. More...
 
void eulerz (const double &angle)
 Set Euler rotation matrix around z axis. More...
 
- Public Member Functions inherited from GMatrixBase
 GMatrixBase (void)
 Void constructor. More...
 
 GMatrixBase (const GMatrixBase &matrix)
 Copy constructor. More...
 
virtual ~GMatrixBase (void)
 Destructor. More...
 
virtual GMatrixBaseoperator= (const GMatrixBase &matrix)
 Assignment operator. More...
 
virtual bool operator== (const GMatrixBase &matrix) const
 Equalty operator. More...
 
virtual bool operator!= (const GMatrixBase &matrix) const
 Non-equality operator. More...
 
bool is_empty (void) const
 Check if matrix is empty. More...
 
const int & size (void) const
 Return number of matrix elements. More...
 
const int & columns (void) const
 Return number of matrix columns. More...
 
const int & rows (void) const
 Return number of matrix rows. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Private Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const GMatrix &matrix)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void alloc_members (const int &rows, const int &columns)
 Allocate matrix memory. More...
 

Additional Inherited Members

- Protected Member Functions inherited from GMatrixBase
void init_members (void)
 Initialise class members. More...
 
void copy_members (const GMatrixBase &matrix)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void select_non_zero (void)
 Setup compressed matrix factorisation. More...
 
void scale_elements (const double &scalar)
 Scale all matrix elements with a scalar. More...
 
void set_all_elements (const double &value)
 Set all elements to a specific value. More...
 
double get_min_element (void) const
 Return minimum matrix element. More...
 
double get_max_element (void) const
 Returns maximum matrix element. More...
 
double get_element_sum (void) const
 Returns sum over all matrix elements. More...
 
std::string print_elements (const GChatter &chatter=NORMAL, const int &num=15) const
 Print all matrix elements. More...
 
std::string print_row_compression (const GChatter &chatter=NORMAL) const
 Print row compression scheme if it exists. More...
 
std::string print_col_compression (const GChatter &chatter=NORMAL) const
 Print column compression scheme if it exists. More...
 
- Protected Attributes inherited from GMatrixBase
int m_rows
 Number of rows. More...
 
int m_cols
 Number of columns. More...
 
int m_elements
 Number of elements stored in matrix. More...
 
int m_alloc
 Size of allocated matrix memory. More...
 
int m_num_rowsel
 Number of selected rows (for compressed decomposition) More...
 
int m_num_colsel
 Number of selected columns (for compressed decomposition) More...
 
int * m_colstart
 Column start indices (m_cols+1) More...
 
int * m_rowsel
 Row selection (for compressed decomposition) More...
 
int * m_colsel
 Column selection (for compressed decomposition) More...
 
double * m_data
 Matrix data. More...
 

Detailed Description

Generic matrix class definition.

This class implements a generic matrix. The class is a non-specialized representation of a matrix, and all other matrix storage classes can be converted into that class.

For a description of the common matrix methods, please refer to the GMatrixBase class.

Matrix allocation is done using the constructors

GMatrix matrix(rows, columns);
GMatrix matrix(matrix);
GMatrix matrix(sparsematrix);
GMatrix matrix(symmetricmatrix);

where rows and columns specify the number of rows and columns of the matrix. Storage conversion constructors exist that allow allocating a generic matrix by copying from a sparse matrix of type GMatrixSparse and a symmetric matrix of type GMatrixSymmetric.

To support using the GMatrix for coordinate transformations, methods are available to compute matrices for the three Euler angles:

matrix.eulerx(angle);
matrix.eulery(angle);
matrix.eulerz(angle);

Methods are also available to extract the lower or the upper triangle of a matrix:

matrix.extract_lower_triangle();
matrix.extract_upper_triangle();

Matrix elements are stored column-wise by the class.

Definition at line 79 of file GMatrix.hpp.

Constructor & Destructor Documentation

GMatrix::GMatrix ( void  )

Void matrix constructor.

Constructs an empty matrix. An empty matrix has zero rows and columns.

Definition at line 70 of file GMatrix.cpp.

References init_members().

Referenced by clone().

GMatrix::GMatrix ( const int &  rows,
const int &  columns 
)
explicit

Matrix constructor.

Parameters
[in]rowsNumber of rows [>=0].
[in]columnsNumber of columns [>=0].
Exceptions
GException::invalid_argumentNumber of rows or columns is negative.

Constructs a matrix with the specified number of rows and columns. The memory for all matrix elements will be allocated and all matrix elements will be initialized to 0.

Definition at line 93 of file GMatrix.cpp.

References alloc_members(), G_CONSTRUCTOR, init_members(), and gammalib::str().

GMatrix::GMatrix ( const GMatrix matrix)

Copy constructor.

Parameters
[in]matrixMatrix.

Definition at line 126 of file GMatrix.cpp.

References copy_members(), and init_members().

GMatrix::GMatrix ( const GMatrixSymmetric matrix)

GMatrixSymmetric to GMatrix storage class convertor.

Parameters
[in]matrixSymmetric matrix (GMatrixSymmetric).

Constructs a GMatrix object from a symmetric matrix object of type GMatrixSymmetric. Since the result is a generic matrix, the constructor will succeed in all cases.

Definition at line 148 of file GMatrix.cpp.

References alloc_members(), GMatrixBase::columns(), init_members(), GMatrixBase::m_cols, GMatrixBase::m_rows, row(), and GMatrixBase::rows().

GMatrix::GMatrix ( const GMatrixSparse matrix)

GMatrixSparse to GMatrix storage class convertor.

Parameters
[in]matrixSparse matrix (GMatrixSparse).

Constructs a GMatrix object from a sparse matrix object of type GMatrixSparse. Since the result is a generic matrix, the constructor will succeed in all cases.

Definition at line 181 of file GMatrix.cpp.

References alloc_members(), GMatrixBase::columns(), init_members(), GMatrixBase::m_cols, GMatrixBase::m_rows, row(), and GMatrixBase::rows().

GMatrix::~GMatrix ( void  )
virtual

Destructor.

Definition at line 204 of file GMatrix.cpp.

References free_members().

Member Function Documentation

GMatrix GMatrix::abs ( void  ) const

Return absolute of matrix.

Returns
Absolute of matrix

Returns matrix where all elements of the matrix have been replaced by their absolute values.

Definition at line 983 of file GMatrix.cpp.

References abs(), GMatrixBase::m_cols, GMatrixBase::m_data, GMatrixBase::m_elements, and GMatrixBase::m_rows.

void GMatrix::add_to_column ( const int &  column,
const GVector vector 
)
virtual

Add vector column into matrix.

Parameters
[in]columnMatrix column [0,...,columns()[.
[in]vectorVector.
Exceptions
GException::out_of_rangeInvalid matrix column specified.
GException::matrix_vector_mismatchVector size does not match number of matrix rows.

Adds the content of a vector to a matrix column.

Implements GMatrixBase.

Definition at line 857 of file GMatrix.cpp.

References column(), G_ADD_TO_COLUMN, GMatrixBase::m_cols, GMatrixBase::m_colstart, GMatrixBase::m_data, GMatrixBase::m_elements, GMatrixBase::m_rows, row(), GVector::size(), and gammalib::str().

void GMatrix::add_to_row ( const int &  row,
const GVector vector 
)
virtual

Add row to matrix elements.

Parameters
[in]rowMatrix row [0,...,rows()[.
[in]vectorVector of matrix row elements (columns() elements).
Exceptions
GException::out_of_rangeInvalid matrix row specified.
GException::matrix_vector_mismatchVector does not match the matrix dimensions.

Implements GMatrixBase.

Definition at line 812 of file GMatrix.cpp.

References G_ADD_TO_ROW, GMatrixBase::m_cols, GMatrixBase::m_data, GMatrixBase::m_rows, GVector::size(), and gammalib::str().

void GMatrix::alloc_members ( const int &  rows,
const int &  columns 
)
private

Allocate matrix memory.

Parameters
[in]rowsNumber of matrix rows.
[in]columnsNumber of matrix columns.

Allocates memory for the matrix elements. The method assumes that no memory has been allocated for the matrix elements and the column start index array. The method allocates the memory for matrix elements and the column start indices, sets all matrix elements to 0, and sets the column start indices.

If either the number of rows or the number of columns is non-positive, the method does nothing.

Definition at line 1324 of file GMatrix.cpp.

References GMatrixBase::columns(), GMatrixBase::m_alloc, GMatrixBase::m_cols, GMatrixBase::m_colstart, GMatrixBase::m_data, GMatrixBase::m_elements, GMatrixBase::m_rows, and GMatrixBase::rows().

Referenced by eulerx(), eulery(), eulerz(), and GMatrix().

double & GMatrix::at ( const int &  row,
const int &  column 
)
virtual

Return reference to matrix element.

Parameters
[in]rowMatrix row [0,...,rows()[.
[in]columnMatrix column [0,...,columns()[.
Returns
Reference to matrix element.
Exceptions
GException::out_of_rangeMatrix row or column out of range.

Returns a reference to the matrix element at row and column.

This method verifies the validity of the row and column argument.

Implements GMatrixBase.

Definition at line 580 of file GMatrix.cpp.

References G_AT, GMatrixBase::m_cols, GMatrixBase::m_colstart, GMatrixBase::m_data, and GMatrixBase::m_rows.

const double & GMatrix::at ( const int &  row,
const int &  column 
) const
virtual

Return reference to matrix element (const version)

Parameters
[in]rowMatrix row [0,...,rows()[.
[in]columnMatrix column [0,...,columns()[.
Returns
Const reference to matrix element.
Exceptions
GException::out_of_rangeMatrix row or column out of range.

Returns a const reference to the matrix element at row and column.

This method verifies the validity of the row and column argument.

Implements GMatrixBase.

Definition at line 609 of file GMatrix.cpp.

References G_AT, GMatrixBase::m_cols, GMatrixBase::m_colstart, GMatrixBase::m_data, and GMatrixBase::m_rows.

std::string GMatrix::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GMatrix").

Implements GMatrixBase.

Definition at line 156 of file GMatrix.hpp.

void GMatrix::clear ( void  )
virtual

Clear matrix.

Implements GMatrixBase.

Definition at line 541 of file GMatrix.cpp.

References free_members(), and init_members().

Referenced by GCTAPointing::init_members().

GMatrix * GMatrix::clone ( void  ) const
virtual

Clone matrix.

Returns
Pointer to deep copy of matrix.

Implements GMatrixBase.

Definition at line 559 of file GMatrix.cpp.

References GMatrix().

GVector GMatrix::column ( const int &  column) const
virtual

Extract column as vector from matrix.

Parameters
[in]columnMatrix column [0,...,columns()[.
Returns
Vector of matrix column elements (rows() elements).
Exceptions
GException::out_of_rangeInvalid matrix column specified.

This method extracts a matrix column into a vector.

Implements GMatrixBase.

Definition at line 718 of file GMatrix.cpp.

References G_EXTRACT_COLUMN, GMatrixBase::m_cols, GMatrixBase::m_colstart, GMatrixBase::m_data, GMatrixBase::m_elements, GMatrixBase::m_rows, and row().

Referenced by add_to_column(), column(), GMatrixSparse::GMatrixSparse(), and GCTAResponseCube::irf_radial().

void GMatrix::column ( const int &  column,
const GVector vector 
)
virtual

Set matrix column from vector.

Parameters
[in]columnMatrix column [0,...,columns()[.
[in]vectorVector.
Exceptions
GException::out_of_rangeInvalid matrix column specified.
GException::invalid_argumentVector size does not match number of matrix rows.

Inserts the content of a vector into a matrix column. Any previous content in the matrix column will be overwritted.

Implements GMatrixBase.

Definition at line 763 of file GMatrix.cpp.

References column(), G_SET_COLUMN, GMatrixBase::m_cols, GMatrixBase::m_colstart, GMatrixBase::m_data, GMatrixBase::m_elements, GMatrixBase::m_rows, row(), GVector::size(), and gammalib::str().

void GMatrix::copy_members ( const GMatrix matrix)
private

Copy class members.

Parameters
[in]matrixMatrix.

Definition at line 1292 of file GMatrix.cpp.

Referenced by GMatrix(), and operator=().

void GMatrix::eulerx ( const double &  angle)

Set Euler rotation matrix around x axis.

Parameters
[in]angleRotation angle (degrees)

Definition at line 1120 of file GMatrix.cpp.

References alloc_members(), cos(), gammalib::deg2rad, GMatrixBase::free_members(), GMatrixBase::init_members(), and sin().

GMatrix GMatrix::extract_lower_triangle ( void  ) const

Extract lower triangle of matrix.

Exceptions
GException::invalid_argumentMatrix is not a square matrix.

This method extracts the lower triangle of a matrix into another matrix. (including the diagonal elements). All remaining matrix elements will be zero.

Triangular extraction only works for square matrixes.

Definition at line 1049 of file GMatrix.cpp.

References G_EXTRACT_LOWER, GMatrixBase::m_cols, GMatrixBase::m_colstart, GMatrixBase::m_data, GMatrixBase::m_rows, row(), and gammalib::str().

GMatrix GMatrix::extract_upper_triangle ( void  ) const

Extract upper triangle of matrix.

Exceptions
GException::invalid_argumentMatrix is not a square matrix.

This method extracts the upper triangle of a matrix into another matrix. (including the diagonal elements). All remaining matrix elements will be zero.

Triangular extraction only works for square matrixes.

Definition at line 1088 of file GMatrix.cpp.

References G_EXTRACT_UPPER, GMatrixBase::m_cols, GMatrixBase::m_colstart, GMatrixBase::m_data, GMatrixBase::m_rows, row(), and gammalib::str().

double GMatrix::fill ( void  ) const
virtual

Return fill of matrix.

Returns
Matrix fill (between 0 and 1).

Returns the fill of the matrix. The fill of a matrix is defined as the number non-zero elements devided by the number of total elements. By definition, the fill is comprised in the interval [0,..,1].

The fill of a matrix with zero elements will be set to 0.

Implements GMatrixBase.

Definition at line 1011 of file GMatrix.cpp.

References GMatrixBase::m_data, and GMatrixBase::m_elements.

void GMatrix::free_members ( void  )
private

Delete class members.

Definition at line 1302 of file GMatrix.cpp.

Referenced by clear(), operator=(), and ~GMatrix().

void GMatrix::init_members ( void  )
private

Initialise class members.

Definition at line 1280 of file GMatrix.cpp.

Referenced by clear(), GMatrix(), and operator=().

GMatrix GMatrix::invert ( void  ) const

Return inverted matrix.

Returns
Inverted matrix.
Exceptions
GException::feature_not_implementedFeature not yet implemented.

Returns inverse of matrix.

Todo:
Needs to be implemented.

Definition at line 932 of file GMatrix.cpp.

References G_INVERT, GMatrixBase::m_cols, and GMatrixBase::m_rows.

double GMatrix::max ( void  ) const
inlinevirtual

Return maximum matrix element.

Returns
Maximum element in matrix.

Returns the largest element in the matrix.

Implements GMatrixBase.

Definition at line 339 of file GMatrix.hpp.

References GMatrixBase::get_max_element().

double GMatrix::min ( void  ) const
inlinevirtual

Return minimum matrix element.

Returns
Minimum element in matrix.

Returns the smallest element in the matrix.

Implements GMatrixBase.

Definition at line 325 of file GMatrix.hpp.

References GMatrixBase::get_min_element().

double & GMatrix::operator() ( const int &  row,
const int &  column 
)
inlinevirtual

Return reference to matrix element.

Parameters
[in]rowMatrix row [0,...,rows()-1].
[in]columnMatrix column [0,...,columns()-1].
Returns
Reference to matrix element.

Returns a reference to the matrix element at row and column.

Implements GMatrixBase.

Definition at line 172 of file GMatrix.hpp.

References GMatrixBase::m_colstart, and GMatrixBase::m_data.

const double & GMatrix::operator() ( const int &  row,
const int &  column 
) const
inlinevirtual

Return reference to matrix element (const version)

Parameters
[in]rowMatrix row [0,...,rows()-1].
[in]columnMatrix column [0,...,columns()-1].
Returns
Const reference to matrix element.

Returns a const reference to the matrix element at row and column.

Implements GMatrixBase.

Definition at line 188 of file GMatrix.hpp.

References GMatrixBase::m_colstart, and GMatrixBase::m_data.

GVector GMatrix::operator* ( const GVector vector) const
virtual

Vector multiplication.

Parameters
[in]vectorVector.
Exceptions
GException::invalid_argumentVector size differs from number of columns in matrix.

This method performs a vector multiplication of a matrix. The vector multiplication will produce a vector. The multiplication can only be performed when the number of matrix columns is identical to the size of the vector. If the size of the vector differs an exception will be thrown.

Implements GMatrixBase.

Definition at line 289 of file GMatrix.cpp.

References G_OP_MUL_VEC, GMatrixBase::m_cols, GMatrixBase::m_data, GMatrixBase::m_rows, row(), GVector::size(), gammalib::str(), and sum().

GMatrix GMatrix::operator* ( const GMatrix matrix) const
inlinevirtual

Binary matrix multiplication.

Parameters
[in]matrixMatrix.
Returns
Result of matrix multiplication.

Returns the product of two matrices. The method makes use of the unary multiplication operator.

Definition at line 275 of file GMatrix.hpp.

GMatrix & GMatrix::operator*= ( const GMatrix matrix)
virtual

Unary matrix multiplication operator.

Parameters
[in]matrixMatrix.
Exceptions
GException::invalid_argumentNumber of rows in matrix is different from number of matrix columns.

This method performs a matrix multiplication. The operation can only succeed when the dimensions of both matrices are compatible.

In case of rectangular matrices the result matrix does not change and the operation is performed inplace. For the general case the result matrix changes in size and for simplicity a new matrix is allocated to hold the result.

Definition at line 479 of file GMatrix.cpp.

References G_OP_MAT_MUL, GMatrixBase::m_cols, GMatrixBase::m_rows, row(), gammalib::str(), and sum().

GMatrix & GMatrix::operator*= ( const double &  scalar)
inlinevirtual

Scale matrix elements.

Parameters
[in]scalarScale factor.
Returns
Matrix with elements multiplied by scalar.

Returns a matrix where all elements have been multiplied by the specified scalar value.

Definition at line 293 of file GMatrix.hpp.

References GMatrixBase::scale_elements().

GMatrix GMatrix::operator+ ( const GMatrix matrix) const
inlinevirtual

Binary matrix addition.

Parameters
[in]matrixMatrix.
Returns
Result of matrix addition.

Returns the sum of two matrices. The method makes use of the unary addition operator.

Definition at line 204 of file GMatrix.hpp.

GMatrix GMatrix::operator+ ( const double &  scalar) const
inlinevirtual

Binary matrix scalar addition.

Parameters
[in]scalarScalar.
Returns
Matrix with scalar added.

Returns a matrix where a scalar has been added to each matrix element.

Definition at line 221 of file GMatrix.hpp.

GMatrix & GMatrix::operator+= ( const GMatrix matrix)
virtual

Unary matrix addition operator.

Parameters
[in]matrixMatrix.
Exceptions
GException::invalid_argumentIncompatible number of matrix rows or columns.

This method performs a matrix addition. The method throws an exception if the number of matrix rows or columns are not identical.

Definition at line 351 of file GMatrix.cpp.

References G_OP_ADD, GMatrixBase::m_cols, GMatrixBase::m_data, GMatrixBase::m_elements, GMatrixBase::m_rows, and gammalib::str().

GMatrix & GMatrix::operator+= ( const double &  scalar)
virtual

Unary matrix scalar addition operator.

Parameters
[in]scalarScalar.

Adds a scalar to each matrix element.

Definition at line 388 of file GMatrix.cpp.

References GMatrixBase::m_data, and GMatrixBase::m_elements.

GMatrix GMatrix::operator- ( const GMatrix matrix) const
inlinevirtual

Binary matrix subtraction.

Parameters
[in]matrixMatrix.
Returns
Result of matrix subtraction.

Returns the difference between two matrices. The method makes use of the unary subtraction operator.

Definition at line 239 of file GMatrix.hpp.

GMatrix GMatrix::operator- ( const double &  scalar) const
inlinevirtual

Binary matrix scalar subtraction.

Parameters
[in]scalarScalar.
Returns
Matrix with scalar subtracted.

Returns a matrix where a scalar has been subtracted from each matrix element.

Definition at line 257 of file GMatrix.hpp.

GMatrix GMatrix::operator- ( void  ) const
virtual

Negate matrix elements.

Returns
Matrix with negated elements.

Returns a matrix where each element has been replaced by its negative element.

Definition at line 324 of file GMatrix.cpp.

References GMatrixBase::m_data, and GMatrixBase::m_elements.

GMatrix & GMatrix::operator-= ( const GMatrix matrix)
virtual

Unary matrix subtraction operator.

Parameters
[in]matrixMatrix.
Exceptions
GException::invalid_argumentIncompatible number of matrix rows or columns.

This method performs a matrix addition. The method throws an exception if the number of matrix rows or columns are not identical.

Definition at line 412 of file GMatrix.cpp.

References G_OP_SUB, GMatrixBase::m_cols, GMatrixBase::m_data, GMatrixBase::m_elements, GMatrixBase::m_rows, and gammalib::str().

GMatrix & GMatrix::operator-= ( const double &  scalar)
virtual

Unary matrix scalar subtraction operator.

Parameters
[in]scalarScalar.

Subtracts a scalar from each matrix element.

Definition at line 449 of file GMatrix.cpp.

References GMatrixBase::m_data, and GMatrixBase::m_elements.

GMatrix & GMatrix::operator/= ( const double &  scalar)
inlinevirtual

Divide matrix elements.

Parameters
[in]scalarScalar.
Returns
Matrix with elements divided by scalar.

Returns a matrix where all elements have been divided by the specified scalar value.

Definition at line 310 of file GMatrix.hpp.

GMatrix & GMatrix::operator= ( const GMatrix matrix)
virtual

Matrix assignment operator.

Parameters
[in]matrixMatrix.
Returns
Matrix.

Assigns the content of another matrix to the actual matrix instance.

Definition at line 228 of file GMatrix.cpp.

References copy_members(), free_members(), init_members(), and GMatrixBase::operator=().

GMatrix & GMatrix::operator= ( const double &  value)
virtual

Value assignment operator.

Parameters
[in]valueValue.
Returns
Matrix.

Assigns the specified value to all elements of the matrix.

Definition at line 262 of file GMatrix.cpp.

References GMatrixBase::m_data, and GMatrixBase::m_elements.

std::string GMatrix::print ( const GChatter chatter = NORMAL) const
virtual
GVector GMatrix::row ( const int &  row) const
virtual

Extract row as vector from matrix.

Parameters
[in]rowMatrix row [0,...,rows()[.
Returns
Vector of matrix row elements (columns() elements).
Exceptions
GException::out_of_rangeInvalid matrix row specified.

Extracts one row of the matrix into a vector. The vector will contain columns() elements.

Implements GMatrixBase.

Definition at line 637 of file GMatrix.cpp.

References G_EXTRACT_ROW, GMatrixBase::m_cols, GMatrixBase::m_data, and GMatrixBase::m_rows.

Referenced by add_to_column(), column(), extract_lower_triangle(), extract_upper_triangle(), GMatrix(), operator*(), operator*=(), and transpose().

void GMatrix::row ( const int &  row,
const GVector vector 
)
virtual

Set row in matrix.

Parameters
[in]rowMatrix row [0,...,rows()[.
[in]vectorVector of matrix row elements (columns() elements).
Exceptions
GException::out_of_rangeInvalid matrix row specified.
GException::invalid_argumentVector size does not match number of matrix columns.

Sets the elements from a vector as the elements of a matrix row. The size of the vector must be identical to the number of columns in the matrix.

Implements GMatrixBase.

Definition at line 676 of file GMatrix.cpp.

References G_SET_ROW, GMatrixBase::m_cols, GMatrixBase::m_data, GMatrixBase::m_rows, GVector::size(), and gammalib::str().

GVector GMatrix::solve ( const GVector vector) const

Solves linear matrix equation.

Parameters
[in]vectorSolution vector.
Exceptions
GException::feature_not_implementedFeature not yet implemented.

Solves the linear equation

\[M \times {\tt solution} = {\tt vector} \]

where \(M\) is the matrix, \({\tt vector}\) is the result, and \({\tt solution}\) is the solution.

Todo:
Needs to be implemented.

Definition at line 962 of file GMatrix.cpp.

References G_SOLVE.

double GMatrix::sum ( void  ) const
inlinevirtual

Return matrix element sum.

Returns
Sum of all matrix elements.

Returns the sum of all matrix elements.

Implements GMatrixBase.

Definition at line 353 of file GMatrix.hpp.

References GMatrixBase::get_element_sum().

Referenced by operator*(), and operator*=().

GMatrix GMatrix::transpose ( void  ) const

Return transposed matrix.

Returns
Transposed matrix.

Returns transposed matrix of the matrix.

Definition at line 903 of file GMatrix.cpp.

References GMatrixBase::m_cols, GMatrixBase::m_rows, and row().

Referenced by GCTAPointing::instdir().


The documentation for this class was generated from the following files: