My Project
_zhematrix-_zhematrix.hpp
1 //=============================================================================
3 inline _zhematrix operator+(const _zhematrix& matA, const _zhematrix& matB)
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] operator+(const _zhematrix&, const _zhematrix&)"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10 #ifdef CPPL_DEBUG
11  if(matA.N!=matB.N){
12  std::cerr << "[ERROR] operator+(_zhematrix&, _zhematrix&)" << std::endl
13  << "These two matrises can not make a summation." << std::endl
14  << "Your input was (" << matA.N << "x" << matA.N << ") + ("
15  << matB.N << "x" << matB.N << ")." << std::endl;
16  exit(1);
17  }
18 #endif//CPPL_DEBUG
19 
20  for(long i=0; i<matA.N; i++){
21  for(long j=0; j<matA.N; j++){
22  matA.Array[i+matA.N*j]+=matB.Array[i+matA.N*j];
23  }
24  }
25 
26  matB.destroy();
27  return matA;
28 }
29 
30 //=============================================================================
32 inline _zhematrix operator-(const _zhematrix& matA, const _zhematrix& matB)
33 {
34 #ifdef CPPL_VERBOSE
35  std::cerr << "# [MARK] operator-(const _zhematrix&, const _zhematrix&)"
36  << std::endl;
37 #endif//CPPL_VERBOSE
38 
39 #ifdef CPPL_DEBUG
40  if(matA.N!=matB.N){
41  std::cerr << "[ERROR] operator-(_zhematrix&, _zhematrix&)" << std::endl
42  << "These two matrises can not make a subtraction." << std::endl
43  << "Your input was (" << matA.N << "x" << matA.N << ") - ("
44  << matB.N << "x" << matB.N << ")." << std::endl;
45  exit(1);
46  }
47 #endif//CPPL_DEBUG
48 
49  for(long i=0; i<matA.N; i++){
50  for(long j=0; j<matA.N; j++){
51  matA.Array[i+matA.N*j]-=matB.Array[i+matA.N*j];
52  }
53  }
54 
55  matB.destroy();
56  return matA;
57 }
58 
59 //=============================================================================
61 inline _zgematrix operator*(const _zhematrix& matA, const _zhematrix& matB)
62 {
63 #ifdef CPPL_VERBOSE
64  std::cerr << "# [MARK] operator*(const _zhematrix&, const _zhematrix&)"
65  << std::endl;
66 #endif//CPPL_VERBOSE
67 
68 #ifdef CPPL_DEBUG
69  if(matA.N!=matB.N){
70  std::cerr << "[ERROR] operator*(_zhematrix&, zhematrix&)" << std::endl
71  << "These two matrises can not make a product." << std::endl
72  << "Your input was (" << matA.N << "x" << matA.N << ") * ("
73  << matB.N << "x" << matB.N << ")." << std::endl;
74  exit(1);
75  }
76 #endif//CPPL_DEBUG
77 
78  matB.complete();
79  zgematrix newmat( matA.N, matB.N );
80 
81  zhemm_( 'L', 'L', matA.N, matB.N, std::complex<double>(1.0,0.0),
82  matA.Array, matA.N, matB.Array, matB.N,
83  std::complex<double>(0.0,0.0), newmat.array, newmat.m );
84 
85  matA.destroy();
86  matB.destroy();
87  return _(newmat);
88 }
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
friend _zrovector operator-(const _zrovector &)
Definition: _zrovector-unary.hpp:15
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 destroy() const
Definition: _zhematrix-misc.hpp:3
std::complex< double > * Array
1D Array to store matrix data
Definition: _zhematrix.hpp:8
friend _zrovector operator*(const zrovector &, const zgematrix &)
Definition: zrovector-zgematrix.hpp:3
long const & m
matrix row size (readable)
Definition: zgematrix.hpp:14
long N
matrix column or row size
Definition: _zhematrix.hpp:7
friend const _zrovector & operator+(const _zrovector &)
Definition: _zrovector-unary.hpp:3