GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmSolverMatrix.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_SOLVER_MATRIX_H_
25#define _GEMA_SOLVER_MATRIX_H_
26
27#include "gmLog.h"
28#include "gmVector.h"
29#include "gmDoubleCmp.h"
30
31#include <QString>
32
35
100{
101public:
102
110 {
111 NO_SUPPORT, // add() can not be called in parallel from multiple threads
112 THREAD_SAFE_SUPPORT, // add() can be freely called from multiple threads. The function implements its own serialization strategy.
113 REENTRANT_SUPPORT, // add() can be called in parallel from multiple threads only if each call addresses a different matrix entry.
114 };
115
117 virtual ~GmSolverMatrix() {}
118
120 virtual bool supportsBatchInsert() const = 0;
121
123 virtual bool supportsSparseLayouts() const = 0;
124
128 virtual bool supportsRandomSet() const = 0;
129
132
143 virtual bool beginBatchInsert(size_t expectedEntries = 0) = 0;
144
150 virtual bool endBatchInsert(bool discardData = false) = 0;
151
157
161 virtual bool emptyLayout() const = 0;
162
168 virtual bool symmetric() const = 0;
169
183 virtual void setSymmetric(bool sym) = 0;
184
192 virtual bool isSymmetric(double relTol = GM_DOUBLECMP_RELTOL, double absTol = GM_DOUBLECMP_ABSTOL) const;
193
195 virtual int nlin() const = 0;
196
198 virtual int ncol() const = 0;
199
207 virtual int layoutSize() const = 0;
208
210 virtual double at(int lin, int col) const = 0;
211
223 double operator()(int lin, int col) const { return at(lin, col); }
224
232 virtual bool inLayout(int lin, int col) const = 0;
233
245 virtual void set(int lin, int col, double value) = 0;
246
257 virtual void add(int lin, int col, double value) = 0;
258
275 virtual void set(GmSolverMatrix* A, GmSolverMatrix* B, double c, bool sameStructure) = 0;
276
282 virtual void clear(bool keepSparseLayout) = 0;
283
312 virtual void clearLineAndColumnSet(const QVector<int>& indexList, bool setDiagonal, bool keepSparseLayout) = 0;
313
317 virtual void ensureDiagonal() = 0;
318
325 virtual void matAdd(const GmVector& a, const GmVector& b, double zeroTol = 0.0) = 0;
326
332 virtual void mul(const GmVector& a, GmVector& b) const = 0;
333
339 virtual void mulAdd(const GmVector& a, GmVector& b) const = 0;
340
346 virtual void mulSub(const GmVector& a, GmVector& b) const = 0;
347
366 virtual void columnMulAdd(int col, GmVector& f, double v, const bool* skipRows = NULL) const = 0;
367
377 virtual size_t usedMemory() const = 0;
378
380 virtual bool hasNanInf() const = 0;
381
382 void print(const GmLogCategory& logger, GmLogLevel level, int fieldWidth = 0,
383 char format = 'g', int precision = -1) const;
384
394 virtual bool saveMatrixCoordinatesToFile(FILE* f) const = 0;
395};
396
397#endif
Class representing a category with multiple logging levels.
Definition gmLog.h:58
Base interface class for Solver Matrix objects.
Definition gmSolverMatrix.h:100
virtual void clear(bool keepSparseLayout)=0
Clears the matrix, filling it with zeros. The keepSparseLayout flag is a hint that the matrix layout ...
virtual void add(int lin, int col, double value)=0
Adds the given value to the value in the position Mat[lin][col].
virtual ~GmSolverMatrix()
Virtual destructor.
Definition gmSolverMatrix.h:117
virtual void mul(const GmVector &a, GmVector &b) const =0
Multiplies the matrix ('X') by a vector 'a' storing the result in 'b' (b = X * a).
virtual void columnMulAdd(int col, GmVector &f, double v, const bool *skipRows=NULL) const =0
Updates the given vector adding to it a matrix column multiplied by a scalar value.
double operator()(int lin, int col) const
Returns the value in the position Mat[lin][col].
Definition gmSolverMatrix.h:223
virtual int nlin() const =0
Returns the number of lines in the matrix. IMPORTANT: This function implementation MUST be thread saf...
virtual void clearLineAndColumnSet(const QVector< int > &indexList, bool setDiagonal, bool keepSparseLayout)=0
Clears a set of lines and columns from the matrix, filling them with zeroes, optionally putting a 1....
virtual void mulAdd(const GmVector &a, GmVector &b) const =0
Multiplies the matrix ('X') by a vector 'a' adding the result to 'b' (b = b + X * a).
virtual void ensureDiagonal()=0
Updates any zero diagonal value to 1.0. If diagonal values do not belong to the layout,...
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 layoutSize() const =0
Returns the size of the sparse matrix layout.
virtual int ncol() const =0
Returns the number of columns in the matrix. IMPORTANT: This function implementation MUST be thread s...
virtual ParallelAddMode supportedParallelAddMode() const =0
Returns the supported mode for calling add.
virtual bool supportsBatchInsert() const =0
Does this matrix supports batch inserts? See comments on the class documentation.
virtual bool hasNanInf() const =0
Returns true if the matrix contains nan or inf values.
virtual bool supportsRandomSet() const =0
Does this matrix supports setting a value on a random position outside the matrix initialization proc...
virtual void set(int lin, int col, double value)=0
Sets the value in the position Mat[lin][col] to the specified value.
virtual void matAdd(const GmVector &a, const GmVector &b, double zeroTol=0.0)=0
Adds to the current matrix ('X') the (dense) matrix resulting from multiplying the column vector 'a' ...
virtual bool endBatchInsert(bool discardData=false)=0
Ends a batch insert process. Important: see comments on the class documentation.
virtual size_t usedMemory() const =0
Returns an estimative of the memory used by the matrix in bytes.
virtual GmSparseMatrixLayoutBuilder * layoutBuilder() const =0
If the matrix supports sparse layouts, returns a builder object that can be used to initialize the ma...
virtual double at(int lin, int col) const =0
Returns the value in the position Mat[lin][col].
virtual bool supportsSparseLayouts() const =0
Does this matrix supports sparse layouts? See comments on the class documentation.
ParallelAddMode
Supported modes for calling add from multiple threads in parallel.
Definition gmSolverMatrix.h:110
virtual void set(GmSolverMatrix *A, GmSolverMatrix *B, double c, bool sameStructure)=0
Sets the values of the whole matrix to the result of the expression A + c * B, where A and B are matr...
virtual bool saveMatrixCoordinatesToFile(FILE *f) const =0
Helper function to GmNumSolver saving capabilities, responsible for saving the matrix contents to the...
virtual bool inLayout(int lin, int col) const =0
Returns true if the given position belongs to the matrix sparse layout.
virtual bool emptyLayout() const =0
If the matrix supports sparse layouts and the layout is currently empty, returns true....
virtual void mulSub(const GmVector &a, GmVector &b) const =0
Multiplies the matrix ('X') by a vector 'a' subtracting the result from 'b' (b = b - X * a).
virtual void setSymmetric(bool sym)=0
Marks the matrix as symmetric or not.
virtual bool beginBatchInsert(size_t expectedEntries=0)=0
Begins a batch insert process. Important: see comments on the class documentation.
An interface for building the layout structure of a sparse matrix.
Definition gmSparseMatrixLayoutBuilder.h:40
#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
Functions for comparing double values.
#define GM_DOUBLECMP_ABSTOL
Tolerância absoluta entre valores para comparar valores próximos de zero.
Definition gmDoubleCmp.h:64
#define GM_DOUBLECMP_RELTOL
Tolerância relativa entre valores = 0.000001%.
Definition gmDoubleCmp.h:61
Declaration of support functions and macros for information logging.
GmLogLevel
Available log levels list.
Definition gmLog.h:36
Declaration of the GmVector class.
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition gmVector.h:34
A base structure for storing layout data for sparse matrices (fill structure or non zero positions)....
Definition gmSparseMatrixLayout.h:66