GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmMatrixSet.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_MATRIX_SET_H_
25#define _GEMA_MATRIX_SET_H_
26
27#include "gmMatrix.h"
28#include "gmThreadLocalBuffer.h"
29
30#include <assert.h>
31
32#include <QStringList>
33
34/* \brief This class holds a fixed size set of square matrices, whose sizes
35 can vary inside a maximum limit.
36*/
38{
39public:
40 GmMatrixSet(int maxMatrixTypes, const QStringList& typeNames);
42
43 bool init(int maxNodes, int numMatrices, ...);
44 bool adjustSizes(int maxNodes);
45 void clear();
46
47 void prepareSet(int nnodes);
48
50 bool containsType(int type) const { return (index(type) >= 0 && _typeEnabled[type]); }
51
55 void setTypeEnabled(int type, bool enabled)
56 {
57 assert(type >= 0 && type < _nTypes);
58 if(enabled == _typeEnabled[type])
59 return;
60 _typeEnabled[type] = enabled;
61 _nEnabled += (enabled ? 1 : -1);
62 }
63
65 int numEnabledTypes() const { return _nEnabled; }
66
67 GmMatrix& matrix (int type);
68 GmMatrix& useMatrix(int type);
69 GmMatrix& useMatrix(int type, bool fill, bool sym);
70
75 void setSymmetric(int type, bool symmetric)
76 {
77 assert(index(type) >= 0);
78 _symmetric.localBuffer()[index(type)] = symmetric;
79 }
80
85 void setFilled(int type, bool filled) { assert(index(type) >= 0); _filled.localBuffer()[index(type)] = filled; }
86
91 bool symmetric(int type) const { assert(index(type) >= 0); return _symmetric.localBuffer()[index(type)]; }
92
93 bool filledSymmetric() const;
94
99 bool filled(int type) const { assert(index(type) >= 0); return _filled.localBuffer()[index(type)]; }
100
102 int index(int type) const { assert(type >= 0 && type < _nTypes); return _typeIndex[type]; }
103
105 int typeFromIndex(int index) const { assert(index >= 0 && index < _nMatrices); return _indexType[index]; }
106
108 QString typeName(int type) const
109 {
110 assert(type >= 0 && type < _nTypes);
111 return type < _typeNames.size() ? _typeNames.at(type) : "";
112 }
113
115 int numMatrices() const { return _nMatrices; }
116
118 const GmMatrix& matrixFromIndex(int index) const { assert(index >= 0 && index < _nMatrices); return _matrices.localBuffer()[index]; }
119
123 bool symmetricFromIndex(int index) const { assert(index >= 0 && index < _nMatrices); return _symmetric.localBuffer()[index]; }
124
128 bool filledFromIndex(int index) const { assert(index >= 0 && index < _nMatrices); return _filled.localBuffer()[index]; }
129
130protected:
131 bool initTypes(int numMatrices, va_list typeList);
132
139
146};
147
148
149#endif
150
Definition gmMatrixSet.h:38
GmTLBuffer< bool, true > _filled
Vector stating, for each matrix, if it was filled by the user or not.
Definition gmMatrixSet.h:145
int numEnabledTypes() const
Returns the number of enabled types in the matrix set.
Definition gmMatrixSet.h:65
bool filled(int type) const
Returns true if the matrix from the current thread, identified by its type, was marked as filled (def...
Definition gmMatrixSet.h:99
int _maxNodes
The maximum dimension of a matrix (maximum number of element nodes)
Definition gmMatrixSet.h:141
int numMatrices() const
Return the number of matrices stored in this set.
Definition gmMatrixSet.h:115
void setSymmetric(int type, bool symmetric)
Marks a matrix, identified by its type in the set, as symmetric or unsymmetric. IMPORTANT: The suppli...
Definition gmMatrixSet.h:75
const GmMatrix & matrixFromIndex(int index) const
Returns a matrix, tied to the current thread, identified by its index in the set.
Definition gmMatrixSet.h:118
QString typeName(int type) const
Returns a name associated to the given type from the list supplied in the constructor.
Definition gmMatrixSet.h:108
int _nMatrices
The number of matrices stored in this set.
Definition gmMatrixSet.h:140
bool symmetricFromIndex(int index) const
Returns true if the matrix tied to the current thread, and indentified by its index,...
Definition gmMatrixSet.h:123
GmTLBuffer< GmMatrix, true > _matrices
Vector with matrices prepared by prepareSet()
Definition gmMatrixSet.h:143
int * _typeIndex
An index mapping matrix types to its position within the set.
Definition gmMatrixSet.h:134
int typeFromIndex(int index) const
Given a matrix index, returns its type.
Definition gmMatrixSet.h:105
GmTLBuffer< bool, true > _symmetric
Vector stating, for each matrix, if it is symmetric or not.
Definition gmMatrixSet.h:144
void setFilled(int type, bool filled)
Marks a matrix, identified by its type in the set, as filled or unfilled. IMPORTANT: The supplied typ...
Definition gmMatrixSet.h:85
GmTLBuffer< double, true > _matrixMemory
Memory used to hold data for the set matrices.
Definition gmMatrixSet.h:142
bool symmetric(int type) const
Returns true if the matrix from the current thread, identified by its type, was marked symmetric (def...
Definition gmMatrixSet.h:91
bool containsType(int type) const
Returns true if the matrix set contains a matrix of the requested type AND the type is enabled.
Definition gmMatrixSet.h:50
QStringList _typeNames
Optional names for matrix types.
Definition gmMatrixSet.h:138
int * _indexType
Reverse index for finding the type from the matrix index.
Definition gmMatrixSet.h:135
void setTypeEnabled(int type, bool enabled)
Enables or disables a type in the set. Disabled types do NOT return matrices in calls to matrix() or ...
Definition gmMatrixSet.h:55
int _nTypes
The number of existing matrix types.
Definition gmMatrixSet.h:133
bool * _typeEnabled
A vector stating if the type is enabled or not.
Definition gmMatrixSet.h:136
bool filledFromIndex(int index) const
Returns true if the matrix tied to the current thread, indentified by its index, was marked as filled...
Definition gmMatrixSet.h:128
int _nEnabled
The number of enabled matrices in _typeEnabled.
Definition gmMatrixSet.h:137
int index(int type) const
Returns the index inside the set of the supplied type (-1 if the type doesn't belong to the set).
Definition gmMatrixSet.h:102
A class similar to GmTLS that creates a buffer for each possible thread in the GmThreadManager,...
Definition gmThreadLocalBuffer.h:106
#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
Declaration of the GmMatrix class.
arma::mat GmMatrix
The basic type for a GeMA matrix object. Currently based on an Armadillo matrix.
Definition gmMatrix.h:38
Declaration of the GmTLBuffer class.