CPPLapack
 All Classes Files Functions Variables Friends Pages
dsymatrix-calc.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! return transposed dgematrix */
3 inline _dsymatrix t(const dsymatrix& mat)
4 {CPPL_VERBOSE_REPORT;
5 #ifdef CPPL_DEBUG
6  WARNING_REPORT;
7  std::cerr << "This function call has no effect since the matrix is symmetric." << std::endl;
8 #endif//CPPL_DEBUG
9 
10  dsymatrix newmat(mat);
11  return _(newmat);
12 }
13 
14 //=============================================================================
15 /*! return its inverse matrix */
16 inline _dsymatrix i(const dsymatrix& mat)
17 {CPPL_VERBOSE_REPORT;
18  dsymatrix mat_cp =mat;
19  dsymatrix mat_inv(mat.n);
20  mat_inv.identity();
21  mat_inv.complete();
22 
23  char UPLO('l');
24  CPPL_INT NRHS(mat.n), LDA(mat.n), *IPIV(new CPPL_INT[mat.n]), LDB(mat.n), LWORK(-1), INFO(1);
25  double *WORK( new double[1] );
26  dsysv_(&UPLO, &mat.n, &NRHS, mat_cp.array, &LDA, IPIV, mat_inv.array, &LDB, WORK, &LWORK, &INFO);
27 
28  LWORK = CPPL_INT(WORK[0]);
29  delete [] WORK;
30  WORK = new double[LWORK];
31  dsysv_(&UPLO, &mat.n, &NRHS, mat_cp.array, &LDA, IPIV, mat_inv.array, &LDB, WORK, &LWORK, &INFO);
32 
33  delete [] WORK;
34  delete [] IPIV;
35  if(INFO!=0){
36  WARNING_REPORT;
37  std::cerr << "Serious trouble happend. INFO = " << INFO << "." << std::endl;
38  }
39 
40  return _(mat_inv);
41 }
42 
43 ///////////////////////////////////////////////////////////////////////////////
44 ///////////////////////////////////////////////////////////////////////////////
45 ///////////////////////////////////////////////////////////////////////////////
46 
47 //=============================================================================
48 /*! search the index of element having the largest absolute value in 0-based numbering system */
49 inline void idamax(CPPL_INT& i, CPPL_INT& j, const dsymatrix& mat)
50 {CPPL_VERBOSE_REPORT;
51  i=j=0;
52  double val =0.;
53 
54  for(CPPL_INT J=0; J<mat.n; J++){
55  for(CPPL_INT I=J; I<mat.n; I++){
56  if(val<fabs(mat.darray[J][I]) ){
57  val =fabs(mat.darray[J][I]);
58  i=I;
59  j=J;
60  }
61  }
62  }
63 }
64 
65 //=============================================================================
66 /*! return its largest absolute value */
67 inline double damax(const dsymatrix& mat)
68 {CPPL_VERBOSE_REPORT;
69  CPPL_INT i,j;
70  idamax(i, j, mat);
71  return mat(i,j);
72 }
_dsymatrix i(const dsymatrix &mat)
_dsymatrix t(const dsymatrix &mat)
void idamax(CPPL_INT &i, CPPL_INT &j, const dsymatrix &mat)
Real Double-precision Symmetric Matrix Class [l-type (UPLO=l) Strage].
Definition: dsymatrix.hpp:3
dsymatrix & identity()
CPPL_INT n
matrix column size
Definition: dsymatrix.hpp:10
(DO NOT USE) Smart-temporary Real Double-precision Symmetric Matrix Class
Definition: _dsymatrix.hpp:3
void complete() const
double damax(const dsymatrix &mat)
double * array
1D array to store matrix data
Definition: dsymatrix.hpp:11
double ** darray
array of pointers of column head addresses
Definition: dsymatrix.hpp:12
_dcovector _(dcovector &vec)