24 #ifndef _GEMA_SPARSE_MATRIX_H_ 25 #define _GEMA_SPARSE_MATRIX_H_ 43 virtual void matrixLayoutReady() = 0;
49 template<
class IndexType, GmSparseMatrixLayoutTypes T>
93 virtual int nlin()
const {
return _n; }
96 virtual int ncol()
const {
return _n; }
102 virtual double at(
int lin,
int col)
const 106 assert(lin >= 0 && lin <
_n);
107 assert(col >= 0 && col <
_n);
113 int index =
_layout->index(lin, col);
114 assert(index >= -1 && index < _layout->_nnz);
116 return index >= 0 ?
_values[index] : 0.0;
124 assert(lin >= 0 && lin <
_n);
125 assert(col >= 0 && col <
_n);
130 return (
_layout->index(lin, col) >= 0);
134 virtual void set(
int lin,
int col,
double value)
138 assert(lin >= 0 && lin <
_n);
139 assert(col >= 0 && col <
_n);
142 int index =
_layout->index(lin, col);
143 assert(index >= 0 && index < _layout->_nnz);
149 virtual void add(
int lin,
int col,
double value)
152 assert(lin >= 0 && lin <
_n);
153 assert(col >= 0 && col <
_n);
162 int index =
_layout->index(lin, col);
163 assert(index >= 0 && index < _layout->_nnz);
170 virtual void clear(
bool keepSparseLayout);
189 virtual void checkLayoutData()
const;
198 void addBatch(
int lin,
int col,
double value);
GmSparseMatrixLayoutMode mode() const
Returns the mode for building the sparse matrix.
Definition: gmSparseMatrixOptions.h:64
A class for wrapping up a sparse matrix either using CSR or CSC format. Can also differ on the type u...
Definition: gmSparseMatrix.h:50
virtual int ncol() const
Returns the number of columns in the matrix. IMPORTANT: This function implementation MUST be thread s...
Definition: gmSparseMatrix.h:96
int _n
The number of lines and columns in the matrix.
Definition: gmSparseMatrix.h:206
virtual void setSymmetric(bool sym)
Marks the matrix as symmetric or not.
Definition: gmSparseMatrix.h:90
Base interface class for Solver Matrix objects.
Definition: gmSolverMatrix.h:97
double * _values
The vector with matrix values.
Definition: gmSparseMatrix.h:208
Batch mode with a (per thread) triplet list.
Definition: gmSparseMatrixOptions.h:37
GmSparseMatrixOptions _opt
The matrix options, including the mode used to build the matrix.
Definition: gmSparseMatrix.h:204
QAtomicInt _sym
Flag marking the matrix as symmetric or not.
Definition: gmSparseMatrix.h:207
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: gmSparseMatrix.cpp:825
GmSparseMatrixLayoutBuilder * _layoutBuilder
The layout builder if _masterLayout is not NULL.
Definition: gmSparseMatrix.h:213
virtual GmSparseMatrix< IndexType, T > * detachAndClear()
Creates a new matrix that inherits the layout and matrix data from this matrix and clears this matrix...
Definition: gmSparseMatrix.cpp:1064
GmSparseMatrix(int n, const GmSparseMatrix< IndexType, T > *sharedLayout, GmSparseMatrixOptions options, bool arma)
Constructor for a sparse square matrix stored either in CSR or CSC format. If sharedLayout is differe...
Definition: gmSparseMatrix.cpp:55
virtual void set(int lin, int col, double value)
Sets the value in the position Mat[lin][col] to the specified value.
Definition: gmSparseMatrix.h:134
An interface for building the layout structure of a sparse matrix.
Definition: gmSparseMatrixLayoutBuilder.h:39
bool _batch
Flag to signal that the matrix is inside a batch op (for _opt.mode() == TRIPLET_LIST/STRIPLET_LIST)
Definition: gmSparseMatrix.h:205
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: gmSparseMatrix.cpp:1021
virtual int layoutSize() const
Returns the size of the sparse matrix layout.
Definition: gmSparseMatrix.h:99
virtual bool supportsSparseLayouts() const
Does this matrix supports sparse layouts? See comments on the class documentation.
Definition: gmSparseMatrix.h:62
virtual GmSparseMatrixLayoutBuilder * layoutBuilder() const
If the matrix supports sparse layouts, returns a builder object that can be used to initialize the ma...
Definition: gmSparseMatrix.h:77
Set of configuration options for Sparse matrices.
Definition: gmSparseMatrixOptions.h:54
GmCSxSparseMatrixLayout< IndexType, T > * _masterLayout
The master layout data (equal to _layout) if this matrix is the layout owner, NULL for matrices shari...
Definition: gmSparseMatrix.h:211
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: gmSparseMatrix.cpp:910
Auxiliar class used to store the complete set of simulation data.
Definition: gmSimulationData.h:51
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: gmSparseMatrix.cpp:573
GmSparseMatrixLayoutMode
Supported modes for building the sparse matrix.
Definition: gmSparseMatrixOptions.h:35
Declaration of the GmThreadManager class.
virtual bool supportsRandomSet() const
Does this matrix supports setting a value on a random position outside the matrix initialization proc...
Definition: gmSparseMatrix.h:65
A base class derived from QObject. Needed since GmSparseMatrix is a template and so can't inherit dir...
Definition: gmSparseMatrix.h:38
ParallelAddMode
Supported modes for calling add from multiple threads in parallel.
Definition: gmSolverMatrix.h:107
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: gmSparseMatrix.cpp:985
virtual ~GmSparseMatrix()
Destructor.
Definition: gmSparseMatrix.cpp:107
virtual bool inLayout(int lin, int col) const
Returns true if the given position belongs to the matrix sparse layout.
Definition: gmSparseMatrix.h:120
virtual void ensureDiagonal()
Updates any zero diagonal value to 1.0. If diagonal values do not belong to the layout,...
Definition: gmSparseMatrix.cpp:742
Declaration of the GmSparseMatrixTripletData and GmSparseMatrixTripletBuffer template classes.
virtual bool endBatchInsert(bool discardData=false)
Ends a batch insert process. Important: see comments on the class documentation.
Definition: gmSparseMatrix.cpp:170
virtual size_t usedMemory() const
Returns an estimative of the memory used by the matrix in bytes.
Definition: gmSparseMatrix.cpp:1093
virtual bool beginBatchInsert(size_t expectedEntries=0)
Begins a batch insert process. Important: see comments on the class documentation.
Definition: gmSparseMatrix.cpp:139
T loadAcquire() const const
virtual void clear(bool keepSparseLayout)
Clears the matrix, filling it with zeros. The keepSparseLayout flag is a hint that the matrix layout ...
Definition: gmSparseMatrix.cpp:384
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: gmSparseMatrix.cpp:948
void storeRelease(T newValue)
An especialization of GmAppendBufffer for triplet data with an extra method for returning the buffer ...
Definition: gmSparseMatrixTripletData.h:120
A structure for storing a matrix layout in either CSR or CSC format. The template type defines the ty...
Definition: gmSparseMatrixLayout.h:123
#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
void addBatch(int lin, int col, double value)
Worker function for adding an entry to the matrix while inside a beginBatchInsert() / endBatchInsert(...
Definition: gmSparseMatrix.cpp:329
const GmCSxSparseMatrixLayout< IndexType, T > * _layout
The read-only matrix layout data. Can be shared from other matrices.
Definition: gmSparseMatrix.h:210
GmSparseMatrixLayoutBuilder * createLayoutBuilder(GmSparseMatrixLayoutMode mode, GmCSxSparseMatrixLayout< IndexType, T > *layout)
Creates a new layout builder from the given layout mode and layout.
Definition: gmSparseMatrix.cpp:121
void addToPtrIndexFromThread(int tid, int ptr, int index, double value)
Worker function for adding an entry to the matrix while inside a beginBatchInsert() / endBatchInsert(...
Definition: gmSparseMatrix.cpp:348
virtual bool symmetric() const
Returns true if the matrix was marked as symmetric by setSymmetric() (it does not check for matrix sy...
Definition: gmSparseMatrix.h:87
virtual void add(int lin, int col, double value)
Adds the given value to the value in the position Mat[lin][col].
Definition: gmSparseMatrix.h:149
Declaration of the GmSolverMatrix interface classes.
virtual double at(int lin, int col) const
Returns the value in the position Mat[lin][col].
Definition: gmSparseMatrix.h:102
static bool inMainThread()
Is the current thread the main thread? Equivalent to comparing the currentId() with 0.
Definition: gmThreadManager.h:169
virtual bool emptyLayout() const
If the matrix supports sparse layouts and the layout is currently empty, returns true....
Definition: gmSparseMatrix.h:80
virtual ParallelAddMode supportedParallelAddMode() const
Returns the supported mode for calling add.
Definition: gmSparseMatrix.h:68
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition: gmVector.h:34
GmSparseMatrixTripletBuffer< T > * _batchData
Intermediate structure while building the matrix with a triplet list.
Definition: gmSparseMatrix.h:215
virtual bool supportsBatchInsert() const
Does this matrix supports batch inserts? See comments on the class documentation.
Definition: gmSparseMatrix.h:59
virtual void matrixLayoutReady()
Allocates space for matrix values when notified that the layout is ready.
Definition: gmSparseMatrix.cpp:361
virtual int nlin() const
Returns the number of lines in the matrix. IMPORTANT: This function implementation MUST be thread saf...
Definition: gmSparseMatrix.h:93
Declaration of the GmSparseMatrixOptions class.