25 #ifndef _GEMA_SPARSE_MATRIX_LAYOUT_H_ 26 #define _GEMA_SPARSE_MATRIX_LAYOUT_H_ 34 #define ENABLE_MATRIX_LAYOUT_INDEX_CACHE 1 37 #ifdef ENABLE_MATRIX_LAYOUT_INDEX_CACHE 77 virtual bool empty()
const = 0;
80 virtual void clear() = 0;
83 virtual int index(
int row,
int col)
const = 0;
90 virtual int dindex(
int n)
const = 0;
93 virtual void printStatistics(
const GmLogCategory& logger)
const = 0;
102 virtual void checkLayoutData()
const = 0;
110 void layoutCompleted();
122 template <
class IndexType, GmSparseMatrixLayoutTypes T>
133 _ptr = _index = NULL;
137 #ifdef ENABLE_MATRIX_LAYOUT_INDEX_CACHE 150 virtual bool empty()
const {
return _n == 0; }
157 _ptr = _index = NULL;
160 #ifdef ENABLE_MATRIX_LAYOUT_INDEX_CACHE 168 virtual int index(
int row,
int col)
const;
171 virtual int dindex(
int n)
const {
return indexWorker(_ptr[n], _ptr[n+1], n); }
176 virtual void checkLayoutData()
const;
185 #ifdef ENABLE_MATRIX_LAYOUT_INDEX_CACHE 190 int indexWorker(
int start,
int end,
int ind)
const 208 return (_index[i] == ind) ? i : -1;
215 int i = (li > start && li < end && _index[li] <= ind) ? li : start;
221 return (_index[i] == ind) ? i : -1;
230 int i = (li > start && li < end && _index[li] <= ind) ? li : start;
233 if(_index[i + 0] >= ind) { li = i + 0;
return (_index[i + 0] == ind) ? i + 0 : -1; }
234 if(_index[i + 1] >= ind) { li = i + 1;
return (_index[i + 1] == ind) ? i + 1 : -1; }
235 if(_index[i + 2] >= ind) { li = i + 2;
return (_index[i + 2] == ind) ? i + 2 : -1; }
236 if(_index[i + 3] >= ind) { li = i + 3;
return (_index[i + 3] == ind) ? i + 3 : -1; }
244 return (_index[i] == ind) ? i : -1;
252 IndexType* pos = std::lower_bound(_index+start, _index+end, ind);
253 return (pos < _index+end && *pos == ind) ? pos - _index : -1;
260 if(_index[i + 0] >= ind)
return (_index[i + 0] == ind) ? i + 0 : -1;
261 if(_index[i + 1] >= ind)
return (_index[i + 1] == ind) ? i + 1 : -1;
262 if(_index[i + 2] >= ind)
return (_index[i + 2] == ind) ? i + 2 : -1;
263 if(_index[i + 3] >= ind)
return (_index[i + 3] == ind) ? i + 3 : -1;
269 return (_index[i] == ind) ? i : -1;
276 for(
int i = start; i<end; i++)
277 cnt += (_index[i] < ind);
278 return (cnt < end && _index[cnt] == ind) ? cnt : -1;
GmCSxSparseMatrixLayout< arma::uword, GM_CSC_SPARSE_FORMAT > GmCSCArmadilloSparseMatrixLayout
CSC layout with 64 bits integer index.
Definition: gmSparseMatrixLayout.h:295
GmCSxSparseMatrixLayout(bool arma)
Constructor.
Definition: gmSparseMatrixLayout.h:131
GmSparseMatrixLayoutTypes _type
The stored sparse matrix type.
Definition: gmSparseMatrixLayout.h:98
virtual int dindex(int n) const
Returns the index for the value in the diagonal of the given matrix row (column). Returns -1 if the v...
Definition: gmSparseMatrixLayout.h:171
Declaration of the GmTLS class.
virtual ~GmSparseMatrixLayout()
Virtual destructor.
Definition: gmSparseMatrixLayout.h:74
virtual void clear()
Clears the layout releasing memory and making the matrix a zero matrix.
Definition: gmSparseMatrixLayout.h:153
Declaration of usefull configuration definitions for the Core library.
Data is stored in "Compressed Sparse Column" format.
Definition: gmSparseMatrixLayout.h:47
A class that works together with GmThreadManager to provide thread local storage.
Definition: gmThreadLocalStorage.h:131
GmCSxSparseMatrixLayout< int, GM_CSR_SPARSE_FORMAT > GmCSRSparseMatrixLayout
CSR layout with 32 bits integer index.
Definition: gmSparseMatrixLayout.h:286
int _nnz
The number of elements stored in the matrix (in some cases zero values can be stored,...
Definition: gmSparseMatrixLayout.h:182
Data is stored in "Compressed Sparse Row" (or old Yale) format.
Definition: gmSparseMatrixLayout.h:48
GmSparseMatrixLayoutTypes
Supported sparse matrix types by GmSparseMatrixLayout sub-classes.
Definition: gmSparseMatrixLayout.h:45
GmSparseMatrixLayout(GmSparseMatrixLayoutTypes type)
Constructor.
Definition: gmSparseMatrixLayout.h:71
T & localData(int tid)
Returns the given thread local data as a modifiable reference.
Definition: gmThreadLocalStorage.h:163
virtual int index(int row, int col) const =0
Returns the index for the value in the given matrix row, col. Returns -1 if the value is not part of ...
int _n
The number of rows(CSR)/columns(CSC) in the matrix.
Definition: gmSparseMatrixLayout.h:181
virtual bool empty() const
Returns true if the layout is empty.
Definition: gmSparseMatrixLayout.h:150
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
virtual void printStatistics(const GmLogCategory &logger) const =0
Print layout statistics to the given logger.
Class representing a category with multiple logging levels.
Definition: gmLog.h:58
IndexType * _ptr
Vector storing the index of the first non zero element of each matrix row(CSR)/column(CSC)....
Definition: gmSparseMatrixLayout.h:179
A base structure for storing layout data for sparse marices (fill structure or non zero positions)....
Definition: gmSparseMatrixLayout.h:65
int _arma
Stores 1 if the layout should store 1 extra space per vector to be compatible with Armadillo requirem...
Definition: gmSparseMatrixLayout.h:183
virtual ~GmCSxSparseMatrixLayout()
Destuctor.
Definition: gmSparseMatrixLayout.h:143
IndexType * _index
Vector storing the column(CSR)/row(CSC) index for each non zero value. Size = _nnz.
Definition: gmSparseMatrixLayout.h:180
bool _shared
Is this layout shared? Mutable to enable matrices sharing a layout to specify so.
Definition: gmSparseMatrixLayout.h:99
void emitLayoutCompleted()
Emits the layoutCompleted signal.
Definition: gmSparseMatrixLayout.h:96