C++ main module for mmsd Package  1.0
LAP_DoublePackedSymmetricMatrix.h
Go to the documentation of this file.
1 #ifndef LAP_DoublePackedSymmetricMatrix_H
2 #define LAP_DoublePackedSymmetricMatrix_H
3 
5 
7 
9 
11 
12 #include "LAP_DoubleVector.h"
13 #include "LAP_IntegerVector.h"
14 
16 
17 //friend classes
19 
20 
32 
34 
35 private:
36  // ATTRIBUTES
37 
38  // ASSOCIATIONS
39 
40 
41 
42  // METHOD
43 
44 
45 public:
46  // CONSTRUCTORS
53 
54  // DESTRUCTORS
58 
59 
60 
61  // -------------
62  // NEW METHODS
63  // -------------
64 public:
65 
66  inline static SP::LAP_DoublePackedSymmetricMatrix New() {
67  SP::LAP_DoublePackedSymmetricMatrix p(new LAP_DoublePackedSymmetricMatrix(),
69  p->setThis(p);
70  return p;
71  };
72 
73  inline static SP::LAP_DoublePackedSymmetricMatrix New(const tLVectorIndex& n) {
74  SP::LAP_DoublePackedSymmetricMatrix p=New();
75  p->setSize(n);
76  return p;
77  };
80  virtual SP::LAP_DoubleMatrix NewInstance() const {
81  return New();
82  }
83 
84 
85  //-----------
86  // OPERATORS
87  // ----------
88 
92  virtual double& operator()(const tLVectorIndex& i,const tLVectorIndex& j) {
93  return (i<=j)?getPackedStorage()(i,j):getPackedStorage()(j,i);
94  };
95 
99  virtual const double& operator()(const tLVectorIndex& i,const tLVectorIndex& j) const {
100  return (i<=j)?getPackedStorage()(i,j):getPackedStorage()(j,i);
101  };
102 
103 
104 
105  //copy operator
106  //=============
107 
111  getStorage().init(s);
112  return (*this);
113  };
117  copy(s);
118  return (*this);
119  };
120 
121  //scalar operators
122  //================
123 
127  getPackedStorage()^=s;
128  return (*this);
129  }
130 
134  getPackedStorage()*=s;
135  return (*this);
136  }
140  getPackedStorage()/=s;
141  return (*this);
142  }
143 
147  getPackedStorage()+=s;
148  return (*this);
149  }
150 
151 
155  getPackedStorage()-=s;
156  return (*this);
157  }
158 
159  //pack matrix operator
160  //=====================
161 
166  return (*this);
167  }
172  return (*this);
173  }
174 
179  return (*this);
180  }
185  return (*this);
186  }
187  //full matrix operator
188  //=====================
189 
196 
203 
204 
205 
206 
207 
208 public:
209 
210  //dimension setting
211  //=================
212 
216  virtual void setSize(const tLVectorIndex & nRows,const tLVectorIndex& nCols) {
217  tLVectorIndex d=(nRows<nCols)?nRows:nCols;
219 
221  }
222 
226  virtual void setSize(const tLVectorIndex & n) {
228 
229  getStorage().setValuesNumber( ( (tLVectorIndex)n)*((tLVectorIndex)(n+1)) /2 );
230  }
231 
232  // values setting
233  //================
234 
238  virtual void setValues(SP::LAP_DoubleVector values) {
239  ASSERT_IN(values.get()!=null);
240 
241  //compute the number of columns
242  tLVectorIndex n=values->getSize();
243  n=( ((sqrt(1+8*n)-1)/2) +0.5);
244 
246 
247  //set the values pointer
248  getStorage().setValuesPointer(values);
249 
250  }
251 
254  virtual void setValues(const tLVectorIndex& n,const double* values) {
255 
256  tLVectorIndex nRows=( ((sqrt(1+8*n)-1)/2) +0.5);
258 
259  //set the values
260  getStorage().setValues(n,values);
261 
262  }
263 
265  //======
266 
267 public:
271  return *dynamic_cast<LAP_DoublePackedStorage*>(&getStorage());
272  };
276  return *dynamic_cast<const LAP_DoublePackedStorage*>(&getStorage());
277  };
278 
279 public:
282  virtual void getColumn(const tLVectorIndex& j,LAP_DoubleVector& v) const;
285  virtual void getColumn(const tLVectorIndex& j,SP::LAP_DoubleVector v) const {
286  ASSERT_IN(v.get()!=null);
287  getColumn(j,*v.get());
288  };
289 
290 
291 
292 
295  virtual void getRow(const tLVectorIndex& i,LAP_DoubleVector& v) const;
296 
299  virtual void getRow(const tLVectorIndex& i,SP::LAP_DoubleVector v) const {
300  ASSERT_IN(v.get()!=null);
301  getRow(i,*v.get());
302  };
303 
304 
305 
306 
307  // ------------------------
308  // operation on matrix
309  // ------------------------
310 public:
311 
312 
315  virtual tReal norm2() const;
316 
319  virtual tReal norm2(LAP_DoubleVector& v) const;
320 
326  virtual tReal sum(const tFlag& d,LAP_DoubleVector& s) const;
327 
333  virtual tReal sum(const tFlag& d,const tLVectorIndex& index) const;
334 
335 
336 
337 
338  // ----------------
339  // vector product
340  // ----------------
341 
342 public:
343 
346  virtual void vectorProduct(const LAP_DoubleVector& X,LAP_DoubleVector& Y) {
348  }
349 
356  virtual void vectorProduct(const LAP_DoubleVector& X,
357  const lapack_real& alpha,
358  const lapack_real& beta,
359  LAP_DoubleVector& Y) const {
360  //get the dimenson of Matrix
362 
363  tLVectorIndex nX=X.getSize();
364 
365  //verify the dimension of X
366  if (nX!=nRows) {
367  throw LAP_Exception("math/linalg/core","LAP_DoublePackedSymmetricMatrix::product()","incompatible size of X vector");
368  }
369 
370  //set the dimension of Y is beta=0
371  if (beta==0) {
372  Y.setSize(nRows);
373  }
374  tLVectorIndex nY=Y.getSize();
375  if (nY!=nRows) {
376  throw LAP_Exception("math/linalg/core","LAP_DoublePackedSymmetricMatrix::product()","incompatible size of Y vector");
377  }
378  //make the product
379  vectorProduct(nX,X.getIncrement(),&X(0),
380  alpha,
381  beta,
382  nY,Y.getIncrement(),&Y(0));
383  };
384 
391  virtual void vectorProduct(const LAP_ConstDoubleVector& X,
392  const lapack_real& alpha,
393  const lapack_real& beta,
394  LAP_DoubleVector& Y) const {
395  //get the dimenson of Matrix
397 
398  tLVectorIndex nX=X.getSize();
399 
400  //verify the dimension of X
401  if (nX!=nRows) {
402  throw LAP_Exception("math/linalg/core","LAP_DoublePackedSymmetricMatrix::product()","incompatible size of X vector");
403  }
404 
405  //set the dimension of Y is beta=0
406  if (beta==0) {
407  Y.setSize(nRows);
408  }
409  tLVectorIndex nY=Y.getSize();
410  if (nY!=nRows) {
411  throw LAP_Exception("math/linalg/core","LAP_DoublePackedSymmetricMatrix::product()","incompatible size of Y vector");
412  }
413  //make the product
414  vectorProduct(nX,X.getIncrement(),&X(0),
415  alpha,
416  beta,
417  nY,Y.getIncrement(),&Y(0));
418  };
419 
420 
421 public:
432  virtual void vectorProduct(const tBoolean& isTrans,
433  const tLVectorIndex& nX,const tLVectorIncrement& incX,const double *X,
434  const lapack_real& alpha, const lapack_real& beta,
435  const tLVectorIndex& nY,const tLVectorIncrement& incY,double *Y) const {
436  vectorProduct(nX,incX,X,alpha,beta,nY,incY,Y);
437  }
438 
451  virtual void vectorProduct(const tLVectorIndex& nx,const tLVectorIncrement& incx,const double* x,
452  const lapack_real& alpha,
453  const lapack_real& beta,
454  const tLVectorIndex& ny,const tLVectorIncrement&incy,double* y) const {
455 
457  if (nRows==0) return;
458  if (nRows!=nx) {
459  throw LAP_Exception("math/linal/core","LAP_DoublePackedSymmetricMatrix::product","incompatible size of X vector");
460  }
461  if (nRows!=ny) {
462  throw LAP_Exception("math/linal/core","LAP_DoublePackedSymmetricMatrix::product","incompatible size of Y vector");
463  }
464  if (x==y) {
465  throw LAP_Exception("math/linal/core","LAP_DoublePackedSymmetricMatrix::product","x & y must have different pointer");
466  }
467 
469  nRows,
470  &(*this)(0,0),
471  alpha,beta,
472  ny,incy,y);
473  }
474 
475 
476 
477 
478 public:
483  virtual void dotProduct(const LAP_DoubleVector& v) {
484  dotProduct(1,v);
485  };
490  virtual void dotProduct(const double& alpha,const LAP_DoubleVector& X) {
491  //A is considered to be of size 1 x Nx : X is the first row
492  tLVectorIndex nRows=X.getSize();
493  setSize(nRows);
494 
496  alpha,//alpha
497  nRows,&(*this)(0,0));
498 
499  }
503  rankSymmetricProduct(1.,0.,false,A);
504  }
507  void rankSymmetricProduct(const double& alpha,const tBoolean& isTrans,const LAP_DoubleFullGeneralMatrix& A) {
508  rankSymmetricProduct(alpha,0,isTrans,A);
509  }
510 
515  virtual void rankSymmetricProduct(const double& alpha,const double& beta,const tBoolean& isTrans,
516  const LAP_DoubleFullGeneralMatrix& A) {
517  //A is considered to be of size 1 x Nx : X is the first row
518  tLVectorIndex nARows=A.getRowsNumber();
519  tLVectorIndex nACols=A.getColumnsNumber();
521  const tLVectorIncrement& incA=A.getRowIncrement();
522  if (nARows*nACols==0) return;
523  rankSymmetricProduct(alpha,beta,nARows,nACols,incA,ldA,isTrans,&A(0,0));
524 
525  }
526 
537  virtual void rankSymmetricProduct(const double& alpha,const double& beta,
538  const tLVectorIndex& nARows,const tLVectorIndex& nACols,const tLVectorIncrement& incA,const tLVectorIndex& ldA,
539  const tBoolean& isTransA,const double* A) {
540  if (alpha==0) {
541  (*this)*=beta;
542  return;
543  }
544  tLVectorIndex nRows=nARows;
545  tLVectorIndex nCols=nACols;
546  if (isTransA) std::swap(nRows,nCols);
547  if (beta==0) {
548  setSize(nRows);
549  } else {
550  if (getRowsNumber()!=nRows) {
551  throw LAP_Exception("math/linalg/core",
552  "LAP_DoublePackedSymmetricMatrix::rankSymmetricProduct",
553  "matrices size incompatible");
554  }
555  }
556 
557  DoublePackedSymmetricMatrixKRankSymmetricProduct(nARows,nACols,incA,ldA,isTransA,A,
558  alpha,beta,
559  0,0,null,
560  nRows,&(*this)(0,0));
561  }
562 
566  rankSymmetricProduct(D,1.,0.,false,A);
567  }
570  void rankSymmetricProduct(const LAP_DoubleVector& D,const double& alpha,const tBoolean& isTrans,const LAP_DoubleFullGeneralMatrix& A) {
571  rankSymmetricProduct(D,alpha,0,isTrans,A);
572  }
573 
585  virtual void rankSymmetricProduct(const LAP_DoubleVector& D,const double& alpha,const double& beta,const tBoolean& isTrans,const LAP_DoubleFullGeneralMatrix& A) {
586  if (alpha==0) {
587  (*this)*=beta;
588  return;
589  }
590  //A is considered to be of size 1 x Nx : X is the first row
591  tLVectorIndex nRows=A.getRowsNumber();
593  if (nRows*nCols==0) return;
594 
595  if (isTrans) std::swap(nRows,nCols);
596  if (beta==0) {
597  setSize(nRows);
598  } else {
599  if (getRowsNumber()!=nRows) {
600  throw LAP_Exception("math/linalg/core",
601  "LAP_DoublePackedSymmetricMatrix::rankSymmetricProduct",
602  "matrices size incompatible");
603  }
604  }
605  if (nCols!=D.getSize()) {
606  throw LAP_Exception("math/linalg/core",
607  "LAP_DoublePackedSymmetricMatrix::rankSymmetricProduct",
608  "matrix & diagonal have incompatible size");
609  }
611  A.getRowIncrement(),A.getLeadingDimension(),isTrans,&A(0,0),
612  alpha,beta,
613  D.getSize(),D.getIncrement(),&D(0),
614  nRows,&(*this)(0,0));
615  }
616 
617 
618 
619 
620 
621 
622  // ----------------
623  // matrix product
624  // ----------------
627  virtual SP::LAP_DoubleMatrix matrixProduct(const LAP_DoubleMatrix& B) const {
628  SP::LAP_DoubleFullGeneralMatrix C=LAP_DoubleFullGeneralMatrix::New();
629  const LAP_DoublePackedSymmetricMatrix* dsyM=dynamic_cast<const LAP_DoublePackedSymmetricMatrix*>(&B);
630  if (dsyM!=null) {
631  matrixProduct(*dsyM,*C.get());
632  return C;
633  }
634  const LAP_DoubleFullGeneralMatrix* dgeM=dynamic_cast<const LAP_DoubleFullGeneralMatrix*>(&B);
635  if (dgeM!=null) {
636  matrixProduct(*dgeM,*C.get());
637  return C;
638  }
639  return C;
640  };
641 
645  LAP_DoubleFullGeneralMatrix& C) const {
646 
648  matrixProduct(true,(*this),B,1.0,0,C);
649  };
653  LAP_DoubleFullGeneralMatrix& C) const {
654 
655  matrixProduct(true,(*this),B,1.0,0,C);
656  };
657 
658 
663  virtual void matrixProduct(const tBoolean& leftSide,
665  const lapack_real& alpha,
666  const lapack_real& beta,
667  LAP_DoubleFullGeneralMatrix& C) const {
668 
669  matrixProduct(leftSide,*this,B,alpha,beta,C);
670 
671  }
672 
685  virtual void matrixProduct(const tBoolean& leftSide,
686  const tLVectorIndex& nBRows,
687  const tLVectorIndex& nBCols,
688  const tLVectorIncrement& incB,
689  const tLVectorIndex& ldB,
690  const double* B,
691  const lapack_real& alpha,
692  const lapack_real& beta,
693  LAP_DoubleFullGeneralMatrix& C) const {
694  ASSERT_IN(B!=&C(0,0));
695 
696  //verify the dimension
698 
699  tLVectorIndex M=nBRows;
700  tLVectorIndex P=nBCols;
701  if (!leftSide) std::swap(M,P);
702 
703  if (N!=M) throw LAP_Exception("math/linalg/core","LAP_DoubleFullSymmetricMatrix::product()","incompatible size of matrix");
704  if (beta==0) {
705  if (leftSide) C.setSize(N,P);
706  else C.setSize(P,N);
707  } else {
708  if (leftSide && ((C.getRowsNumber()!=N) || (C.getColumnsNumber()!=P))) C.setSize(N,P);
709  else if (!leftSide && ((C.getRowsNumber()!=P) || (C.getColumnsNumber()!=N))) C.setSize(P,N);
710  }
711 
712  if (nBRows!=nBCols) throw LAP_Exception("math/linalg/core","LAP_DoubleFullSymmetricMatrix::product()","incompatible size of matrix");
713  if (beta==0) {
714  if (leftSide) C.setSize(N,P);
715  else C.setSize(P,N);
716  } else {
717  if (leftSide && ((C.getRowsNumber()!=N) || (C.getColumnsNumber()!=P))) C.setSize(N,P);
718  else if (!leftSide && ((C.getRowsNumber()!=P) || (C.getColumnsNumber()!=N))) C.setSize(P,N);
719  }
721  getRowsNumber(),&(*this)(0,0),//S
722  nBRows,nBCols,incB,ldB,false,true,B,//B
723  alpha,beta,
725  }
726 
743  static void matrixProduct(const tBoolean& leftSide,
746  const lapack_real& alpha,
747  const lapack_real& beta,
749  ASSERT_IN(&B!=&C);
750 
751  //verify the dimension
755  if (!leftSide) std::swap(M,P);
756 
757  if (N!=M) throw LAP_Exception("math/linalg/core","LAP_DoublePackedSymmetricMatrix::product()","incompatible size of matrix");
758  if (beta==0) {
759  if (leftSide) C.setSize(N,P);
760  else C.setSize(P,N);
761  } else {
762  if (leftSide && ((C.getRowsNumber()!=N) || (C.getColumnsNumber()!=P))) C.setSize(N,P);
763  else if (!leftSide && ((C.getRowsNumber()!=P) || (C.getColumnsNumber()!=N))) C.setSize(P,N);
764  }
766  S.getRowsNumber(),&S(0,0),//S
767  B.getRowsNumber(),B.getColumnsNumber(),B.getRowIncrement(),B.getLeadingDimension(),false,true,&B(0,0),//B
768  alpha,beta,
770 
771  }
787  static void matrixProduct(const tBoolean& leftSide,
790  const lapack_real& alpha,
791  const lapack_real& beta,
792  LAP_DoubleFullGeneralMatrix& C) { //verify the dimension
796  if (!leftSide) std::swap(M,P);
797 
798  if (N!=M) throw LAP_Exception("math/linalg/core","LAP_DoublePackedSymmetricMatrix::product()","incompatible size of matrix");
799  if (beta==0) {
800  if (leftSide) C.setSize(N,P);
801  else C.setSize(P,N);
802  } else {
803  if (leftSide && ((C.getRowsNumber()!=N) || (C.getColumnsNumber()!=P))) C.setSize(N,P);
804  else if (!leftSide && ((C.getRowsNumber()!=P) || (C.getColumnsNumber()!=N))) C.setSize(P,N);
805  }
806  if (leftSide) {
807 
809  S1.getRowsNumber(),&S1(0,0),//S1
810  S2.getRowsNumber(),S2.getColumnsNumber(),1,S2.getRowsNumber(),true,false,&S2(0,0),//S2
811  alpha,beta,
813  } else {
815  S2.getRowsNumber(),&S2(0,0),//S1
816  S1.getRowsNumber(),S1.getColumnsNumber(),1,S1.getRowsNumber(),true,false,&S2(0,0),//S2
817  alpha,beta,
819  }
820  }
835  void matrixProduct(const tBoolean& leftSide,
837  const lapack_real& alpha,
838  const lapack_real& beta,
839  LAP_DoubleFullGeneralMatrix& C) const {
840  matrixProduct(leftSide,*this,S,alpha,beta,C);
841  }
856  static void matrixProduct(const tBoolean& leftSide,
859  const lapack_real& alpha,
860  const lapack_real& beta,
862 
863 
864  // ----------------------
865  // eigen values & vectors
866  // ------------------------
867 public:
872  return computeEigenValues(C,U);
873  };
878  tLVectorIndex nRows=A.getRowsNumber();
880 
881  if (nRows>nCols)
882  throw LAP_Exception("math/linal/core","LAP_DoublePackedSymmetricMatrix::computeEigenValues","matrix columns number must be greater than its rows number");
883 
884  U.resetView();
885  U.setSize(nRows);
886 
887  return DoublePackedSymmetricMatrixEigenValues(nRows,&A(0,0),nRows,&U(0),1,null);
888 
889  }
890 
891 public:
896  A.copy(*this);
897  return computeEigenValueDecomposition(A,U,W);
898  };
899 
900 public:
907  LAP_DoubleVector& U,
909  tLVectorIndex nRows=A.getRowsNumber();;
910 
911  U.resetView();
912  U.setSize(nRows);
913  W.setSize(nRows,nRows);
914  return DoublePackedSymmetricMatrixEigenValues(nRows,&A(0,0),nRows,&U(0),W.getLeadingDimension(),&W(0,0));
915  }
916 
917 
918 
919 
920 public:
927  const int& il,const int& iu) const {
929  return computeEigenValueDecomposition(C,U,VR,il,iu);
930  };
931 
932 
943  LAP_DoubleVector& U,
945  const lapack_int &il,const lapack_int& ul) {
946  tLVectorIndex nRows=A.getRowsNumber();
947 
948  //eigen values
949  int nEigens=ul-il+1;
950  U.resetView();
951  U.setSize(nEigens);
952 
953  //eigen vectors
954  Z.setSize(nRows,nEigens);
955 
956  return DoublePackedSymmetricMatrixBoundedEigenValues(nRows,&A(0,0),//A
957  nEigens,&U(0),
958  il,ul,0,0,Z.getLeadingDimension(),&Z(0,0));
959  }
960 
961  // -----------------------
962  // linear system solver
963  // -----------------------
968  return inverse(*this);
969  };
970 
971 public:
972 
977 
978  int nRows=A.getRowsNumber();
979  if (nRows==0) return true;
980 
981  LAP_IntegerVector ipiv;
982  ipiv.setSize(nRows);
983  if (!DoublePackedSymmetricMatrixBunchKaufmanFactorization(nRows,&A(0,0),&ipiv(0))) return false;
984 
985  return DoublePackedSymmetricMatrixInverse(nRows,&ipiv(0),&A(0,0));
986 
987  };
988 
989 private:
993  static SP::LAP_DoublePackedUpperMatrix choleskyFactorization(LAP_DoublePackedSymmetricMatrix& A) {
994 
995  tLVectorIndex nRows=A.getRowsNumber();
997  SP::LAP_DoublePackedUpperMatrix U=LAP_DoublePackedUpperMatrix::New();
998  SP::LAP_DoubleVector vs;
1000  if (succeeds) U->setValues(vs);
1001  return U;
1002  }
1003 public:
1004 
1008  virtual SP::LAP_DoubleUpperMatrix choleskyFactorization() {
1010  }
1011 
1012 
1013 };
1014 #endif
LAP_DoublePackedSymmetricMatrix & operator=(const LAP_DoubleMatrix &s)
init all the matrix to s
Definition: LAP_DoublePackedSymmetricMatrix.h:116
void matrixProduct(const LAP_DoubleFullGeneralMatrix &B, LAP_DoubleFullGeneralMatrix &C) const
return C=(This) . B
Definition: LAP_DoublePackedSymmetricMatrix.h:652
LAP_DoublePackedSymmetricMatrix & operator/=(const lapack_real &s)
divide by s the matrix v
Definition: LAP_DoublePackedSymmetricMatrix.h:139
virtual tBoolean computeEigenValues(LAP_DoubleVector &U) const
compute the eigen values of This: A is copied in ascending order
Definition: LAP_DoublePackedSymmetricMatrix.h:870
this class describes the exceptions raised for LAP package
Definition: LAP_Exception.h:14
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
static SP::LAP_DoubleFullGeneralMatrix New()
Definition: LAP_DoubleFullGeneralMatrix.h:78
double get(const tLVectorIndex &i, const tLVectorIndex &j) const
get the value taking into account the view
Definition: LAP_DoubleMatrix.h:172
virtual void dotProduct(const LAP_DoubleVector &v)
compute the symmetric matrix S= X.tX only the upper symmetric matric is set. (lapack method dsyr call...
Definition: LAP_DoublePackedSymmetricMatrix.h:483
this class describes a general double symmetric matrix
Definition: LAP_DoubleSymmetricMatrix.h:21
void DoublePackedSymmetricMatrixRankSymmetricProduct(const tLVectorIncrement &incX, const double *X, const double &alpha, const tLVectorIndex &nSRows, double *S)
compute the symmetric matrix S+=alpha X tX
Definition: dpackedsymmatrix_functions.cpp:287
this class describes a packed storage by column
Definition: LAP_DoublePackedStorage.h:21
Definition: LAP_IntegerVector.h:18
tLVectorIncrement getRowIncrement() const
get the memory distance between (*this)(i,j) & (*this)(i+1,j)
Definition: LAP_DoubleFullGeneralMatrix.h:346
LAP_DoublePackedSymmetricMatrix & operator-=(const LAP_DoublePackedSymmetricMatrix &s)
sub the viewed matrix
Definition: LAP_DoublePackedSymmetricMatrix.h:177
virtual void setValuesPointer(SP::LAP_DoubleVector v)
set the vector values by reference
Definition: LAP_DoubleMatrixStorage.h:132
virtual void matrixProduct(const tBoolean &leftSide, const LAP_DoubleFullGeneralMatrix &B, const lapack_real &alpha, const lapack_real &beta, LAP_DoubleFullGeneralMatrix &C) const
make the product if (leftSide) C = alpha. This . B +beta C if (!leftSide) C = alpha. B . This +beta C
Definition: LAP_DoublePackedSymmetricMatrix.h:663
LAP_DoublePackedSymmetricMatrix & operator/=(const LAP_DoublePackedSymmetricMatrix &s)
divide the viewed matrices term by term
Definition: LAP_DoublePackedSymmetricMatrix.h:170
virtual tBoolean copy(const LAP_DoubleMatrix &x)
copy a matrix
Definition: LAP_DoubleMatrix.cpp:18
virtual void matrixProduct(const tBoolean &leftSide, const tLVectorIndex &nBRows, const tLVectorIndex &nBCols, const tLVectorIncrement &incB, const tLVectorIndex &ldB, const double *B, const lapack_real &alpha, const lapack_real &beta, LAP_DoubleFullGeneralMatrix &C) const
make the product:
Definition: LAP_DoublePackedSymmetricMatrix.h:685
void matrixProduct(const LAP_DoublePackedSymmetricMatrix &B, LAP_DoubleFullGeneralMatrix &C) const
return C=(This) . B
Definition: LAP_DoublePackedSymmetricMatrix.h:644
Definition: LAP_DoubleVector.h:20
#define lapack_int
Definition: lapack_functions.h:7
Definition: LAP_DoubleMatrix.h:18
LAP_DoublePackedSymmetricMatrix()
build a matrix
Definition: LAP_DoublePackedSymmetricMatrix.cpp:11
virtual void rankSymmetricProduct(const LAP_DoubleVector &D, const double &alpha, const double &beta, const tBoolean &isTrans, const LAP_DoubleFullGeneralMatrix &A)
compute the symmetric matrix S:=beta.S+ alpha op(A).D.t(op(A))
Definition: LAP_DoublePackedSymmetricMatrix.h:585
LAP_DoublePackedSymmetricMatrix & operator+=(const LAP_DoublePackedSymmetricMatrix &s)
add the viewed matrix
Definition: LAP_DoublePackedSymmetricMatrix.h:183
virtual SP::LAP_DoubleMatrix NewInstance() const
create a New instance of this
Definition: LAP_DoublePackedSymmetricMatrix.h:80
virtual void setSize(const tLVectorIndex &n, const tLVectorIndex &p)
set the dimension of the matrix n x p
Definition: LAP_Matrix.h:87
virtual void vectorProduct(const LAP_ConstDoubleVector &X, const lapack_real &alpha, const lapack_real &beta, LAP_DoubleVector &Y) const
compute Y:=betaY+alpha.This.X
Definition: LAP_DoublePackedSymmetricMatrix.h:391
LAP_DoublePackedSymmetricMatrix & operator*=(const lapack_real &s)
multiply by s the matrix
Definition: LAP_DoublePackedSymmetricMatrix.h:133
tLVectorIndex getSize() const
get the size of the vector
Definition: LAP_ConstVector.h:170
#define tBoolean
Definition: types.h:48
LAP_DoublePackedSymmetricMatrix & operator=(const double &s)
init all the matrix to s
Definition: LAP_DoublePackedSymmetricMatrix.h:110
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
virtual void getColumn(const tLVectorIndex &j, SP::LAP_DoubleVector v) const
get the j-th column of this symmetric matrix in a vector
Definition: LAP_DoublePackedSymmetricMatrix.h:285
#define lapack_real
Definition: lapack_functions.h:9
virtual tLVectorIndex getRowsNumber() const
get the lines number of the matrix from view
Definition: LAP_DoubleFullGeneralMatrix.h:366
const LAP_DoublePackedStorage & getPackedStorage() const
get the banded storage
Definition: LAP_DoublePackedSymmetricMatrix.h:275
virtual void getColumn(const tLVectorIndex &j, LAP_DoubleVector &v) const
get the j-th column of this symmetric matrix in a vector
Definition: LAP_DoublePackedSymmetricMatrix.cpp:101
#define null
Definition: types.h:13
const tLVectorIncrement & getIncrement() const
get the increment of the vector
Definition: LAP_Vector.h:529
static tBoolean computeEigenValues(LAP_DoublePackedSymmetricMatrix &A, LAP_DoubleVector &U)
compute the eigen values of A in ascending order and A is destroyed after method lapack method dsyev ...
Definition: LAP_DoublePackedSymmetricMatrix.h:877
virtual SP::LAP_DoubleMatrix matrixProduct(const LAP_DoubleMatrix &B) const
return C=(This) . B
Definition: LAP_DoublePackedSymmetricMatrix.h:627
virtual void setSize(const tLVectorIndex &n)
set the dimension of the matrix
Definition: LAP_DoublePackedSymmetricMatrix.h:226
void init(const double &v)
init the values
Definition: LAP_DoubleMatrixStorage.h:124
static tBoolean computeEigenValueDecomposition(LAP_DoublePackedSymmetricMatrix &A, LAP_DoubleVector &U, LAP_DoubleFullGeneralMatrix &Z, const lapack_int &il, const lapack_int &ul)
compute the eigen elements of A in ascending order . A is supposed to be symmetric, the eigen vectors are set in Z, A must be symmetric. only the eigen values & vectors are computed in index il and iu when the iegen values are ordering in an ascent order.
Definition: LAP_DoublePackedSymmetricMatrix.h:942
static tBoolean inverse(LAP_DoublePackedSymmetricMatrix &A)
inverse a symmetric matrix dsytrf & dsytri lapack methods called
Definition: LAP_DoublePackedSymmetricMatrix.h:976
virtual void setValuesNumber(const tLVectorIndex &n)
set the values number
Definition: LAP_DoubleMatrixStorage.h:155
LAP_DoublePackedStorage & getPackedStorage()
GET.
Definition: LAP_DoublePackedSymmetricMatrix.h:270
Definition: LAP_DoubleFullGeneralMatrix.h:30
void DoublePackedSymmetricMatrixVectorProduct(const tLVectorIndex &nX, const tLVectorIncrement &incX, const double *x, const tLVectorIndex &nRows, const double *A, const lapack_real &alpha, const lapack_real &beta, const tLVectorIndex &nY, const tLVectorIncrement &incY, double *y)
compute Y!=Beta.Y+alpha A.X
Definition: dpackedsymmatrix_functions.cpp:181
static tBoolean computeEigenValueDecomposition(LAP_DoublePackedSymmetricMatrix &A, LAP_DoubleVector &U, LAP_DoubleFullGeneralMatrix &W)
compute the eigen elements in ascending order of A the eigen vectors are set in A: A is destroyed IN ...
Definition: LAP_DoublePackedSymmetricMatrix.h:906
tLVectorIndex getSize() const
get the size of the vector
Definition: LAP_Vector.h:519
virtual void getValuesPointer(SP::LAP_DoubleVector &v)
Definition: LAP_DoubleMatrixStorage.h:208
tBoolean DoublePackedSymmetricMatrixBunchKaufmanFactorization(const tLVectorIndex &nRows, double *A, lapack_int *ipiv)
make the Bunch Kaufman factorization A=U.D.tU
Definition: dpackedsymmatrix_functions.cpp:977
static SP::LAP_DoublePackedSymmetricMatrix New(const tLVectorIndex &n)
Definition: LAP_DoublePackedSymmetricMatrix.h:73
tBoolean DoublePackedSymmetricMatrixEigenValues(const tLVectorIndex &nRowsA, double *A, const tLVectorIndex &nU, double *U, const tLVectorIndex &ldW, double *W)
compute all the eigen values or vectors (if W is not null or ldW<=1)
Definition: dpackedsymmatrix_functions.cpp:607
virtual void getRow(const tLVectorIndex &i, LAP_DoubleVector &v) const
get the i-th row in a vector
Definition: LAP_DoublePackedSymmetricMatrix.cpp:59
static SP::LAP_DoublePackedUpperMatrix New()
Definition: LAP_DoublePackedUpperMatrix.h:63
virtual ~LAP_DoublePackedSymmetricMatrix()
destroy a matrix
Definition: LAP_DoublePackedSymmetricMatrix.cpp:23
tBoolean DoublePackedSymmetricMatrixCholeskyFactorization(const tLVectorIndex &nRowsA, double *A)
make the cholesky factorization A=tU.U
Definition: dpackedsymmatrix_functions.cpp:906
static void matrixProduct(const tBoolean &leftSide, const LAP_DoublePackedSymmetricMatrix &S, const LAP_DoubleFullGeneralMatrix &B, const lapack_real &alpha, const lapack_real &beta, LAP_DoubleFullGeneralMatrix &C)
compute :
Definition: LAP_DoublePackedSymmetricMatrix.h:743
virtual void getRow(const tLVectorIndex &i, SP::LAP_DoubleVector v) const
get the i-th row in a vector
Definition: LAP_DoublePackedSymmetricMatrix.h:299
virtual void setSize(const tLVectorIndex &nRows, const tLVectorIndex &nCols)
set the dimension of the matrix
Definition: LAP_DoublePackedSymmetricMatrix.h:216
LAP_DoublePackedSymmetricMatrix & operator+=(const lapack_real &s)
add s to the upper matrix
Definition: LAP_DoublePackedSymmetricMatrix.h:146
void DoublePackedSymmetricMatrixKRankSymmetricProduct(const tLVectorIndex &nRowsA, const tLVectorIndex &nColsA, const tLVectorIncrement &incA, const tLVectorIndex &ldA, const tBoolean &isTransA, const double *A, const double &alpha, const double &beta, const tLVectorIndex &nD, const tLVectorIncrement &incD, const double *D, const tLVectorIndex &nS, double *S)
compute : S:=beta S+ alpha op(A) . D . top(A) If D is null D is supposed to be identity (fortran vers...
Definition: dpackedsymmatrix_functions.cpp:487
LAP_DoublePackedSymmetricMatrix & operator*=(const LAP_DoublePackedSymmetricMatrix &s)
multiply the viewed matrices term by term
Definition: LAP_DoublePackedSymmetricMatrix.h:164
LAP_DoublePackedSymmetricMatrix & operator^=(const lapack_real &s)
power by s the matrix v
Definition: LAP_DoublePackedSymmetricMatrix.h:126
void matrixProduct(const tBoolean &leftSide, const LAP_DoubleFullSymmetricMatrix &S, const lapack_real &alpha, const lapack_real &beta, LAP_DoubleFullGeneralMatrix &C) const
compute :
Definition: LAP_DoublePackedSymmetricMatrix.h:835
virtual tReal norm2() const
return norm2 sqrt(sum_ij(aij^2))=sqrt(tr(AtA));
Definition: LAP_DoublePackedSymmetricMatrix.cpp:198
virtual void vectorProduct(const tLVectorIndex &nx, const tLVectorIncrement &incx, const double *x, const lapack_real &alpha, const lapack_real &beta, const tLVectorIndex &ny, const tLVectorIncrement &incy, double *y) const
compute Y= betaY + alpha. This. X
Definition: LAP_DoublePackedSymmetricMatrix.h:451
void rankSymmetricProduct(const double &alpha, const tBoolean &isTrans, const LAP_DoubleFullGeneralMatrix &A)
compute the symmetric matrix S:=alpha op(A).t(op(A))
Definition: LAP_DoublePackedSymmetricMatrix.h:507
tBoolean computeEigenValueDecomposition(LAP_DoubleVector &U, LAP_DoubleFullGeneralMatrix &VR, const int &il, const int &iu) const
compute the eigen elements in ascending order of This supposed to be symmetric, the eigen vectors are...
Definition: LAP_DoublePackedSymmetricMatrix.h:925
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
virtual void setValues(const tLVectorIndex &n, const double *values)
set the values
Definition: LAP_DoublePackedSymmetricMatrix.h:254
this class describes a packed symmetric matrix for lapack used where values are stored in vector: {A(...
Definition: LAP_DoublePackedSymmetricMatrix.h:31
const tLVectorIncrement & getIncrement() const
get the increment of the vector
Definition: LAP_ConstVector.h:175
tLVectorIndex getLeadingDimension() const
get the memory distance between (*this)(i,j) & (*this)(i,j+1)
Definition: LAP_DoubleFullGeneralMatrix.h:351
tBoolean DoublePackedSymmetricMatrixBoundedEigenValues(const tLVectorIndex &nRowsA, double *A, const tLVectorIndex &nU, double *U, const tLVectorIndex &minIndex, const tLVectorIndex &maxIndex, const double &minBound, const double &maxBound, const tLVectorIndex &ldW, double *W)
compute the selected eigen values or vectors (if W is not null or ldW<=1) with
Definition: dpackedsymmatrix_functions.cpp:710
tBoolean DoublePackedSymmetricMatrixInverse(const tLVectorIndex &nRows, const lapack_int *ipiv, double *A)
inverse the pack symmetric matrix where is has ben Bunch Kaufman factorized
Definition: dpackedsymmatrix_functions.cpp:1073
virtual void vectorProduct(const LAP_DoubleVector &X, const lapack_real &alpha, const lapack_real &beta, LAP_DoubleVector &Y) const
compute Y:=betaY+alpha.This.X
Definition: LAP_DoublePackedSymmetricMatrix.h:356
virtual tLVectorIndex getColumnsNumber() const
get the columns number of the matrix from view
Definition: LAP_DoubleFullGeneralMatrix.h:371
virtual tReal sum(const tFlag &d, LAP_DoubleVector &s) const
make the sum among the direction if (d==ROW) sum all the columns of each row and size of s is the num...
Definition: LAP_DoublePackedSymmetricMatrix.cpp:233
virtual void rankSymmetricProduct(const double &alpha, const double &beta, const tBoolean &isTrans, const LAP_DoubleFullGeneralMatrix &A)
compute the symmetric matrix S:=beta.S+ alpha op(A).t(op(A)) only the upper symmetric matric is set...
Definition: LAP_DoublePackedSymmetricMatrix.h:515
virtual const double & operator()(const tLVectorIndex &i, const tLVectorIndex &j) const
accessor of element at row i and column j taking into account the view only use the upper diagonal ...
Definition: LAP_DoublePackedSymmetricMatrix.h:99
virtual tLVectorIndex getColumnsNumber() const
get the columns number of the matrix from view
Definition: LAP_Matrix.h:121
virtual void vectorProduct(const tBoolean &isTrans, const tLVectorIndex &nX, const tLVectorIncrement &incX, const double *X, const lapack_real &alpha, const lapack_real &beta, const tLVectorIndex &nY, const tLVectorIncrement &incY, double *Y) const
compute Y= op(This). X with op(A)=A or tA depending on isTrans value
Definition: LAP_DoublePackedSymmetricMatrix.h:432
#define tLVectorIncrement
Definition: lapack_types.h:16
DEFINE_SPTR(LAP_DoublePackedSymmetricMatrix)
void DoublePackedSymmetricMatrixMatrixProduct(const tBoolean &isLeftSide, const tLVectorIndex &nRowsS, const double *S, const tLVectorIndex &nRowsB, const tLVectorIndex &nColsB, const tLVectorIncrement &incB, const tLVectorIndex &ldB, const tBoolean &isBSymmetric, const tBoolean &isBFull, const double *B, const lapack_real &alpha, const lapack_real &beta, const tLVectorIndex &nRowsC, const tLVectorIndex &nColsC, const tLVectorIncrement &incC, const tLVectorIndex &ldC, double *C)
compute :
Definition: dpackedsymmatrix_functions.cpp:363
void rankSymmetricProduct(const LAP_DoubleVector &D, const double &alpha, const tBoolean &isTrans, const LAP_DoubleFullGeneralMatrix &A)
compute the symmetric matrix S:=alpha op(A).t(op(A))
Definition: LAP_DoublePackedSymmetricMatrix.h:570
virtual void setValues(SP::LAP_DoubleVector values)
set the values set the pointer values of the matrix to values
Definition: LAP_DoublePackedSymmetricMatrix.h:238
Definition: LAP_ConstDoubleVector.h:25
virtual void dotProduct(const double &alpha, const LAP_DoubleVector &X)
compute the symmetric matrix S:= alpha X.tX only the upper symmetric matric is set. (lapack method dsyr called)
Definition: LAP_DoublePackedSymmetricMatrix.h:490
virtual void rankSymmetricProduct(const double &alpha, const double &beta, const tLVectorIndex &nARows, const tLVectorIndex &nACols, const tLVectorIncrement &incA, const tLVectorIndex &ldA, const tBoolean &isTransA, const double *A)
compute the symmetric matrix S:=beta.S+ alpha op(A).t(op(A))
Definition: LAP_DoublePackedSymmetricMatrix.h:537
#define tReal
Definition: types.h:18
virtual tLVectorIndex getRowsNumber() const
get the lines number of the matrix from view
Definition: LAP_Matrix.h:116
void rankSymmetricProduct(const LAP_DoubleFullGeneralMatrix &A)
compute the symmetric matrix S:=alpha op(A).t(op(A))
Definition: LAP_DoublePackedSymmetricMatrix.h:502
virtual SP::LAP_DoubleVector vectorProduct(const LAP_DoubleVector &X) const
compute This. X
Definition: LAP_DoubleMatrix.h:328
virtual void vectorProduct(const LAP_DoubleVector &X, LAP_DoubleVector &Y)
compute Y=A.X
Definition: LAP_DoublePackedSymmetricMatrix.h:346
void resetView()
set the view of the vector to all the values
Definition: LAP_Vector.h:352
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
virtual void setValues(const tLVectorIndex &n, const double *values)
copy the values
Definition: LAP_DoubleMatrixStorage.h:145
void rankSymmetricProduct(const LAP_DoubleVector &D, const LAP_DoubleFullGeneralMatrix &A)
compute the symmetric matrix S:=alpha op(A).t(op(A))
Definition: LAP_DoublePackedSymmetricMatrix.h:565
#define ASSERT_IN(a)
Definition: types.h:96
static void matrixProduct(const tBoolean &leftSide, const LAP_DoublePackedSymmetricMatrix &S1, const LAP_DoublePackedSymmetricMatrix &S2, const lapack_real &alpha, const lapack_real &beta, LAP_DoubleFullGeneralMatrix &C)
compute :
Definition: LAP_DoublePackedSymmetricMatrix.h:787
virtual double & operator()(const tLVectorIndex &i, const tLVectorIndex &j)
accessor of element at row i and column j taking into account the view only use the upper diagonal ...
Definition: LAP_DoublePackedSymmetricMatrix.h:92
virtual SP::LAP_DoubleUpperMatrix choleskyFactorization()
compute the choleskey factorization of the full symmetric matrix A is modified such that the upper ma...
Definition: LAP_DoublePackedSymmetricMatrix.h:1008
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
LAP_DoublePackedSymmetricMatrix & operator-=(const lapack_real &s)
sub s to the upper matrix
Definition: LAP_DoublePackedSymmetricMatrix.h:154
#define tFlag
Definition: types.h:14
static SP::LAP_DoublePackedSymmetricMatrix New()
Definition: LAP_DoublePackedSymmetricMatrix.h:66
tBoolean inverse()
inverse the matrix
Definition: LAP_DoublePackedSymmetricMatrix.h:967