My Project
dgematrix-dgematrix.hpp
1 //=============================================================================
3 inline dgematrix& dgematrix::operator=(const dgematrix& mat)
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] dgematrix::operator=(const dgematrix&)"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10  if(Array!=mat.Array){ // if it is NOT self substitution
11  copy(mat);
12  }
13  return *this;
14 }
15 
19 
20 //=============================================================================
22 inline dgematrix& dgematrix::operator+=(const dgematrix& mat)
23 {
24 #ifdef CPPL_VERBOSE
25  std::cerr << "# [MARK] dgematrix::operator+=(const dgematrix&)"
26  << std::endl;
27 #endif//CPPL_VERBOSE
28 
29 #ifdef CPPL_DEBUG
30  if(N!=mat.N || M!=mat.M){
31  std::cerr << "[ERROR] dgematrix::operator+=(dgematrix&)" << std::endl
32  << "These two matrises can not make a summation." << std::endl
33  << "Your input was (" << M << "x" << N << ") += ("
34  << mat.M << "x" << mat.N << ")." << std::endl;
35  exit(1);
36  }
37 #endif//CPPL_DEBUG
38 
39  for(long i=0; i<M*N; i++){ Array[i]+=mat.Array[i]; }
40  return *this;
41 }
42 
43 //=============================================================================
45 inline dgematrix& dgematrix::operator-=(const dgematrix& mat)
46 {
47 #ifdef CPPL_VERBOSE
48  std::cerr << "# [MARK] dgematrix::operator-=(const dgematrix&)"
49  << std::endl;
50 #endif//CPPL_VERBOSE
51 
52 #ifdef CPPL_DEBUG
53  if(N!=mat.N || M!=mat.M){
54  std::cerr << "[ERROR] dgematrix::operator-=(dgematrix&)" << std::endl
55  << "These two matrises can not make a sutraction." << std::endl
56  << "Your input was (" << M << "x" << N << ") -= ("
57  << mat.M << "x" << mat.N << ")." << std::endl;
58  exit(1);
59  }
60 #endif//CPPL_DEBUG
61 
62  for(long i=0; i<M*N; i++){ Array[i]-=mat.Array[i]; }
63  return *this;
64 }
65 
66 //=============================================================================
68 inline dgematrix& dgematrix::operator*=(const dgematrix& mat)
69 {
70 #ifdef CPPL_VERBOSE
71  std::cerr << "# [MARK] dgematrix::operator*=(const dgematrix&)"
72  << std::endl;
73 #endif//CPPL_VERBOSE
74 
75 #ifdef CPPL_DEBUG
76  if(N!=mat.M){
77  std::cerr << "[ERROR] dgematrix::operator*=(dgematrix&)" << std::endl
78  << "These two matrises can not make a product." << std::endl
79  << "Your input was (" << M << "x" << N << ") *= ("
80  << mat.M << "x" << mat.N << ")." << std::endl;
81  exit(1);
82  }
83 #endif//CPPL_DEBUG
84 
85  dgematrix newmat( M, mat.N );
86  dgemm_( 'N', 'N', M, mat.N, N, 1.0, Array, M,
87  mat.Array, mat.M, 0.0, newmat.Array, M );
88 
89  swap(*this,newmat);
90  return *this;
91 }
92 
96 
97 //=============================================================================
99 inline _dgematrix operator+(const dgematrix& matA, const dgematrix& matB)
100 {
101 #ifdef CPPL_VERBOSE
102  std::cerr << "# [MARK] operator+(const dgematrix&, const dgematrix&)"
103  << std::endl;
104 #endif//CPPL_VERBOSE
105 
106 #ifdef CPPL_DEBUG
107  if(matA.N!=matB.N || matA.M!=matB.M){
108  std::cerr << "[ERROR] operator+(dgematrix&, dgematrix&)" << std::endl
109  << "These two matrises can not make a summation." << std::endl
110  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
111  << matB.M << "x" << matB.N << ")." << std::endl;
112  exit(1);
113  }
114 #endif//CPPL_DEBUG
115 
116  dgematrix newmat(matA.M,matA.N);
117  for(long i=0; i<newmat.M*newmat.N; i++){
118  newmat.Array[i] =matA.Array[i]+matB.Array[i];
119  }
120 
121  return _(newmat);
122 }
123 
124 //=============================================================================
126 inline _dgematrix operator-(const dgematrix& matA, const dgematrix& matB)
127 {
128 #ifdef CPPL_VERBOSE
129  std::cerr << "# [MARK] operator-(const dgematrix&, const dgematrix&)"
130  << std::endl;
131 #endif//CPPL_VERBOSE
132 
133 #ifdef CPPL_DEBUG
134  if(matA.N!=matB.N || matA.M!=matB.M){
135  std::cerr << "[ERROR] operator-(dgematrix&, dgematrix&)" << std::endl
136  << "These two matrises can not make a subtraction." << std::endl
137  << "Your input was (" << matA.M << "x" << matA.N << ") - ("
138  << matB.M << "x" << matB.N << ")." << std::endl;
139  exit(1);
140  }
141 #endif//CPPL_DEBUG
142 
143  dgematrix newmat(matA.M,matA.N);
144  for(long i=0; i<newmat.M*newmat.N; i++){
145  newmat.Array[i] =matA.Array[i]-matB.Array[i];
146  }
147 
148  return _(newmat);
149 }
150 
151 //=============================================================================
153 inline _dgematrix operator*(const dgematrix& matA, const dgematrix& matB)
154 {
155 #ifdef CPPL_VERBOSE
156  std::cerr << "# [MARK] operator*(const dgematrix&, const dgematrix&)"
157  << std::endl;
158 #endif//CPPL_VERBOSE
159 
160 #ifdef CPPL_DEBUG
161  if(matA.N!=matB.M){
162  std::cerr << "[ERROR] operator*(dgematrix&, dgematrix&)" << std::endl
163  << "These two matrises can not make a product." << std::endl
164  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
165  << matB.M << "x" << matB.N << ")." << std::endl;
166  exit(1);
167  }
168 #endif//CPPL_DEBUG
169 
170  dgematrix newmat( matA.M, matB.N );
171  dgemm_( 'N', 'N', matA.M, matB.N, matA.N, 1.0, matA.Array, matA.M,
172  matB.Array, matB.M, 0.0, newmat.Array, matA.M );
173 
174  return _(newmat);
175 }
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
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
void copy(const dgematrix &)
Definition: dgematrix-misc.hpp:72
friend _drovector operator*(const drovector &, const dgematrix &)
Definition: drovector-dgematrix.hpp:3
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