My Project
zgematrix-_zgematrix.hpp
1 //=============================================================================
3 inline zgematrix& zgematrix::operator=(const _zgematrix& mat)
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] zgematrix::operator=(const _zgematrix&)"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10  shallow_copy(mat);
11  return *this;
12 }
13 
17 
18 //=============================================================================
20 inline zgematrix& zgematrix::operator+=(const _zgematrix& mat)
21 {
22 #ifdef CPPL_VERBOSE
23  std::cerr << "# [MARK] zgematrix::operator+=(const _zgematrix&)"
24  << std::endl;
25 #endif//CPPL_VERBOSE
26 
27 #ifdef CPPL_DEBUG
28  if(N!=mat.N || M!=mat.M){
29  std::cerr << "[ERROR] zgematrix::operator+=(_zgematrix&)" << std::endl
30  << "These two matrises can not make a summation." << std::endl
31  << "Your input was (" << M << "x" << N << ") += ("
32  << mat.M << "x" << mat.N << ")." << std::endl;
33  exit(1);
34  }
35 #endif//CPPL_DEBUG
36 
37  for(long i=0; i<M*N; i++){ Array[i]+=mat.Array[i]; }
38 
39  mat.destroy();
40  return *this;
41 }
42 
43 //=============================================================================
45 inline zgematrix& zgematrix::operator-=(const _zgematrix& mat)
46 {
47 #ifdef CPPL_VERBOSE
48  std::cerr << "# [MARK] zgematrix::operator-=(const _zgematrix&)"
49  << std::endl;
50 #endif//CPPL_VERBOSE
51 
52 #ifdef CPPL_DEBUG
53  if(N!=mat.N || M!=mat.M){
54  std::cerr << "[ERROR] zgematrix::operator-=(_zgematrix&)" << 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 
64  mat.destroy();
65  return *this;
66 }
67 
68 //=============================================================================
70 inline zgematrix& zgematrix::operator*=(const _zgematrix& mat)
71 {
72 #ifdef CPPL_VERBOSE
73  std::cerr << "# [MARK] zgematrix::operator*=(const _zgematrix&)"
74  << std::endl;
75 #endif//CPPL_VERBOSE
76 
77 #ifdef CPPL_DEBUG
78  if(N!=mat.M){
79  std::cerr << "[ERROR] zgematrix::operator*=(_zgematrix&)" << std::endl
80  << "These two matrises can not make a product." << std::endl
81  << "Your input was (" << M << "x" << N << ") *= ("
82  << mat.M << "x" << mat.N << ")." << std::endl;
83  exit(1);
84  }
85 #endif//CPPL_DEBUG
86 
87  zgematrix newmat( M, mat.N );
88  zgemm_( 'N', 'N', M, mat.N, N, std::complex<double>(1.0,0.0), Array, M,
89  mat.Array, mat.M, std::complex<double>(0.0,0.0), newmat.array, M );
90 
91  swap(*this,newmat);
92  mat.destroy();
93  return *this;
94 }
95 
99 
100 //=============================================================================
102 inline _zgematrix operator+(const zgematrix& matA, const _zgematrix& matB)
103 {
104 #ifdef CPPL_VERBOSE
105  std::cerr << "# [MARK] operator+(const zgematrix&, const _zgematrix&)"
106  << std::endl;
107 #endif//CPPL_VERBOSE
108 
109 #ifdef CPPL_DEBUG
110  if(matA.N!=matB.N || matA.M!=matB.M){
111  std::cerr << "[ERROR] operator+(zgematrix&, _zgematrix&)" << std::endl
112  << "These two matrises can not make a summation." << std::endl
113  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
114  << matB.M << "x" << matB.N << ")." << std::endl;
115  exit(1);
116  }
117 #endif//CPPL_DEBUG
118 
119  for(long i=0; i<matA.M*matA.N; i++){ matB.Array[i] +=matA.Array[i]; }
120 
121  return matB;
122 }
123 
124 //=============================================================================
126 inline _zgematrix operator-(const zgematrix& matA, const _zgematrix& matB)
127 {
128 #ifdef CPPL_VERBOSE
129  std::cerr << "# [MARK] operator-(const zgematrix&, const _zgematrix&)"
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-(zgematrix&, _zgematrix&)" << 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  for(long i=0; i<matA.M*matA.N; i++){
144  matB.Array[i] =matA.Array[i]-matB.Array[i];
145  }
146 
147  return matB;
148 }
149 
150 //=============================================================================
152 inline _zgematrix operator*(const zgematrix& matA, const _zgematrix& matB)
153 {
154 #ifdef CPPL_VERBOSE
155  std::cerr << "# [MARK] operator*(const zgematrix&, const _zgematrix&)"
156  << std::endl;
157 #endif//CPPL_VERBOSE
158 
159 #ifdef CPPL_DEBUG
160  if(matA.N!=matB.M){
161  std::cerr << "[ERROR] operator*(zgematrix&, _zgematrix&)" << std::endl
162  << "These two matrises can not make a product." << std::endl
163  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
164  << matB.M << "x" << matB.N << ")." << std::endl;
165  exit(1);
166  }
167 #endif//CPPL_DEBUG
168 
169  zgematrix newmat( matA.M, matB.N );
170  zgemm_( 'N', 'N', matA.M, matB.N, matA.N, std::complex<double>(1.0,0.0),
171  matA.Array, matA.M, matB.Array, matB.M,
172  std::complex<double>(0.0,0.0), newmat.array, matA.M );
173 
174  matB.destroy();
175  return _(newmat);
176 }
void shallow_copy(const _zgematrix &)
Definition: zgematrix-misc.hpp:103
long N
matrix column size
Definition: _zgematrix.hpp:8
zgematrix & operator-=(const zgematrix &)
Definition: zgematrix-zgematrix.hpp:45
friend _zrovector operator-(const _zrovector &)
Definition: _zrovector-unary.hpp:15
zgematrix & operator=(const zgematrix &)
Definition: zgematrix-zgematrix.hpp:3
friend _zgematrix i(const zgematrix &)
Definition: zgematrix-calc.hpp:21
zgematrix & operator*=(const zgematrix &)
Definition: zgematrix-zgematrix.hpp:68
Complex Double-precision General Dence Matrix Class.
Definition: zgematrix.hpp:3
(DO NOT USE) Smart-temporary Complex Double-precision General Dence Matrix Class
Definition: _zgematrix.hpp:3
void destroy() const
Definition: _zgematrix-misc.hpp:3
std::complex< double > * Array
1D Array to store matrix data
Definition: _zgematrix.hpp:9
friend _zrovector operator*(const zrovector &, const zgematrix &)
Definition: zrovector-zgematrix.hpp:3
long M
matrix row size
Definition: _zgematrix.hpp:7
zgematrix & operator+=(const zgematrix &)
Definition: zgematrix-zgematrix.hpp:22
friend void swap(zgematrix &, zgematrix &)
Definition: zgematrix-misc.hpp:154
friend const _zrovector & operator+(const _zrovector &)
Definition: _zrovector-unary.hpp:3
std::complex< double > * Array
1D Array to store vector data
Definition: _zrovector.hpp:8