GemaCoreLib
The GeMA Core library
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 
33 
98 {
99 public:
100 
108  {
109  NO_SUPPORT, // add() can not be called in parallel from multiple threads
110  THREAD_SAFE_SUPPORT, // add() can be freely called from multiple threads. The function implements its own serialization strategy.
111  REENTRANT_SUPPORT, // add() can be called in parallel from multiple threads only if each call adresses a different matrix entry.
112  };
113 
115  virtual ~GmSolverMatrix() {}
116 
118  virtual bool supportsBatchInsert() const = 0;
119 
121  virtual bool supportsSparseLayouts() const = 0;
122 
126  virtual bool supportsRandomSet() const = 0;
127 
129  virtual ParallelAddMode supportedParallelAddMode() const = 0;
130 
141  virtual bool beginBatchInsert(size_t expectedEntries = 0) = 0;
142 
148  virtual bool endBatchInsert(bool discardData = false) = 0;
149 
154  virtual GmSparseMatrixLayoutBuilder* layoutBuilder() const = 0;
155 
159  virtual bool emptyLayout() const = 0;
160 
166  virtual bool symmetric() const = 0;
167 
181  virtual void setSymmetric(bool sym) = 0;
182 
184  virtual int nlin() const = 0;
185 
187  virtual int ncol() const = 0;
188 
196  virtual int layoutSize() const = 0;
197 
199  virtual double at(int lin, int col) const = 0;
200 
212  double operator()(int lin, int col) const { return at(lin, col); }
213 
221  virtual bool inLayout(int lin, int col) const = 0;
222 
234  virtual void set(int lin, int col, double value) = 0;
235 
246  virtual void add(int lin, int col, double value) = 0;
247 
264  virtual void set(GmSolverMatrix* A, GmSolverMatrix* B, double c, bool sameStructure) = 0;
265 
271  virtual void clear(bool keepSparseLayout) = 0;
272 
301  virtual void clearLineAndColumnSet(const QList<int>& indexList, bool setDiagonal, bool keepSparseLayout) = 0;
302 
306  virtual void ensureDiagonal() = 0;
307 
314  virtual void matAdd(const GmVector& a, const GmVector& b, double zeroTol = 0.0) = 0;
315 
321  virtual void mul(const GmVector& a, GmVector& b) const = 0;
322 
328  virtual void mulAdd(const GmVector& a, GmVector& b) const = 0;
329 
335  virtual void mulSub(const GmVector& a, GmVector& b) const = 0;
336 
355  virtual void columnMulAdd(int col, GmVector& f, double v, const bool* skipRows = NULL) const = 0;
356 
366  virtual size_t usedMemory() const = 0;
367 
368  bool isSymmetric(double relTol = GM_DOUBLECMP_RELTOL, double absTol = GM_DOUBLECMP_ABSTOL) const;
369 
370  void print(const GmLogCategory& logger, GmLogLevel level, int fieldWidth = 0, char format = 'g', int precision = -1);
371 };
372 #endif
#define GM_DOUBLECMP_ABSTOL
Tolerância absoluta entre valores para comparar valores próximos de zero.
Definition: gmDoubleCmp.h:64
virtual ~GmSolverMatrix()
Virtual destructor.
Definition: gmSolverMatrix.h:115
Base interface class for Solver Matrix objects.
Definition: gmSolverMatrix.h:97
double operator()(int lin, int col) const
Returns the value in the position Mat[lin][col].
Definition: gmSolverMatrix.h:212
An interface for building the layout structure of a sparse matrix.
Definition: gmSparseMatrixLayoutBuilder.h:39
ParallelAddMode
Supported modes for calling add from multiple threads in parallel.
Definition: gmSolverMatrix.h:107
Functions for comparing double values.
void print(const GmMatrix &m, const GmLogCategory &logger, GmLogLevel level, int fieldWidth, char format, int precision)
Prints the matrix using the specified logger, level and precision fields.
Definition: gmMatrixUtils.cpp:34
Declaration of the GmVector class.
#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
GmLogLevel
Available log levels list.
Definition: gmLog.h:36
Class representing a category with multiple logging levels.
Definition: gmLog.h:58
#define GM_DOUBLECMP_RELTOL
Tolerância relativa entre valores = 0.000001%.
Definition: gmDoubleCmp.h:61
A base structure for storing layout data for sparse marices (fill structure or non zero positions)....
Definition: gmSparseMatrixLayout.h:65
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition: gmVector.h:34
Declaration of support functions and macros for information logging.