1 #ifndef SM_PackedBlockSymmetricMatrix_H
2 #define SM_PackedBlockSymmetricMatrix_H
5 #include "SM_PackedBlockMatrix.h"
17 template<
typename T,tUCInt P>
39 std::valarray<T> mSupBlocksValues;
41 std::valarray<T> mDiagonalValues;
103 mem+=mSupBlocksValues.size()*
sizeof(T);
104 mem+=mDiagonalValues.size()*
sizeof(T);
111 inline static CORE_UniquePointer<SelfClass>
New() {
112 return CORE_UniquePointer<SelfClass>(
new SelfClass(),
124 memset(&mSupBlocksValues[0],0,mSupBlocksValues.size()*
sizeof(T));
125 memset(&mDiagonalValues[0],0,mDiagonalValues.size()*
sizeof(T));
131 inline void setSize(
const tIndex& nRowBlocks) {
132 setSize(nRowBlocks,nRowBlocks);
139 virtual void setSize(
const tIndex& nRowBlocks,
const tIndex& nColBlocks)
final {
140 ASSERT_IN(nRowBlocks==nColBlocks);
145 tIndex s=GetSupBlocksValuesNumber(nRowBlocks);
146 if (s!=mSupBlocksValues.size()) {
148 mSupBlocksValues.resize(s);
149 memset(&mSupBlocksValues[0],0,
sizeof(T)*s);
150 }
catch (std::exception& e) {
152 "SM_PackedBlockSymmetricMatrix::setSize("+std::to_string(nRowBlocks)+
")",
153 "not enough size to allocate "+std::to_string(s)+
" elements for sup matrix : memory size needed: "+std::to_string((
sizeof(T)*s)/(1024*1024*1024))+
" Go");
156 if (nRowBlocks!=mDiagonalValues.size()) {
158 mDiagonalValues.resize(nRowBlocks);
159 memset(&mDiagonalValues[0],0,
sizeof(T)*nRowBlocks);
160 }
catch (std::exception& e) {
162 "SM_PackedBlockSymmetricMatrix::setSize("+std::to_string(nRowBlocks)+
")",
163 "not enough size to allocate "+std::to_string(s)+
" elements for diagonla matrix : memory size needed: "+std::to_string((
sizeof(T)*s)/(1024*1024*1024))+
" Go");
174 virtual void setValue(
const tIndex& i,
const tIndex& j,
const T& v)
final{
183 virtual const T&
getValue(
const tIndex& i,
const tIndex& j)
const final {
191 virtual T&
getValue(
const tIndex& i,
const tIndex& j)
final {
200 return mSupBlocksValues;
205 return mDiagonalValues;
211 return mSupBlocksValues;
216 return mDiagonalValues;
233 return (i==j)?mDiagonalValues[i]:mSupBlocksValues[GetSupBlockIndex<P>(i,j)+index];
244 return (i==j)?mDiagonalValues[i]:mSupBlocksValues[GetSupBlockIndex<P>(i,j)+mWIndex];
252 inline static tIndex GetSupBlocksValuesNumber(
const tIndex& n) {
269 return GetSupBlockIndex<SM_PackedBlockMatrix<T,P>::BLOCK_SIZE>(ib,jb);
279 inline static tIndex
GetBlockIndex(
const tIndex& i ,
const tIndex& j) {
296 inline static tIndex GetSupBlockIndex(
const tIndex& ib ,
const tIndex& jb) {
321 std::stringstream ret;
324 ret<<
"sup blocks values:"<<functions_array::toString(mSupBlocksValues)<<
"\n";
325 ret<<
"diagonal values:"<<functions_array::toString(mDiagonalValues)<<
"\n";
331 #include "SM_PackedBlockSymmetricMatrix.hpp"
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:17
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
abstract base class for most classes.
Definition: CORE_Object.h:65
This class described a matrix by packed block of size in a row storage.
Definition: SM_PackedBlockMatrix.h:18
virtual tString toString() const override
return string representaton of the operator
Definition: SM_PackedBlockMatrix.h:236
virtual void setSize(const tInteger &nRowBlocks, const tInteger &nColBlocks)
set the number or rows & columns of the blocks matrix
Definition: SM_PackedBlockMatrix.h:112
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_PackedBlockMatrix.h:94
static tIndex GetPackedIndex(const tIndex &i, const tIndex &j)
return the pack index of size Q in a column storage
Definition: SM_PackedBlockMatrix.h:165
This class described a symmetric matrix by block of size PxP in a packed storage.
Definition: SM_PackedBlockSymmetricMatrix.h:18
static tIndex GetBlockIndex(const tIndex &ib, const tIndex &jb)
get the value of the sub pack block at index
Definition: SM_PackedBlockSymmetricMatrix.h:268
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_PackedBlockSymmetricMatrix.h:101
SM_PackedBlockSymmetricMatrix(void)
create a matrix of size 0
Definition: SM_PackedBlockSymmetricMatrix.h:59
virtual void setSize(const tIndex &nRowBlocks, const tIndex &nColBlocks) final
set the number or rows & columns of the blocks matrix
Definition: SM_PackedBlockSymmetricMatrix.h:139
const T & operator()(tIndex i, tIndex j) const
get values at row i and column j for reading
Definition: SM_PackedBlockSymmetricMatrix.h:228
virtual tString toString() const override
return string representaton of the operator
Definition: SM_PackedBlockSymmetricMatrix.h:320
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_PackedBlockSymmetricMatrix.h:89
std::valarray< T > & getDiagonalValues()
get the diagonal values : Diagonal[i].I_P
Definition: SM_PackedBlockSymmetricMatrix.h:204
virtual void vectorProduct(const T *vX, T *vY) const
vector product
Definition: SM_PackedBlockSymmetricMatrix.hpp:5
T & operator()(tIndex i, tIndex j)
get values at row i and column j for writing
Definition: SM_PackedBlockSymmetricMatrix.h:240
virtual void reset() final
reset the values
Definition: SM_PackedBlockSymmetricMatrix.h:123
virtual ~SM_PackedBlockSymmetricMatrix(void)
destroy
Definition: SM_PackedBlockSymmetricMatrix.h:66
std::valarray< T > & getSupBlocksValues()
get the values of superior blocks of the matrix
Definition: SM_PackedBlockSymmetricMatrix.h:199
virtual void setValue(const tIndex &i, const tIndex &j, const T &v) final
set values at row i and column j
Definition: SM_PackedBlockSymmetricMatrix.h:174
virtual const T & getValue(const tIndex &i, const tIndex &j) const final
get values at row i and column j for reading
Definition: SM_PackedBlockSymmetricMatrix.h:183
virtual T & getValue(const tIndex &i, const tIndex &j) final
get values at row i and column j for writing
Definition: SM_PackedBlockSymmetricMatrix.h:191
void setSize(const tIndex &nRowBlocks)
set the number or rows & columns of the blocks matrix
Definition: SM_PackedBlockSymmetricMatrix.h:131
static CORE_UniquePointer< SelfClass > New()
build a new instance of the operator
Definition: SM_PackedBlockSymmetricMatrix.h:111
const std::valarray< T > & getDiagonalValues() const
get the diagonal values : Diagonal[i].I_P
Definition: SM_PackedBlockSymmetricMatrix.h:215
const std::valarray< T > & getSupBlocksValues() const
get the values of superior blocks of the matrix
Definition: SM_PackedBlockSymmetricMatrix.h:210