VERB_code_2.3
dgematrix-_dgematrix.hpp
1 //=============================================================================
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] dgematrix::operator=(const _dgematrix&)"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10 #ifdef CPPL_DEBUG
11  std::cerr << "# [NOTE] dgematrix::operator=(const _dgematrix&) was called."
12  << std::endl;
13 #endif//CPPL_DEBUG
14 
15  shallow_copy(mat);
16  return *this;
17 }
18 
22 
23 //=============================================================================
26 {
27 #ifdef CPPL_VERBOSE
28  std::cerr << "# [MARK] dgematrix::operator+=(const _dgematrix&)"
29  << std::endl;
30 #endif//CPPL_VERBOSE
31 
32 #ifdef CPPL_DEBUG
33  if(N!=mat.N || M!=mat.M){
34  std::cerr << "[ERROR] dgematrix::operator+=(_dgematrix&)" << std::endl
35  << "These two matrises can not make a summation." << std::endl
36  << "Your input was (" << M << "x" << N << ") += ("
37  << mat.M << "x" << mat.N << ")." << std::endl;
38  exit(1);
39  }
40 #endif//CPPL_DEBUG
41 
42  for(long i=0; i<M*N; i++){ Array[i]+=mat.Array[i]; }
43 
44  mat.destroy();
45  return *this;
46 }
47 
48 //=============================================================================
51 {
52 #ifdef CPPL_VERBOSE
53  std::cerr << "# [MARK] dgematrix::operator-=(const _dgematrix&)"
54  << std::endl;
55 #endif//CPPL_VERBOSE
56 
57 #ifdef CPPL_DEBUG
58  if(N!=mat.N || M!=mat.M){
59  std::cerr << "[ERROR] dgematrix::operator-=(_dgematrix&)" << std::endl
60  << "These two matrises can not make a sutraction." << std::endl
61  << "Your input was (" << M << "x" << N << ") -= ("
62  << mat.M << "x" << mat.N << ")." << std::endl;
63  exit(1);
64  }
65 #endif//CPPL_DEBUG
66 
67  for(long i=0; i<M*N; i++){ Array[i]-=mat.Array[i]; }
68 
69  mat.destroy();
70  return *this;
71 }
72 
73 //=============================================================================
76 {
77 #ifdef CPPL_VERBOSE
78  std::cerr << "# [MARK] dgematrix::operator*=(const _dgematrix&)"
79  << std::endl;
80 #endif//CPPL_VERBOSE
81 
82 #ifdef CPPL_DEBUG
83  if(N!=mat.M){
84  std::cerr << "[ERROR] dgematrix::operator*=(_dgematrix&)" << std::endl
85  << "These two matrises can not make a product." << std::endl
86  << "Your input was (" << M << "x" << N << ") *= ("
87  << mat.M << "x" << mat.N << ")." << std::endl;
88  exit(1);
89  }
90 #endif//CPPL_DEBUG
91 
92  dgematrix newmat( M, mat.N );
93  dgemm_( 'N', 'N', M, mat.N, N, 1.0, Array, M,
94  mat.Array, mat.M, 0.0, newmat.Array, M );
95 
96  swap(*this,newmat);
97  mat.destroy();
98  return *this;
99 }
100 
104 
105 //=============================================================================
107 inline _dgematrix operator+(const dgematrix& matA, const _dgematrix& matB)
108 {
109 #ifdef CPPL_VERBOSE
110  std::cerr << "# [MARK] operator+(const dgematrix&, const _dgematrix&)"
111  << std::endl;
112 #endif//CPPL_VERBOSE
113 
114 #ifdef CPPL_DEBUG
115  if(matA.N!=matB.N || matA.M!=matB.M){
116  std::cerr << "[ERROR] operator+(dgematrix&, _dgematrix&)" << std::endl
117  << "These two matrises can not make a summation." << std::endl
118  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
119  << matB.M << "x" << matB.N << ")." << std::endl;
120  exit(1);
121  }
122 #endif//CPPL_DEBUG
123 
124  for(long i=0; i<matA.M*matA.N; i++){ matB.Array[i] +=matA.Array[i]; }
125 
126  return matB;
127 }
128 
129 //=============================================================================
131 inline _dgematrix operator-(const dgematrix& matA, const _dgematrix& matB)
132 {
133 #ifdef CPPL_VERBOSE
134  std::cerr << "# [MARK] operator-(const dgematrix&, const _dgematrix&)"
135  << std::endl;
136 #endif//CPPL_VERBOSE
137 
138 #ifdef CPPL_DEBUG
139  if(matA.N!=matB.N || matA.M!=matB.M){
140  std::cerr << "[ERROR] operator-(dgematrix&, _dgematrix&)" << std::endl
141  << "These two matrises can not make a subtraction." << std::endl
142  << "Your input was (" << matA.M << "x" << matA.N << ") - ("
143  << matB.M << "x" << matB.N << ")." << std::endl;
144  exit(1);
145  }
146 #endif//CPPL_DEBUG
147 
148  for(long i=0; i<matA.M*matA.N; i++){
149  matB.Array[i] =matA.Array[i]-matB.Array[i];
150  }
151 
152  return matB;
153 }
154 
155 //=============================================================================
157 inline _dgematrix operator*(const dgematrix& matA, const _dgematrix& matB)
158 {
159 #ifdef CPPL_VERBOSE
160  std::cerr << "# [MARK] operator*(const dgematrix&, const _dgematrix&)"
161  << std::endl;
162 #endif//CPPL_VERBOSE
163 
164 #ifdef CPPL_DEBUG
165  if(matA.N!=matB.M){
166  std::cerr << "[ERROR] operator*(dgematrix&, _dgematrix&)" << std::endl
167  << "These two matrises can not make a product." << std::endl
168  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
169  << matB.M << "x" << matB.N << ")." << std::endl;
170  exit(1);
171  }
172 #endif//CPPL_DEBUG
173 
174  dgematrix newmat( matA.M, matB.N );
175  dgemm_( 'N', 'N', matA.M, matB.N, matA.N, 1.0, matA.Array, matA.M,
176  matB.Array, matB.M, 0.0, newmat.Array, matA.M );
177 
178  matB.destroy();
179  return _(newmat);
180 }
friend void swap(dgematrix &, dgematrix &)
Definition: dgematrix-misc.hpp:154
Real Double-precision General Dence Matrix Class.
Definition: dgematrix.hpp:3
dgematrix & operator=(const dgematrix &)
Definition: dgematrix-dgematrix.hpp:3
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
long N
matrix column size
Definition: _dgematrix.hpp:8
void shallow_copy(const _dgematrix &)
Definition: dgematrix-misc.hpp:103
double * Array
1D array to store matrix data
Definition: _dgematrix.hpp:9
friend _drovector operator*(const drovector &, const dgematrix &)
Definition: drovector-dgematrix.hpp:3
void destroy() const
Definition: _dgematrix-misc.hpp:3
dgematrix & operator-=(const dgematrix &)
Definition: dgematrix-dgematrix.hpp:45
friend _dgematrix i(const dgematrix &)
Definition: dgematrix-calc.hpp:21
double * Array
1D Array to store vector data
Definition: _drovector.hpp:8
dgematrix & operator+=(const dgematrix &)
Definition: dgematrix-dgematrix.hpp:22
friend const _drovector & operator+(const _drovector &)
Definition: _drovector-unary.hpp:3
long M
matrix row size
Definition: _dgematrix.hpp:7