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;
260 virtual void add(
int lin,
int col,
double val);
279 bool doEnd(
bool ordered);
281 virtual void addFromThread(
int tid,
int lin,
int col,
double val);
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 double at(int lin, int col) const
Returns the value in the position Mat[lin][col].
Definition: gmArmadilloSolverMatrix.h:96
virtual ParallelAddMode supportedParallelAddMode() const
Returns the supported mode for calling add.
Definition: gmArmadilloSolverMatrix.h:249
T & armadilloMatrix()
Returns the internal Armadillo matrix.
Definition: gmArmadilloSolverMatrix.h:220
virtual int nlin() const =0
Returns the number of lines in the matrix. IMPORTANT: This function implementation MUST be thread saf...
Base interface class for Solver Matrix objects.
Definition: gmSolverMatrix.h:97
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 int ncol() const =0
Returns the number of columns in the matrix. IMPORTANT: This function implementation MUST be thread s...
An interface for building the layout structure of a sparse matrix.
Definition: gmSparseMatrixLayoutBuilder.h:39
QAtomicInt _sym
Flag marking the matrix as symmetric or not.
Definition: gmArmadilloSolverMatrix.h:230
virtual bool emptyLayout() const
If the matrix supports sparse layouts and the layout is currently empty, returns true....
Definition: gmArmadilloSolverMatrix.h:78
virtual bool supportsBatchInsert() const
Does this matrix supports batch inserts? See comments on the class documentation.
Definition: gmArmadilloSolverMatrix.h:246
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 void set(GmSolverMatrix *A, GmSolverMatrix *B, double c, bool sameStructure)
Sets the values of the whole matrix to the result of the expresion A + c * B, where A and B are matri...
Definition: gmArmadilloSolverMatrix.h:108
virtual ParallelAddMode supportedParallelAddMode() const
Returns the supported mode for calling add.
Definition: gmArmadilloSolverMatrix.h:66
bool _batch
Are we in batch mode?
Definition: gmArmadilloSolverMatrix.h:285
Set of configuration options for Sparse matrices.
Definition: gmSparseMatrixOptions.h:54
GmArmadilloSolverMatrixBase(int nlin, int ncol, GmSparseMatrixOptions options=GmSparseMatrixOptions(GM_ARMADILLO_TRIPLET_LIST))
Constructor. Receives as parameters the matrix size.
Definition: gmArmadilloSolverMatrix.h:43
A virtual class representing a buffer of T objects that can be appended in a thread-safe way,...
Definition: gmArmadilloSolverMatrix.h:36
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:270
Declaration of the GmThreadManager class.
virtual void setSymmetric(bool sym)
Marks the matrix as symmetric or not.
Definition: gmArmadilloSolverMatrix.h:84
ParallelAddMode
Supported modes for calling add from multiple threads in parallel.
Definition: gmSolverMatrix.h:107
An implementation of the GmSolverMatrix interface using as base the Armadillo library.
Definition: gmArmadilloSolverMatrix.h:39
virtual int layoutSize() const
Returns the size of the sparse matrix layout.
Definition: gmArmadilloSolverMatrix.h:93
GmArmadilloSolverMatrixBase< arma::mat > GmArmadilloSolverMatrix
The standard 'Full' matrix based on Armadillo.
Definition: gmArmadilloSolverMatrix.h:234
GmSparseMatrixOptions _opt
The set of sparse matrix options, reused from GmSparseMatrix.
Definition: gmArmadilloSolverMatrix.h:284
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 clearLineAndColumnSet(const QList< int > &indexList, bool setDiagonal, bool keepSparseLayout)
Clears a set of lines and columns from the matrix, filling them with zeroes, optionally puting a 1....
Definition: gmArmadilloSolverMatrix.h:140
virtual double at(int lin, int col) const =0
Returns the value in the position Mat[lin][col].
The standard 'Sparse' matrix based on Armadillo.
Definition: gmArmadilloSolverMatrix.h:237
virtual bool supportsSparseLayouts() const
Does this matrix supports sparse layouts? See comments on the class documentation.
Definition: gmArmadilloSolverMatrix.h:60
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 ~GmArmadilloSolverMatrixBase()
Destructor.
Definition: gmArmadilloSolverMatrix.h:54
T loadAcquire() const const
T _mat
The Armadillo matrix.
Definition: gmArmadilloSolverMatrix.h:229
virtual bool symmetric() const =0
Returns true if the matrix was marked as symmetric by setSymmetric() (it does not check for matrix sy...
virtual bool supportsRandomSet() const
Does this matrix supports setting a value on a random position outside the matrix initialization proc...
Definition: gmArmadilloSolverMatrix.h:63
void storeRelease(T newValue)
virtual bool endBatchInsert(bool discardData=false)
Ends a batch insert process. Important: see comments on the class documentation.
Definition: gmArmadilloSolverMatrix.h:72
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 size_t usedMemory() const
Returns an estimative of the memory used by the matrix in bytes.
Definition: gmArmadilloSolverMatrix.h:223
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
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 int ncol() const
Returns the number of columns in the matrix. IMPORTANT: This function implementation MUST be thread s...
Definition: gmArmadilloSolverMatrix.h:90
Declaration of the GmSolverMatrix interface classes.
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
static bool inMainThread()
Is the current thread the main thread? Equivalent to comparing the currentId() with 0.
Definition: gmThreadManager.h:169
Declaration of the GmSparseMatrix template class.
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 supportsBatchInsert() const
Does this matrix supports batch inserts? See comments on the class documentation.
Definition: gmArmadilloSolverMatrix.h:57
GmAppendBuffer< arma::uword > * _positions
The positions array ordered as (row, column) pairs while batch inserting values.
Definition: gmArmadilloSolverMatrix.h:287
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 int layoutSize() const
Returns the size of the sparse matrix layout.
Definition: gmArmadilloSolverMatrix.h:258
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition: gmVector.h:34
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
GmAppendBuffer< double > * _values
The values array while batch inserting values (size = _positions size / 2)
Definition: gmArmadilloSolverMatrix.h:288
virtual bool inLayout(int lin, int col) const
Returns true if the given position belongs to the matrix sparse layout.
Definition: gmArmadilloSolverMatrix.h:99
Definition: gmSparseMatrixOptions.h:48
virtual bool supportsRandomSet() const
Does this matrix supports setting a value on a random position outside the matrix initialization proc...
Definition: gmArmadilloSolverMatrix.h:255
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