CPPLapack
 All Classes Files Functions Variables Friends Pages
_dgematrix-calc.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! return transposed dgematrix */
3 inline _dgematrix t(const _dgematrix& mat)
4 {CPPL_VERBOSE_REPORT;
5  dgematrix newmat(mat.n,mat.m);
6 
7  for(CPPL_INT i=0; i<newmat.m; i++){
8  for(CPPL_INT j=0; j<newmat.n; j++){
9  newmat(i,j) =mat(j,i);
10  }
11  }
12 
13  mat.destroy();
14  return _(newmat);
15 }
16 
17 //=============================================================================
18 /*! return its inverse matrix */
19 inline _dgematrix i(const _dgematrix& mat)
20 {CPPL_VERBOSE_REPORT;
21 #ifdef CPPL_DEBUG
22  if(mat.m!=mat.n){
23  ERROR_REPORT;
24  std::cerr << "This matrix is not square and has no inverse matrix." << std::endl
25  << "Your input was (" << mat.m << "x" << mat.n << ")." << std::endl;
26  exit(1);
27  }
28 #endif//CPPL_DEBUG
29 
30  dgematrix mat_cp(mat);
31  dgematrix mat_inv(mat_cp.m,mat_cp.n);
32  mat_inv.identity();
33  mat_cp.dgesv(mat_inv);
34 
35  return _(mat_inv);
36 }
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////////////////
41 
42 //=============================================================================
43 /*! search the index of element having the largest absolute value
44  in 0-based numbering system */
45 inline void idamax(CPPL_INT& i, CPPL_INT& j, const _dgematrix& mat)
46 {CPPL_VERBOSE_REPORT;
47  CPPL_INT mn =mat.m*mat.n;
48  CPPL_INT inc =1;
49  CPPL_INT index =idamax_(&mn, mat.array, &inc) -1;
50  i =index%mat.m;
51  j =index/mat.m;
52 
53  mat.destroy();
54 }
55 
56 //=============================================================================
57 /*! return its largest absolute value */
58 inline double damax(const _dgematrix& mat)
59 {CPPL_VERBOSE_REPORT;
60  CPPL_INT mn =mat.m*mat.n;
61  CPPL_INT inc =1;
62  double val =mat.array[idamax_(&mn, mat.array, &inc) -1];
63 
64  mat.destroy();
65  return val;
66 }
_dgematrix t(const _dgematrix &mat)
dgematrix & identity()
CPPL_INT m
matrix row size
Definition: dgematrix.hpp:9
CPPL_INT n
matrix column size
Definition: dgematrix.hpp:10
Real Double-precision General Dence Matrix Class.
Definition: dgematrix.hpp:3
CPPL_INT dgesv(dgematrix &)
CPPL_INT m
matrix row size
Definition: _dgematrix.hpp:9
double * array
1D array to store matrix data
Definition: _dgematrix.hpp:11
(DO NOT USE) Smart-temporary Real Double-precision General Dence Matrix Class
Definition: _dgematrix.hpp:3
void idamax(CPPL_INT &i, CPPL_INT &j, const _dgematrix &mat)
CPPL_INT n
matrix column size
Definition: _dgematrix.hpp:10
_dgematrix i(const _dgematrix &mat)
void destroy() const
_dcovector _(dcovector &vec)
double damax(const _dgematrix &mat)