My Project
zhematrix-zhematrix.hpp
1 //=============================================================================
3 inline zhematrix& zhematrix::operator=(const zhematrix& mat)
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] zhematrix::operator=(const zhematrix&)"
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 zhematrix& zhematrix::operator+=(const zhematrix& mat)
23 {
24 #ifdef CPPL_VERBOSE
25  std::cerr << "# [MARK] zhematrix::operator+=(const zhematrix&)"
26  << std::endl;
27 #endif//CPPL_VERBOSE
28 
29 #ifdef CPPL_DEBUG
30  if(N!=mat.N){
31  std::cerr << "[ERROR] zhematrix::operator+=(zhematrix&)" << std::endl
32  << "These two matrises can not make a summation." << std::endl
33  << "Your input was (" << N << "x" << N << ") += ("
34  << mat.N << "x" << mat.N << ")." << std::endl;
35  exit(1);
36  }
37 #endif//CPPL_DEBUG
38 
39  for(long i=0; i<N; i++){ for(long j=0; j<=i; j++){
40  operator()(i,j) +=mat(i,j);
41  }}
42 
43  return *this;
44 }
45 
46 //=============================================================================
48 inline zhematrix& zhematrix::operator-=(const zhematrix& mat)
49 {
50 #ifdef CPPL_VERBOSE
51  std::cerr << "# [MARK] zhematrix::operator-=(const zhematrix&)"
52  << std::endl;
53 #endif//CPPL_VERBOSE
54 
55 #ifdef CPPL_DEBUG
56  if(N!=mat.N){
57  std::cerr << "[ERROR] zhematrix::operator-=(zhematrix&)" << std::endl
58  << "These two matrises can not make a sutraction." << std::endl
59  << "Your input was (" << N << "x" << N << ") -= ("
60  << mat.N << "x" << mat.N << ")." << std::endl;
61  exit(1);
62  }
63 #endif//CPPL_DEBUG
64 
65  for(long i=0; i<N; i++){ for(long j=0; j<=i; j++){
66  operator()(i,j) -=mat(i,j);
67  }}
68 
69  return *this;
70 }
71 
72 //=============================================================================
74 inline _zhematrix operator+(const zhematrix& matA, const zhematrix& matB)
75 {
76 #ifdef CPPL_VERBOSE
77  std::cerr << "# [MARK] operator+(const zhematrix&, const zhematrix&)"
78  << std::endl;
79 #endif//CPPL_VERBOSE
80 
81 #ifdef CPPL_DEBUG
82  if(matA.N!=matB.N){
83  std::cerr << "[ERROR] operator+(zhematrix&, zhematrix&)" << std::endl
84  << "These two matrises can not make a summation." << std::endl
85  << "Your input was (" << matA.N << "x" << matA.N << ") + ("
86  << matB.N << "x" << matB.N << ")." << std::endl;
87  exit(1);
88  }
89 #endif//CPPL_DEBUG
90 
91  long N = matA.N;
92  zhematrix newmat(N);
93  for(long i=0; i<N; i++){ for(long j=0; j<=i; j++){
94  newmat.Array[i+N*j] = matA.Array[i+N*j] + matB.Array[i+N*j];
95  }}
96 
97  return _(newmat);
98 }
99 
100 //=============================================================================
102 inline _zhematrix operator-(const zhematrix& matA, const zhematrix& matB)
103 {
104 #ifdef CPPL_VERBOSE
105  std::cerr << "# [MARK] operator-(const zhematrix&, const zhematrix&)"
106  << std::endl;
107 #endif//CPPL_VERBOSE
108 
109 #ifdef CPPL_DEBUG
110  if(matA.N!=matB.N){
111  std::cerr << "[ERROR] operator-(zhematrix&, zhematrix&)" << std::endl
112  << "These two matrises can not make a subtraction." << std::endl
113  << "Your input was (" << matA.N << "x" << matA.N << ") - ("
114  << matB.N << "x" << matB.N << ")." << std::endl;
115  exit(1);
116  }
117 #endif//CPPL_DEBUG
118 
119  long N = matA.N;
120  zhematrix newmat(N);
121  for(long i=0; i<N; i++){ for(long j=0; j<=i; j++){
122  newmat.Array[i+N*j] =matA.Array[i+N*j]-matB.Array[i+N*j];
123  }}
124 
125  return _(newmat);
126 }
127 
128 //=============================================================================
130 inline _zgematrix operator*(const zhematrix& matA, const zhematrix& matB)
131 {
132 #ifdef CPPL_VERBOSE
133  std::cerr << "# [MARK] operator*(const zhematrix&, const zhematrix&)"
134  << std::endl;
135 #endif//CPPL_VERBOSE
136 
137 #ifdef CPPL_DEBUG
138  if(matA.N!=matB.N){
139  std::cerr << "[ERROR] operator*(zhematrix&, zhematrix&)" << std::endl
140  << "These two matrises can not make a product." << std::endl
141  << "Your input was (" << matA.N << "x" << matA.N << ") * ("
142  << matB.N << "x" << matB.N << ")." << std::endl;
143  exit(1);
144  }
145 #endif//CPPL_DEBUG
146 
147  matB.complete();
148  zgematrix newmat( matA.N, matB.N );
149 
150  zhemm_( 'L', 'L', matA.N, matB.N, std::complex<double>(1.0,0.0),
151  matA.Array, matA.N, matB.Array, matB.N,
152  std::complex<double>(0.0,0.0), newmat.array, newmat.m );
153 
154  return _(newmat);
155 }
__zhecomplex operator()(const long &, const long &)
Definition: zhematrix-io.hpp:3
(DO NOT USE) Smart-temporary Complex Double-precision Hermitian Matrix Class
Definition: _zhematrix.hpp:3
zhematrix & operator+=(const zhematrix &)
Definition: zhematrix-zhematrix.hpp:22
friend _zrovector operator-(const _zrovector &)
Definition: _zrovector-unary.hpp:15
void complete() const
Definition: zhematrix-misc.hpp:3
Complex Double-precision General Dence Matrix Class.
Definition: zgematrix.hpp:3
void copy(const zhematrix &)
Definition: zhematrix-misc.hpp:95
(DO NOT USE) Smart-temporary Complex Double-precision General Dence Matrix Class
Definition: _zgematrix.hpp:3
friend _zgematrix i(const zhematrix &)
Definition: zhematrix-calc.hpp:20
friend _zrovector operator*(const zrovector &, const zgematrix &)
Definition: zrovector-zgematrix.hpp:3
zhematrix & operator=(const zhematrix &)
Definition: zhematrix-zhematrix.hpp:3
Complex Double-precision Hermitian Matrix Class [L-type (UPLO=L) Strage].
Definition: zhematrix.hpp:4
zhematrix & operator-=(const zhematrix &)
Definition: zhematrix-zhematrix.hpp:48
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