GemaCoreLib
The GeMA Core library
Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
GmCRMatrix Class Reference

An auxiliary matrix WRAPPER that binds the matrix to a CONST memory area with data already inicialized and interpreted in COLUMN MAJOR FORMAT. More...

#include <gmMatrix.h>

Public Types

typedef double elem_type
 the type of elements stored in the matrix
 

Public Member Functions

 GmCRMatrix (const double *data, int nlin, int ncol)
 Constructs the matrix pointing to a const memory area represented in COLUMN MAJOR ORDER.
 
 GmCRMatrix ()
 Constructs an empty matrix that needs to be initialized later by a call to setMemory()
 
 operator const GmMatrix & ()
 Returns the wrapped matrix as a CONST reference.
 
const GmMatrixm ()
 Returns the wrapped matrix as a CONST reference.
 
void setMemory (const double *data, int nlin, int ncol)
 Exchanges the memory area used by the matrix. Same caveats explained in the class documentation apply.
 
const double & operator[] (unsigned int ii) const
 
const double & at (unsigned int ii) const
 
const double & operator() (unsigned int ii) const
 
const double & at (unsigned int in_row, unsigned int in_col) const
 
const double & operator() (unsigned int in_row, unsigned int in_col) const
 
bool is_empty () const
 
bool is_vec () const
 
bool is_rowvec () const
 
bool is_colvec () const
 
bool is_square () const
 
bool in_range (unsigned int ii) const
 
bool in_range (unsigned int in_row, unsigned int in_col) const
 
const double * colptr (unsigned int in_col) const
 
const double * memptr () const
 
bool empty () const
 
unsigned int size () const
 

Public Attributes

const unsigned int n_rows
 number of rows in the matrix (read-only)
 
const unsigned int n_cols
 number of columns in the matrix (read-only)
 
const unsigned int n_elem
 number of elements in the matrix (read-only)
 

Private Attributes

GmMatrix _mat
 The wrapped matrix.
 

Detailed Description

An auxiliary matrix WRAPPER that binds the matrix to a CONST memory area with data already inicialized and interpreted in COLUMN MAJOR FORMAT.

Armadillo matrices can be build referencing some external memory as can be seen by the DECLARE_REF_MATRIX() macro, but it can't take a reference to a const memory area since there is no way to make a matrix read only (and no way to directly guarantee that a constructed matrix will be used only by const objects).

This wrapper class allows this by wrapping an Armadillo matrix inside it and providing only constant access methods. In particluar, an object of type GmCRMatrix can be implicitly casted to a const reference to an Armadillo matrix which allows it to participate in some right hand side of expressions. In others, due to the havy template magic used by Armadillo, it might be necessary to call the m() member to explicitly call the conversion.

IMPORTANT points to REMEMBER: This matrix will be valid only while the memory it points to remains valid. It won't take ownership of the memory, so it won't release the memory when the matrix wrapper is destroyed.


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