My Project
zgematrix-_zhematrix.hpp
1 //=============================================================================
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] zgematrix::operator=(const _zhematrix&)"
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 //=============================================================================
30 {
31 #ifdef CPPL_VERBOSE
32  std::cerr << "# [MARK] zgematrix::operator+=(const _zhematrix&)"
33  << std::endl;
34 #endif//CPPL_VERBOSE
35 
36 #ifdef CPPL_DEBUG
37  if(N!=mat.N || M!=mat.N){
38  std::cerr << "[ERROR] zgematrix::operator+=(_zhematrix&)" << 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++){ for(long j=0; j<N; j++){
47  operator()(i,j) +=mat(i,j);
48  }}
49 
50  mat.destroy();
51  return *this;
52 }
53 
54 //=============================================================================
57 {
58 #ifdef CPPL_VERBOSE
59  std::cerr << "# [MARK] zgematrix::operator-=(const _zhematrix&)"
60  << std::endl;
61 #endif//CPPL_VERBOSE
62 
63 #ifdef CPPL_DEBUG
64  if(N!=mat.N || M!=mat.N){
65  std::cerr << "[ERROR] zgematrix::operator-=(_zhematrix&)" << std::endl
66  << "These two matrises can not make a sutraction." << std::endl
67  << "Your input was (" << M << "x" << N << ") -= ("
68  << mat.N << "x" << mat.N << ")." << std::endl;
69  exit(1);
70  }
71 #endif//CPPL_DEBUG
72 
73  for(long i=0; i<M; i++){ for(long j=0; j<N; j++){
74  operator()(i,j) -=mat(i,j);
75  }}
76 
77  mat.destroy();
78  return *this;
79 }
80 
81 //=============================================================================
84 {
85 #ifdef CPPL_VERBOSE
86  std::cerr << "# [MARK] zgematrix::operator*=(const _zhematrix&)"
87  << std::endl;
88 #endif//CPPL_VERBOSE
89 
90 #ifdef CPPL_DEBUG
91  if(N!=mat.N){
92  std::cerr << "[ERROR] zgematrix::operator*=(_zhematrix&)" << std::endl
93  << "These two matrises can not make a product." << std::endl
94  << "Your input was (" << M << "x" << N << ") *= ("
95  << mat.N << "x" << mat.N << ")." << std::endl;
96  exit(1);
97  }
98 #endif//CPPL_DEBUG
99 
100  zgematrix newmat( M, mat.N );
101 
102  zhemm_( 'R', 'L', mat.N, N, std::complex<double>(1.0,0.0), mat.Array, mat.N,
103  Array, M, std::complex<double>(0.0,0.0), newmat.array, newmat.m );
104 
105  swap(*this,newmat);
106  mat.destroy();
107  return *this;
108 }
109 
113 
114 //=============================================================================
116 inline _zgematrix operator+(const zgematrix& matA, const _zhematrix& matB)
117 {
118 #ifdef CPPL_VERBOSE
119  std::cerr << "# [MARK] operator+(const zgematrix&, const _zhematrix&)"
120  << std::endl;
121 #endif//CPPL_VERBOSE
122 
123 #ifdef CPPL_DEBUG
124  if(matA.N!=matB.N || matA.M!=matB.N){
125  std::cerr << "[ERROR] operator+(zgematrix&, _zgematrix&)" << std::endl
126  << "These two matrises can not make a summation." << std::endl
127  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
128  << matB.N << "x" << matB.N << ")." << std::endl;
129  exit(1);
130  }
131 #endif//CPPL_DEBUG
132 
133  zgematrix newmat(matA);
134  for(long i=0; i<matA.M; i++){ for(long j=0; j<matA.N; j++){
135  newmat(i,j) +=matB(i,j);
136  }}
137 
138  matB.destroy();
139  return _(newmat);
140 }
141 
142 //=============================================================================
144 inline _zgematrix operator-(const zgematrix& matA, const _zhematrix& matB)
145 {
146 #ifdef CPPL_VERBOSE
147  std::cerr << "# [MARK] operator-(const zgematrix&, const _zhematrix&)"
148  << std::endl;
149 #endif//CPPL_VERBOSE
150 
151 #ifdef CPPL_DEBUG
152  if(matA.N!=matB.N || matA.M!=matB.N){
153  std::cerr << "[ERROR] operator-(zgematrix&, _zgematrix&)" << std::endl
154  << "These two matrises can not make a subtraction." << std::endl
155  << "Your input was (" << matA.M << "x" << matA.N << ") - ("
156  << matB.N << "x" << matB.N << ")." << std::endl;
157  exit(1);
158  }
159 #endif//CPPL_DEBUG
160 
161  zgematrix newmat(matA);
162  for(long i=0; i<matA.M; i++){ for(long j=0; j<matA.N; j++){
163  newmat(i,j) -=matB(i,j);
164  }}
165 
166  matB.destroy();
167  return _(newmat);
168 }
169 
170 //=============================================================================
172 inline _zgematrix operator*(const zgematrix& matA, const _zhematrix& matB)
173 {
174 #ifdef CPPL_VERBOSE
175  std::cerr << "# [MARK] operator*(const zgematrix&, const _zhematrix&)"
176  << std::endl;
177 #endif//CPPL_VERBOSE
178 
179 #ifdef CPPL_DEBUG
180  if(matA.N!=matB.N){
181  std::cerr << "[ERROR] operator*(zgematrix&, _zgematrix&)" << std::endl
182  << "These two matrises can not make a product." << std::endl
183  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
184  << matB.N << "x" << matB.N << ")." << std::endl;
185  exit(1);
186  }
187 #endif//CPPL_DEBUG
188 
189  zgematrix newmat( matA.N, matB.N );
190 
191  zhemm_( 'R', 'L', matB.N, matA.N, std::complex<double>(1.0,0.0),
192  matB.Array, matB.N, matA.Array, matA.M,
193  std::complex<double>(0.0,0.0), newmat.array, newmat.m );
194 
195  matB.destroy();
196  return _(newmat);
197 }
std::complex< double > ** Darray
array of pointers of column head addresses
Definition: _zhematrix.hpp:9
std::complex< double > *const & array
1D array to store matrix data (readable)
Definition: zgematrix.hpp:16
(DO NOT USE) Smart-temporary Complex Double-precision Hermitian Matrix Class
Definition: _zhematrix.hpp:3
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 complete() const
Definition: _zhematrix-misc.hpp:22
void clear()
Definition: zgematrix-misc.hpp:3
void destroy() const
Definition: _zhematrix-misc.hpp:3
std::complex< double > * Array
1D Array to store matrix data
Definition: _zhematrix.hpp:8
std::complex< double > & operator()(const long &, const long &)
Definition: zgematrix-io.hpp:3
friend _zrovector operator*(const zrovector &, const zgematrix &)
Definition: zrovector-zgematrix.hpp:3
long const & m
matrix row size (readable)
Definition: zgematrix.hpp:14
zgematrix & operator+=(const zgematrix &)
Definition: zgematrix-zgematrix.hpp:22
friend void swap(zgematrix &, zgematrix &)
Definition: zgematrix-misc.hpp:154
long N
matrix column or row size
Definition: _zhematrix.hpp:7
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