25#ifndef _GEMA_ARMADILLO_SOLVER_MATRIX_H_
26#define _GEMA_ARMADILLO_SOLVER_MATRIX_H_
87 virtual int nlin()
const {
return _mat.n_rows; }
90 virtual int ncol()
const {
return _mat.n_cols; }
105 virtual void add(
int lin,
int col,
double val) {
_mat(lin, col) += val; }
110 Q_UNUSED(sameStructure);
121 for(
unsigned int j = 0; j<
_mat.n_cols; j++)
122 for(
unsigned int i = 0; i<
_mat.n_rows; i++)
123 _mat(i, j) = A->
at(i, j) + c * B->
at(i, j);
131 virtual void clear(
bool keepSparseLayout)
133 Q_UNUSED(keepSparseLayout);
142 Q_UNUSED(keepSparseLayout);
144 foreach(
int i, indexList)
157 for(
int i = 0; i <
_mat.n_rows; i++)
159 if(
_mat(i, i) == 0.0)
168 assert(a.n_rows ==
_mat.n_rows);
169 assert(b.n_rows ==
_mat.n_cols);
170 for(
int j = 0; j <
_mat.n_cols; j++)
173 for(
int i = 0; i <
_mat.n_rows; i++)
175 double v =
_mat(i, j) + a[i] * bv;
176 if(fabs(v) > zeroTol)
186 assert(a.n_elem ==
_mat.n_cols);
194 assert(a.n_elem ==
_mat.n_cols);
202 assert(a.n_elem ==
_mat.n_cols);
210 assert(f.n_elem ==
_mat.n_rows);
211 for(
int i = 0; i <
_mat.n_rows; i++)
213 if(skipRows && skipRows[i])
215 f[i] +=
_mat(i, col) * v;
270 virtual void add(
int lin,
int col,
double val);
291 bool doEnd(
bool ordered);
293 virtual void addFromThread(
int tid,
int lin,
int col,
double val);
A virtual class representing a buffer of T objects that can be appended in a thread-safe way,...
Definition gmAppendBuffer.h:66
An implementation of the GmSolverMatrix interface using as base the Armadillo library.
Definition gmArmadilloSolverMatrix.h:40
virtual void columnMulAdd(int col, GmVector &f, double v, const bool *skipRows=NULL) const
Updates the given vector adding to it a matrix column multiplied by a scalar value.
Definition gmArmadilloSolverMatrix.h:207
virtual GmSparseMatrixLayoutBuilder * layoutBuilder() const
If the matrix supports sparse layouts, returns a builder object that can be used to initialize the ma...
Definition gmArmadilloSolverMatrix.h:75
virtual void setSymmetric(bool sym)
Marks the matrix as symmetric or not.
Definition gmArmadilloSolverMatrix.h:84
virtual void add(int lin, int col, double val)
Adds the given value to the value in the position Mat[lin][col].
Definition gmArmadilloSolverMatrix.h:105
T _mat
The Armadillo matrix.
Definition gmArmadilloSolverMatrix.h:239
QAtomicInt _sym
Flag marking the matrix as symmetric or not.
Definition gmArmadilloSolverMatrix.h:240
virtual bool emptyLayout() const
If the matrix supports sparse layouts and the layout is currently empty, returns true....
Definition gmArmadilloSolverMatrix.h:78
virtual double at(int lin, int col) const
Returns the value in the position Mat[lin][col].
Definition gmArmadilloSolverMatrix.h:96
virtual void mulAdd(const GmVector &a, GmVector &b) const
Multiplies the matrix ('X') by a vector 'a' adding the result to 'b' (b = b + X * a).
Definition gmArmadilloSolverMatrix.h:191
virtual bool beginBatchInsert(size_t expectedEntries=0)
Begins a batch insert process. Important: see comments on the class documentation.
Definition gmArmadilloSolverMatrix.h:69
virtual void ensureDiagonal()
Updates any zero diagonal value to 1.0. If diagonal values do not belong to the layout,...
Definition gmArmadilloSolverMatrix.h:154
virtual void mulSub(const GmVector &a, GmVector &b) const
Multiplies the matrix ('X') by a vector 'a' subtracting the result from 'b' (b = b - X * a).
Definition gmArmadilloSolverMatrix.h:199
virtual void matAdd(const GmVector &a, const GmVector &b, double zeroTol=0.0)
Adds to the current matrix ('X') the (dense) matrix resulting from multiplying the column vector 'a' ...
Definition gmArmadilloSolverMatrix.h:165
virtual bool inLayout(int lin, int col) const
Returns true if the given position belongs to the matrix sparse layout.
Definition gmArmadilloSolverMatrix.h:99
GmArmadilloSolverMatrixBase(int nlin, int ncol, GmSparseMatrixOptions options=GmSparseMatrixOptions(GM_ARMADILLO_TRIPLET_LIST))
Constructor. Receives as parameters the matrix size.
Definition gmArmadilloSolverMatrix.h:43
virtual bool supportsSparseLayouts() const
Does this matrix supports sparse layouts? See comments on the class documentation.
Definition gmArmadilloSolverMatrix.h:60
virtual void set(GmSolverMatrix *A, GmSolverMatrix *B, double c, bool sameStructure)
Sets the values of the whole matrix to the result of the expression A + c * B, where A and B are matr...
Definition gmArmadilloSolverMatrix.h:108
virtual int nlin() const
Returns the number of lines in the matrix. IMPORTANT: This function implementation MUST be thread saf...
Definition gmArmadilloSolverMatrix.h:87
virtual bool saveMatrixCoordinatesToFile(FILE *f) const
Helper function to GmNumSolver saving capabilities, responsible for saving the matrix contents to the...
Definition gmArmadilloSolverMatrix.h:233
T & armadilloMatrix()
Returns the internal Armadillo matrix.
Definition gmArmadilloSolverMatrix.h:220
virtual void clear(bool keepSparseLayout)
Clears the matrix, filling it with zeros. The keepSparseLayout flag is a hint that the matrix layout ...
Definition gmArmadilloSolverMatrix.h:131
virtual bool hasNanInf() const
Returns true if the matrix contains nan or inf values.
Definition gmArmadilloSolverMatrix.h:226
virtual int layoutSize() const
Returns the size of the sparse matrix layout.
Definition gmArmadilloSolverMatrix.h:93
virtual bool symmetric() const
Returns true if the matrix was marked as symmetric by setSymmetric() (it does not check for matrix sy...
Definition gmArmadilloSolverMatrix.h:81
virtual void mul(const GmVector &a, GmVector &b) const
Multiplies the matrix ('X') by a vector 'a' storing the result in 'b' (b = X * a).
Definition gmArmadilloSolverMatrix.h:183
virtual void set(int lin, int col, double val)
Sets the value in the position Mat[lin][col] to the specified value.
Definition gmArmadilloSolverMatrix.h:102
virtual bool endBatchInsert(bool discardData=false)
Ends a batch insert process. Important: see comments on the class documentation.
Definition gmArmadilloSolverMatrix.h:72
virtual int ncol() const
Returns the number of columns in the matrix. IMPORTANT: This function implementation MUST be thread s...
Definition gmArmadilloSolverMatrix.h:90
virtual bool supportsBatchInsert() const
Does this matrix supports batch inserts? See comments on the class documentation.
Definition gmArmadilloSolverMatrix.h:57
virtual size_t usedMemory() const
Returns an estimative of the memory used by the matrix in bytes.
Definition gmArmadilloSolverMatrix.h:223
virtual bool supportsRandomSet() const
Does this matrix supports setting a value on a random position outside the matrix initialization proc...
Definition gmArmadilloSolverMatrix.h:63
virtual ~GmArmadilloSolverMatrixBase()
Destructor.
Definition gmArmadilloSolverMatrix.h:54
virtual ParallelAddMode supportedParallelAddMode() const
Returns the supported mode for calling add.
Definition gmArmadilloSolverMatrix.h:66
virtual void clearLineAndColumnSet(const QVector< int > &indexList, bool setDiagonal, bool keepSparseLayout)
Clears a set of lines and columns from the matrix, filling them with zeroes, optionally putting a 1....
Definition gmArmadilloSolverMatrix.h:140
The standard 'Sparse' matrix based on Armadillo.
Definition gmArmadilloSolverMatrix.h:248
virtual void set(int lin, int col, double val)
Sets the value in the position Mat[lin][col] to the specified value.
Definition gmArmadilloSolverMatrix.h:280
GmAppendBuffer< double > * _values
The values array while batch inserting values (size = _positions size / 2)
Definition gmArmadilloSolverMatrix.h:300
virtual bool supportsRandomSet() const
Does this matrix supports setting a value on a random position outside the matrix initialization proc...
Definition gmArmadilloSolverMatrix.h:265
virtual ParallelAddMode supportedParallelAddMode() const
Returns the supported mode for calling add.
Definition gmArmadilloSolverMatrix.h:259
virtual bool supportsBatchInsert() const
Does this matrix supports batch inserts? See comments on the class documentation.
Definition gmArmadilloSolverMatrix.h:256
GmSparseMatrixOptions _opt
The set of sparse matrix options, reused from GmSparseMatrix.
Definition gmArmadilloSolverMatrix.h:296
bool _batch
Are we in batch mode?
Definition gmArmadilloSolverMatrix.h:297
GmAppendBuffer< arma::uword > * _positions
The positions array ordered as (row, column) pairs while batch inserting values.
Definition gmArmadilloSolverMatrix.h:299
virtual int layoutSize() const
Returns the size of the sparse matrix layout.
Definition gmArmadilloSolverMatrix.h:268
Base interface class for Solver Matrix objects.
Definition gmSolverMatrix.h:100
virtual int nlin() const =0
Returns the number of lines in the matrix. IMPORTANT: This function implementation MUST be thread saf...
virtual bool symmetric() const =0
Returns true if the matrix was marked as symmetric by setSymmetric() (it does not check for matrix sy...
virtual int ncol() const =0
Returns the number of columns in the matrix. IMPORTANT: This function implementation MUST be thread s...
virtual double at(int lin, int col) const =0
Returns the value in the position Mat[lin][col].
ParallelAddMode
Supported modes for calling add from multiple threads in parallel.
Definition gmSolverMatrix.h:110
An interface for building the layout structure of a sparse matrix.
Definition gmSparseMatrixLayoutBuilder.h:40
Set of configuration options for Sparse matrices.
Definition gmSparseMatrixOptions.h:55
static bool inMainThread()
Is the current thread the main thread? Equivalent to comparing the currentId() with 0.
Definition gmThreadManager.h:174
GmArmadilloSolverMatrixBase< arma::mat > GmArmadilloSolverMatrix
The standard 'Full' matrix based on Armadillo.
Definition gmArmadilloSolverMatrix.h:244
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
Declaration of the GmSolverMatrix interface classes.
Declaration of the GmSparseMatrix template class.
@ GM_ARMADILLO_TRIPLET_LIST
Definition gmSparseMatrixOptions.h:48
Declaration of the GmThreadManager class.
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition gmVector.h:34
T loadAcquire() const const
void storeRelease(T newValue)