My Project
dgematrix-_dsymatrix.hpp
1 //=============================================================================
3 inline dgematrix& dgematrix::operator=(const _dsymatrix& mat)
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] dgematrix::operator=(const _dsymatrix&)"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10  clear();
11  mat.complete();
12 
13  M =mat.N;
14  N =mat.N;
15  Array =mat.Array;
16  Darray =mat.Darray;
17 
18  mat.Array=NULL;
19  mat.Darray=NULL;
20  return *this;
21 }
22 
26 
27 //=============================================================================
29 inline dgematrix& dgematrix::operator+=(const _dsymatrix& mat)
30 {
31 #ifdef CPPL_VERBOSE
32  std::cerr << "# [MARK] dgematrix::operator+=(const _dsymatrix&)"
33  << std::endl;
34 #endif//CPPL_VERBOSE
35 
36 #ifdef CPPL_DEBUG
37  if(N!=mat.N || M!=mat.N){
38  std::cerr << "[ERROR] dgematrix::operator+=(_dsymatrix&)" << std::endl
39  << "These two matrises can not make a summation." << std::endl
40  << "Your input was (" << M << "x" << N << ") += ("
41  << mat.N << "x" << mat.N << ")." << std::endl;
42  exit(1);
43  }
44 #endif//CPPL_DEBUG
45 
46  for(long i=0; i<M; i++){
47  for(long j=0; j<N; j++){
48  operator()(i,j) += mat(i,j);
49  }
50  }
51 
52  mat.destroy();
53  return *this;
54 }
55 
56 //=============================================================================
58 inline dgematrix& dgematrix::operator-=(const _dsymatrix& mat)
59 {
60 #ifdef CPPL_VERBOSE
61  std::cerr << "# [MARK] dgematrix::operator-=(const _dsymatrix&)"
62  << std::endl;
63 #endif//CPPL_VERBOSE
64 
65 #ifdef CPPL_DEBUG
66  if(N!=mat.N || M!=mat.N){
67  std::cerr << "[ERROR] dgematrix::operator-=(_dsymatrix&)" << std::endl
68  << "These two matrises can not make a sutraction." << std::endl
69  << "Your input was (" << M << "x" << N << ") -= ("
70  << mat.N << "x" << mat.N << ")." << std::endl;
71  exit(1);
72  }
73 #endif//CPPL_DEBUG
74 
75  for(long i=0; i<M;i++){
76  for(long j=0; j<N; j++){
77  operator()(i,j) -= mat(i,j);
78  }
79  }
80 
81  mat.destroy();
82  return *this;
83 }
84 
85 //=============================================================================
87 inline dgematrix& dgematrix::operator*=(const _dsymatrix& mat)
88 {
89 #ifdef CPPL_VERBOSE
90  std::cerr << "# [MARK] dgematrix::operator*=(const _dsymatrix&)"
91  << std::endl;
92 #endif//CPPL_VERBOSE
93 
94 #ifdef CPPL_DEBUG
95  if(N!=mat.N){
96  std::cerr << "[ERROR] dgematrix::operator*=(_dsymatrix&)" << std::endl
97  << "These two matrises can not make a product." << std::endl
98  << "Your input was (" << M << "x" << N << ") *= ("
99  << mat.N << "x" << mat.N << ")." << std::endl;
100  exit(1);
101  }
102 #endif//CPPL_DEBUG
103 
104  dgematrix newmat( M, mat.N );
105  dsymm_( 'R', 'L', mat.N, N, 1.0, mat.Array, mat.N,
106  Array, M, 0.0, newmat.Array, newmat.M );
107 
108  swap(*this,newmat);
109  mat.destroy();
110  return *this;
111 }
112 
116 
117 //=============================================================================
119 inline _dgematrix operator+(const dgematrix& matA, const _dsymatrix& matB)
120 {
121 #ifdef CPPL_VERBOSE
122  std::cerr << "# [MARK] operator+(const dgematrix&, const _dsymatrix&)"
123  << std::endl;
124 #endif//CPPL_VERBOSE
125 
126 #ifdef CPPL_DEBUG
127  if(matA.N!=matB.N || matA.M!=matB.N){
128  std::cerr << "[ERROR] operator+(dgematrix&, _dgematrix&)" << std::endl
129  << "These two matrises can not make a summation." << std::endl
130  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
131  << matB.N << "x" << matB.N << ")." << std::endl;
132  exit(1);
133  }
134 #endif//CPPL_DEBUG
135 
136  dgematrix newmat(matA);
137  for(long i=0; i<matA.M; i++){
138  for(long j=0; j<matA.N; j++){
139  newmat(i,j) += matB(i,j);
140  }
141  }
142 
143  matB.destroy();
144  return _(newmat);
145 }
146 
147 //=============================================================================
149 inline _dgematrix operator-(const dgematrix& matA, const _dsymatrix& matB)
150 {
151 #ifdef CPPL_VERBOSE
152  std::cerr << "# [MARK] operator-(const dgematrix&, const _dsymatrix&)"
153  << std::endl;
154 #endif//CPPL_VERBOSE
155 
156 #ifdef CPPL_DEBUG
157  if(matA.N!=matB.N || matA.M!=matB.N){
158  std::cerr << "[ERROR] operator-(dgematrix&, _dgematrix&)" << std::endl
159  << "These two matrises can not make a subtraction." << std::endl
160  << "Your input was (" << matA.M << "x" << matA.N << ") - ("
161  << matB.N << "x" << matB.N << ")." << std::endl;
162  exit(1);
163  }
164 #endif//CPPL_DEBUG
165 
166  dgematrix newmat(matA);
167  for(long i=0; i<matA.M; i++){
168  for(long j=0; j<matA.N; j++){
169  newmat(i,j) -= matB(i,j);
170  }
171  }
172 
173  matB.destroy();
174  return _(newmat);
175 }
176 
177 //=============================================================================
179 inline _dgematrix operator*(const dgematrix& matA, const _dsymatrix& matB)
180 {
181 #ifdef CPPL_VERBOSE
182  std::cerr << "# [MARK] operator*(const dgematrix&, const _dsymatrix&)"
183  << std::endl;
184 #endif//CPPL_VERBOSE
185 
186 #ifdef CPPL_DEBUG
187  if(matA.N!=matB.N){
188  std::cerr << "[ERROR] operator*(dgematrix&, _dgematrix&)" << std::endl
189  << "These two matrises can not make a product." << std::endl
190  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
191  << matB.N << "x" << matB.N << ")." << std::endl;
192  exit(1);
193  }
194 #endif//CPPL_DEBUG
195 
196  dgematrix newmat( matA.N, matB.N );
197  dsymm_( 'R', 'L', matB.N, matA.N, 1.0, matB.Array, matB.N,
198  matA.Array, matA.M, 0.0, newmat.Array, newmat.M );
199 
200  matB.destroy();
201  return _(newmat);
202 }
void clear()
Definition: dgematrix-misc.hpp:3
void destroy() const
Definition: _dsymatrix-misc.hpp:3
friend void swap(dgematrix &, dgematrix &)
Definition: dgematrix-misc.hpp:154
double * Array
1D Array to store vector data
Definition: _drovector.hpp:8
Real Double-precision General Dence Matrix Class.
Definition: dgematrix.hpp:3
double * Array
1D Array to store matrix data
Definition: _dsymatrix.hpp:8
dgematrix & operator=(const dgematrix &)
Definition: dgematrix-dgematrix.hpp:3
double ** Darray
array of pointers of column head addresses
Definition: _dsymatrix.hpp:9
dgematrix & operator*=(const dgematrix &)
Definition: dgematrix-dgematrix.hpp:68
friend _drovector operator-(const _drovector &)
Definition: _drovector-unary.hpp:15
(DO NOT USE) Smart-temporary Real Double-precision General Dence Matrix Class
Definition: _dgematrix.hpp:3
friend _drovector operator*(const drovector &, const dgematrix &)
Definition: drovector-dgematrix.hpp:3
long N
matrix column or row size
Definition: _dsymatrix.hpp:7
(DO NOT USE) Smart-temporary Real Double-precision Symmetric Matrix Class
Definition: _dsymatrix.hpp:3
void complete() const
Definition: _dsymatrix-misc.hpp:22
dgematrix & operator-=(const dgematrix &)
Definition: dgematrix-dgematrix.hpp:45
friend _dgematrix i(const dgematrix &)
Definition: dgematrix-calc.hpp:21
dgematrix & operator+=(const dgematrix &)
Definition: dgematrix-dgematrix.hpp:22
friend const _drovector & operator+(const _drovector &)
Definition: _drovector-unary.hpp:3
double & operator()(const long &, const long &)
Definition: dgematrix-io.hpp:3