1 #ifndef MMSD_DoubleSymmetricMatrix_H
2 #define MMSD_DoubleSymmetricMatrix_H
41 SP::LAP_DoubleFullSymmetricMatrix mFullStorage;
42 SP::LAP_DoublePackedSymmetricMatrix mPackedStorage;
68 inline static SP::MMSD_DoubleSymmetricMatrix
New() {
86 inline double&
operator()(
const size_t& i,
const size_t& j) {
87 return (mFullStorage.get()!=
null)?(*mFullStorage.get())(i,j):(*mPackedStorage.get())(i,j);
93 inline const double&
operator()(
const size_t& i,
const size_t& j)
const {
94 return (mFullStorage.get()!=
null)?(*mFullStorage)(i,j):(*mPackedStorage.get())(i,j);
101 if (mFullStorage!=
null) {
102 if (fsy!=
null) (*mFullStorage)*=(*fsy);
103 else if (psy!=
null) (*mFullStorage)*=(*psy);
104 }
else if (mPackedStorage!=
null) {
105 if (fsy!=
null) (*mPackedStorage)*=(*fsy);
106 else if (psy!=
null) (*mPackedStorage)*=(*psy);
113 if (mFullStorage.get()!=
null) (*mFullStorage.get())*=s;
114 else if (mPackedStorage.get()!=
null) (*mPackedStorage.get())*=s;
120 if (mFullStorage.get()!=
null) (*mFullStorage.get())/=s;
121 else if (mPackedStorage.get()!=
null) (*mPackedStorage.get())/=s;
128 if (mFullStorage.get()!=
null) (*mFullStorage.get())+=s;
129 else if (mPackedStorage.get()!=
null) (*mPackedStorage.get())+=s;
136 if (mFullStorage.get()!=
null) (*mFullStorage.get())-=s;
137 else if (mPackedStorage.get()!=
null) (*mPackedStorage.get())-=s;
143 if (mFullStorage.get()!=
null) (*mFullStorage.get())^=s;
144 else if (mPackedStorage.get()!=
null) (*mPackedStorage.get())^=s;
152 if (mFullStorage.get()!=
null) (*mFullStorage.get())=s;
153 else if (mPackedStorage.get()!=
null) (*mPackedStorage.get())=s;
160 else if (mPackedStorage.get()!=
null) mPackedStorage->copy(s.
getMatrix());
166 if (mFullStorage!=
null) mFullStorage->
copy(s);
167 else if (mPackedStorage.get()!=
null) mPackedStorage->copy(s);
173 if (mFullStorage.get()!=
null) mFullStorage->
copy(s);
174 else if (mPackedStorage.get()!=
null) mPackedStorage->copy(s);
180 if (mFullStorage.get()!=
null) mFullStorage->
copy(s);
181 else if (mPackedStorage.get()!=
null) mPackedStorage->copy(s);
204 void copy(SP::MMSD_DoubleSymmetricMatrix x) {
244 if (mFullStorage.get()!=
null) {
245 return (*mFullStorage.get());
247 return (*mPackedStorage.get());
254 if (mFullStorage.get()!=
null) {
255 return (*mFullStorage.get());
257 return (*mPackedStorage.get());
271 if (mFullStorage.get()!=
null)
return FULL_STORAGE;
279 if (mFullStorage.get()!=
null) mFullStorage->setSize(n);
280 else if (mPackedStorage.get()!=
null) mPackedStorage->setSize(n);
286 virtual void setSize(
const size_t& n,
const size_t& p) {
287 if (mFullStorage.get()!=
null) mFullStorage->setSize(n,p);
288 else if (mPackedStorage.get()!=
null) mPackedStorage->setSize(n,p);
295 if (mFullStorage.get()!=
null) mFullStorage->getColumn(j,v);
296 else if (mPackedStorage.get()!=
null) mPackedStorage->getColumn(j,v);
300 virtual void getColumn(
const size_t& j,SP::LAP_DoubleVector v)
const {
301 if (mFullStorage.get()!=
null) mFullStorage->getColumn(j,v);
302 else if (mPackedStorage.get()!=
null) mPackedStorage->getColumn(j,v);
308 if (mFullStorage.get()!=
null)
return mFullStorage->getRowsNumber();
309 else if (mPackedStorage.get()!=
null)
return mPackedStorage->getRowsNumber();
315 if (mFullStorage.get()!=
null)
return mFullStorage->getSize(d);
316 else if (mPackedStorage.get()!=
null)
return mPackedStorage->getSize(d);
322 if (mFullStorage.get() !=
null)
return mFullStorage->getColumnsNumber();
323 else if (mPackedStorage.get()!=
null)
return mPackedStorage->getColumnsNumber();
329 virtual void set(
const size_t& i,
338 virtual double get(
const size_t& i,
339 const size_t& j)
const {
345 virtual void add(
const size_t& i,
354 inline void setValues(
const size_t& n,
const double* values) {
355 if (mFullStorage.get()!=
null) mFullStorage->setValues(n,values);
356 else if (mPackedStorage.get()!=
null) mPackedStorage->setValues(n,values);
370 if (mFullStorage.get() !=
null) mFullStorage->vectorProduct(vect,result);
371 else if (mPackedStorage.get()!=
null) mPackedStorage->vectorProduct(vect,result);
379 if (mFullStorage.get() !=
null)
380 mFullStorage->vectorProduct(
false,
383 else if (mPackedStorage.get()!=
null)
384 mPackedStorage->vectorProduct(
false,
392 SP::LAP_DoubleVector result)
const {
393 if (mFullStorage.get() !=
null) mFullStorage->vectorProduct(*vect.get(),*result.get());
394 else if (mPackedStorage.get()!=
null) mPackedStorage->vectorProduct(*vect.get(),*result.get());
403 if (mFullStorage.get() !=
null) mFullStorage->vectorProduct(vect,alpha,beta,result);
404 else if (mPackedStorage.get()!=
null) mPackedStorage->vectorProduct(vect,alpha,beta,result);
409 if (mFullStorage.get() !=
null) {
410 mFullStorage->dotProduct(alpha,vect);
412 else if (mPackedStorage.get()!=
null) mPackedStorage->dotProduct(alpha,vect);
423 if (mFullStorage.get() !=
null) {
436 else if (mPackedStorage.get()!=
null) {
457 if (mFullStorage.get()!=
null) mFullStorage->matrixProduct(B,C);
458 else if (mPackedStorage.get()!=
null) mPackedStorage->matrixProduct(B,C);
466 if (mFullStorage.get() !=
null) mFullStorage->matrixProduct(B,alpha,beta,C);
467 else if (mPackedStorage.get()!=
null) mPackedStorage->matrixProduct(
true,B,alpha,beta,C);
479 if (mFullStorage.get() !=
null) {
480 mFullStorage->matrixProduct(leftSide,B,alpha,beta,C);
483 else if (mPackedStorage.get()!=
null) {
484 mPackedStorage->matrixProduct(leftSide,B,alpha,beta,C);
518 if (mFullStorage.get()!=
null) {
521 }
else if (mPackedStorage.get()!=
null) {
540 if (mFullStorage.get()!=
null) {
541 return mFullStorage->computeEigenValueDecomposition(U,VR);
542 }
else if (mPackedStorage.get()!=
null) {
543 return mPackedStorage->computeEigenValueDecomposition(U,VR);
563 return LAP_DoubleFullSymmetricMatrix::computeEigenValueDecomposition(*fsy,U,VR);
576 const int& il,
const int& iu)
const {
577 if (mFullStorage.get()!=
null) {
579 return mFullStorage->computeEigenValueDecomposition(C,U,VR,il,iu);
580 }
else if (mPackedStorage.get()!=
null) {
582 return mPackedStorage->computeEigenValueDecomposition(C,U,VR,il,iu);
605 return LAP_DoubleFullSymmetricMatrix::computeEigenValueDecomposition(*fsy,U,Z,il,ul);
621 if (mFullStorage.get()!=
null)
return mFullStorage->norm2();
622 else if (mPackedStorage.get()!=
null)
return mPackedStorage->norm2();
629 if (mFullStorage.get()!=
null)
return mFullStorage->norm2(v);
630 else if (mPackedStorage.get()!=
null)
return mPackedStorage->norm2(v);
641 if (mFullStorage.get()!=
null)
return mFullStorage->sum(d,s);
642 else if (mPackedStorage.get()!=
null)
return mPackedStorage->sum(d,s);
652 if (mFullStorage.get()!=
null)
return mFullStorage->sum(d,index);
653 else if (mPackedStorage.get()!=
null)
return mPackedStorage->sum(d,index);
661 if (mFullStorage.get()!=
null)
return mFullStorage->trace();
662 else if (mPackedStorage.get()!=
null)
return mPackedStorage->trace();
673 const double& errorMax,
678 const double& errorMax,
682 const double& errorMax,
692 if (mFullStorage.get()!=
null)
return mFullStorage->toString();
693 else if (mPackedStorage.get()!=
null)
return mPackedStorage->toString();
const LAP_DoubleVector & getValues() const
get the values of the symmetric matrix
Definition: MMSD_DoubleSymmetricMatrix.h:225
virtual tReal sum(const tFlag &d, LAP_DoubleVector &s) const
make the sum among the direction if (d==ROW) sum all the rows and size of s if the number of rows if ...
Definition: MMSD_DoubleSymmetricMatrix.h:640
MMSD_DoubleSymmetricMatrix & operator*=(const lapack_real &s)
scale operator
Definition: MMSD_DoubleSymmetricMatrix.h:112
virtual void setSize(const size_t &n, const size_t &p)
set the dimension of the matrix
Definition: MMSD_DoubleSymmetricMatrix.h:286
virtual tBoolean computeEigenValues(LAP_DoubleVector &U) const
compute the eigen values of This: A is copied in ascending order
Definition: LAP_DoublePackedSymmetricMatrix.h:870
LAP_DoubleMatrixStorage & getStorage()
set the storage
Definition: LAP_DoubleMatrix.h:179
this class describes a full symmetric matrix for lapack used
Definition: LAP_DoubleFullSymmetricMatrix.h:31
MMSD_DoubleSymmetricMatrix & operator+=(const lapack_real &s)
add operator
Definition: MMSD_DoubleSymmetricMatrix.h:127
virtual tString toString() const
print the matrix taking into account the view
Definition: MMSD_DoubleSymmetricMatrix.h:691
this class describes a general double symmetric matrix
Definition: LAP_DoubleSymmetricMatrix.h:21
MMSD_DoubleSymmetricMatrix & operator/=(const lapack_real &s)
divide operator
Definition: MMSD_DoubleSymmetricMatrix.h:119
MMSD_DoubleSymmetricMatrix & operator=(const MMSD_DoubleSymmetricMatrix &s)
init all the matrix to s
Definition: MMSD_DoubleSymmetricMatrix.h:158
virtual void getColumn(const size_t &j, SP::LAP_DoubleVector v) const
get the j-th column of this symmetric matrix in a vector
Definition: MMSD_DoubleSymmetricMatrix.h:300
const LAP_DoubleSymmetricMatrix & getMatrix() const
get its matrix form
Definition: MMSD_DoubleSymmetricMatrix.h:243
size_t getSize() const
Definition: MMSD_DoubleSymmetricMatrix.h:262
MMSD_DoubleSymmetricMatrix & operator=(const double &s)
init all the matrix to s
Definition: MMSD_DoubleSymmetricMatrix.h:151
virtual void product(const LAP_DoubleFullGeneralMatrix &B, const lapack_real &alpha, const lapack_real &beta, LAP_DoubleFullGeneralMatrix &C) const
return C=(This) . B (lefside=true) or B. (this) (lefside=false)
Definition: MMSD_DoubleSymmetricMatrix.h:462
static tBoolean computeEigenValues(LAP_DoubleFullSymmetricMatrix &A, LAP_DoubleVector &U)
compute the eigen values of A in ascending order and A is destroyed after method lapack method dsyev ...
Definition: LAP_DoubleFullSymmetricMatrix.h:869
virtual tReal sum(const tFlag &d, const int &index) const
make the sum among the direction if (d==ROW) sum all the rows and size of s if the number of rows if ...
Definition: MMSD_DoubleSymmetricMatrix.h:651
virtual void set(const size_t &i, const size_t &j, const double &v)
set the value taking into account the view
Definition: MMSD_DoubleSymmetricMatrix.h:329
MMSD_DoubleSymmetricMatrix & operator=(const LAP_DoubleFullGeneralMatrix &s)
init all the matrix to s
Definition: MMSD_DoubleSymmetricMatrix.h:179
LAP_DoubleSymmetricMatrix & getMatrix()
get its matrix form
Definition: MMSD_DoubleSymmetricMatrix.h:253
MMSD_DoubleSymmetricMatrix & operator^=(const lapack_real &s)
power operator
Definition: MMSD_DoubleSymmetricMatrix.h:142
This class describes the FullMatrix class.
Definition: MMSD_DoubleFullMatrix.h:17
Definition: LAP_DoubleVector.h:20
#define lapack_int
Definition: lapack_functions.h:7
Definition: LAP_DoubleMatrix.h:18
virtual tBoolean computeEigenValues(LAP_DoubleVector &U) const
compute the eigen values of This: This is copied
Definition: MMSD_DoubleSymmetricMatrix.h:517
void setStorage(const tFlag &storageType)
get its matrix form
Definition: MMSD_DoubleSymmetricMatrix.cpp:55
void copy(SP::MMSD_DoubleSymmetricMatrix x)
copy a matrix the view is taken into account
Definition: MMSD_DoubleSymmetricMatrix.h:204
MMSD_DoubleSymmetricMatrix()
build a matrix
Definition: MMSD_DoubleSymmetricMatrix.cpp:10
tLVectorIndex getSize() const
get the size of the vector
Definition: LAP_ConstVector.h:170
virtual SP::LAP_DoubleMatrix matrixProduct(const LAP_DoubleMatrix &B) const
return C=(This) . B
Definition: LAP_DoubleFullSymmetricMatrix.h:679
void setValues(const size_t &n, const double *values)
set the values values is orderd by column
Definition: MMSD_DoubleSymmetricMatrix.h:354
void product(const LAP_ConstDoubleVector &vect, LAP_DoubleVector &result) const
return result=this.vector
Definition: MMSD_DoubleSymmetricMatrix.h:375
tLVectorIndex getValuesNumber() const
get the number of values
Definition: LAP_DoubleMatrix.h:281
#define tBoolean
Definition: types.h:48
virtual tReal trace() const
return the trace of the symmetric matrix
Definition: MMSD_DoubleSymmetricMatrix.h:660
virtual void setSize(const tLVectorIndex &n, const tLVectorIndex &p)
set the dimension of the matrix and allocate the values array
Definition: LAP_DoubleFullGeneralMatrix.h:230
#define lapack_real
Definition: lapack_functions.h:9
static const tFlag ROW
Definition: LAP_Matrix.h:21
virtual tBoolean product(const tBoolean &leftSide, const LAP_DoubleFullGeneralMatrix &B, const lapack_real &alpha, const lapack_real &beta, LAP_DoubleFullGeneralMatrix &C) const
make the product C = alpha. A . B +beta C if leftSide=true C = alpha. B . A +beta C if leftSide=false...
Definition: MMSD_DoubleSymmetricMatrix.h:474
void setValues(SP::MMSD_DoubleVector values)
set the values of the symmetric matrix
Definition: MMSD_DoubleSymmetricMatrix.h:230
#define null
Definition: types.h:13
const tLVectorIncrement & getIncrement() const
get the increment of the vector
Definition: LAP_Vector.h:529
MMSD_DoubleSymmetricMatrix & operator=(const LAP_DoublePackedSymmetricMatrix &s)
init all the matrix to s
Definition: MMSD_DoubleSymmetricMatrix.h:172
virtual SP::LAP_DoubleMatrix matrixProduct(const LAP_DoubleMatrix &B) const
return C=(This) . B
Definition: LAP_DoublePackedSymmetricMatrix.h:627
static tBoolean computeEigenValueDecomposition(MMSD_DoubleSymmetricMatrix &A, LAP_DoubleVector &U, LAP_DoubleFullGeneralMatrix &Z, const lapack_int &il, const lapack_int &ul)
compute the eigen elements of A A is supposed to be symmetric, the eigen vectors are set in Z...
Definition: MMSD_DoubleSymmetricMatrix.h:595
Definition: LAP_DoubleFullGeneralMatrix.h:30
void orthogonalTransformation(const int &n, const double &errorMax, MMSD_DoubleSymmetricMatrix &H)
make the orthogonalization of this
Definition: MMSD_DoubleSymmetricMatrix.cpp:72
virtual tBoolean computeEigenValueDecomposition(LAP_DoubleVector &U, LAP_DoubleFullGeneralMatrix &VR) const
compute the eigen values decomposition on This
Definition: MMSD_DoubleSymmetricMatrix.h:538
static void product(const tBoolean &leftSide, const MMSD_DoubleSymmetricMatrix &A, const LAP_DoubleFullGeneralMatrix &B, const lapack_real &alpha, const lapack_real &beta, LAP_DoubleFullGeneralMatrix &C)
make the product C = alpha. A . B +beta C if leftSide=true C = alpha. B . A +beta C if leftSide=false...
Definition: MMSD_DoubleSymmetricMatrix.h:495
virtual ~MMSD_DoubleSymmetricMatrix()
destroy a matrix
Definition: MMSD_DoubleSymmetricMatrix.cpp:17
tBoolean computeEigenValueDecomposition(LAP_DoubleVector &U, LAP_DoubleFullGeneralMatrix &VR, const int &il, const int &iu) const
compute the eigen elements of This supposed to be symmetric, the eigen vectors are set in Z...
Definition: MMSD_DoubleSymmetricMatrix.h:574
static const tFlag PACKED_STORAGE
to store symmetric matrix in a packed storage form
Definition: MMSD_DoubleSymmetricMatrix.h:29
double & operator()(const size_t &i, const size_t &j)
accessor of element at row i and column j taking into account the view only use the upper diagonal ...
Definition: MMSD_DoubleSymmetricMatrix.h:86
virtual void setSize(const size_t &n)
set the dimension of the matrix
Definition: MMSD_DoubleSymmetricMatrix.h:278
const tLVectorIndex & getSize(const tFlag &direction) const
get the size in direction
Definition: LAP_Matrix.h:108
tFlag getStorage() const
get its matrix form
Definition: MMSD_DoubleSymmetricMatrix.h:270
size_t getRowsNumber() const
get the rows number
Definition: MMSD_DoubleSymmetricMatrix.h:307
const double & operator()(const size_t &i, const size_t &j) const
accessor of element at row i and column j taking into account the view only use the upper diagonal ...
Definition: MMSD_DoubleSymmetricMatrix.h:93
int getValuesNumber() const
get the values number
Definition: MMSD_DoubleSymmetricMatrix.h:237
tBoolean computeEigenValueDecomposition(LAP_DoubleVector &U, LAP_DoubleFullGeneralMatrix &W) const
compute the eigen elements in ascending order of This the eigen vectors are set in This: This is dest...
Definition: LAP_DoublePackedSymmetricMatrix.h:894
#define tLVectorIndex
Definition: lapack_types.h:13
DEFINE_SPTR(MMSD_DoubleFullMatrix)
this class describes a packed symmetric matrix for lapack used where values are stored in vector: {A(...
Definition: LAP_DoublePackedSymmetricMatrix.h:31
#define tString
Definition: types.h:49
virtual void product(const LAP_DoubleVector &vect, const lapack_real &alpha, const lapack_real &beta, LAP_DoubleVector &result) const
return result=beta.result+alpha.this.vector
Definition: MMSD_DoubleSymmetricMatrix.h:399
const tLVectorIncrement & getIncrement() const
get the increment of the vector
Definition: LAP_ConstVector.h:175
size_t getColumnsNumber() const
get the rows number
Definition: MMSD_DoubleSymmetricMatrix.h:321
virtual void rankSymmetricProduct(const lapack_real &alpha, const LAP_DoubleVector &vect)
Definition: MMSD_DoubleSymmetricMatrix.h:408
virtual void copy(const LAP_DoubleMatrix &x)
copy a matrix the view is taken into account
Definition: MMSD_DoubleSymmetricMatrix.cpp:25
virtual tReal norm2() const
return norm2 sqrt(sum_ij(aij^2))=sqrt(tr(AtA));
Definition: MMSD_DoubleSymmetricMatrix.h:620
const LAP_DoubleVector & getValues() const
get the vector values of the matrix
Definition: LAP_DoubleMatrixStorage.h:197
DEFINE_SVPTR(MMSD_DoubleSymmetricMatrix)
MMSD_DoubleSymmetricMatrix & operator-=(const lapack_real &s)
sub operator
Definition: MMSD_DoubleSymmetricMatrix.h:135
virtual void setValues(SP::LAP_DoubleVector v)
set the values of the matrix
Definition: LAP_DoubleMatrix.h:153
static SP::MMSD_DoubleSymmetricMatrix New()
Definition: MMSD_DoubleSymmetricMatrix.h:68
virtual void getColumn(const size_t &j, LAP_DoubleVector &v) const
get the j-th column of this symmetric matrix in a vector
Definition: MMSD_DoubleSymmetricMatrix.h:294
void product(const LAP_DoubleVector &vect, LAP_DoubleVector &result) const
return result=this.vector
Definition: MMSD_DoubleSymmetricMatrix.h:368
virtual tReal norm2(LAP_DoubleVector &v) const
return norm2 of the matrix and for each row;
Definition: MMSD_DoubleSymmetricMatrix.h:628
void product(SPC::LAP_DoubleVector vect, SP::LAP_DoubleVector result) const
Definition: MMSD_DoubleSymmetricMatrix.h:391
virtual tLVectorIndex getColumnsNumber() const
get the columns number of the matrix from view
Definition: LAP_Matrix.h:121
static tBoolean computeEigenValueDecomposition(MMSD_DoubleSymmetricMatrix &A, LAP_DoubleVector &U, LAP_DoubleFullGeneralMatrix &VR)
compute the eigen values decomposition of A; A is destroyed
Definition: MMSD_DoubleSymmetricMatrix.h:554
Definition: MMSD_DoubleSymmetricMatrix.h:22
MMSD_DoubleSymmetricMatrix & operator*=(const MMSD_DoubleSymmetricMatrix &s)
operator *= : element by element multiplication
Definition: MMSD_DoubleSymmetricMatrix.h:98
size_t getSize(const tFlag &d) const
get the rows number
Definition: MMSD_DoubleSymmetricMatrix.h:314
static const tFlag FULL_STORAGE
to store symmetric matrix in afull storage form
Definition: MMSD_DoubleSymmetricMatrix.h:32
void product(const LAP_DoubleFullGeneralMatrix &B, LAP_DoubleFullGeneralMatrix &C) const
return C=(This) . B
Definition: MMSD_DoubleSymmetricMatrix.h:454
Definition: LAP_ConstDoubleVector.h:25
#define tReal
Definition: types.h:18
tBoolean product(const MMSD_DoubleSymmetricMatrix &B, LAP_DoubleFullGeneralMatrix &C) const
return C=(This) . B
Definition: MMSD_DoubleSymmetricMatrix.h:420
virtual void add(const size_t &i, const size_t &j, const double &v)
add the value taking into account the view
Definition: MMSD_DoubleSymmetricMatrix.h:345
void setSize(const tLVectorIndex &n)
set the view to [0,n[ by 1 increment if values is too small, re-alocate it
Definition: LAP_Vector.h:360
This class is the base class of all Mixture of Multiple Scaled Distribution package.
Definition: MMSD_Object.h:20
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
#define tFlag
Definition: types.h:14
MMSD_DoubleSymmetricMatrix & operator=(const LAP_DoubleFullSymmetricMatrix &s)
init all the matrix to s
Definition: MMSD_DoubleSymmetricMatrix.h:165