My Project
_dgematrix-calc.hpp
1 //=============================================================================
3 inline _dgematrix t(const _dgematrix& mat)
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] t(const _dgematrix&)"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10  dgematrix newmat(mat.N,mat.M);
11 
12  for(long i=0; i<newmat.m; i++){ for(long j=0; j<newmat.n; j++){
13  newmat(i,j) =mat(j,i);
14  }}
15 
16  mat.destroy();
17  return _(newmat);
18 }
19 
20 //=============================================================================
22 inline _dgematrix i(const _dgematrix& mat)
23 {
24 #ifdef CPPL_VERBOSE
25  std::cerr << "# [MARK] i(const _dgematrix&)"
26  << std::endl;
27 #endif//CPPL_VERBOSE
28 
29 #ifdef CPPL_DEBUG
30  if(mat.M!=mat.N){
31  std::cerr << "[ERROR] i(_dgematrix&) " << std::endl
32  << "This matrix is not square and has no inverse matrix."
33  << std::endl
34  << "Your input was (" << mat.M << "x" << mat.N << ")."
35  << std::endl;
36  exit(1);
37  }
38 #endif//CPPL_DEBUG
39  dgematrix mat_cp;
40  mat_cp.shallow_copy(mat);
41 
42  dgematrix mat_inv(mat.M,mat.N);
43  mat_inv.identity();
44  mat_cp.dgesv(mat_inv);
45 
46  return _(mat_inv);
47 }
48 
52 
53 //=============================================================================
56 inline void idamax(long& i, long& j, const _dgematrix& mat)
57 {
58 #ifdef CPPL_VERBOSE
59  std::cerr << "# [MARK] idamax(long&, long&, const _dgematrix&)"
60  << std::endl;
61 #endif//CPPL_VERBOSE
62 
63  long index( idamax_(mat.M*mat.N, mat.Array, 1) -1 );
64  i =index%mat.M;
65  j =index/mat.M;
66 
67  mat.destroy();
68 }
69 
70 //=============================================================================
72 inline double damax(const _dgematrix& mat)
73 {
74 #ifdef CPPL_VERBOSE
75  std::cerr << "# [MARK] damax(const _dgematrix&)"
76  << std::endl;
77 #endif//CPPL_VERBOSE
78 
79  double val( mat.Array[idamax_(mat.M*mat.N, mat.Array, 1) -1] );
80 
81  mat.destroy();
82  return val;
83 }
friend double damax(const drovector &)
Definition: drovector-calc.hpp:43
long const & n
matrix column size (readable)
Definition: dgematrix.hpp:15
Real Double-precision General Dence Matrix Class.
Definition: dgematrix.hpp:3
long dgesv(dgematrix &)
Definition: dgematrix-lapack.hpp:6
(DO NOT USE) Smart-temporary Real Double-precision General Dence Matrix Class
Definition: _dgematrix.hpp:3
void identity()
Definition: dgematrix-misc.hpp:38
long N
matrix column size
Definition: _dgematrix.hpp:8
friend _dcovector t(const drovector &)
Definition: drovector-calc.hpp:3
void shallow_copy(const _dgematrix &)
Definition: dgematrix-misc.hpp:103
long const & m
matrix row size (readable)
Definition: dgematrix.hpp:14
double * Array
1D array to store matrix data
Definition: _dgematrix.hpp:9
void destroy() const
Definition: _dgematrix-misc.hpp:3
friend long idamax(const drovector &)
Definition: drovector-calc.hpp:31
long M
matrix row size
Definition: _dgematrix.hpp:7