My Project
zgbmatrix-_zgematrix.hpp
1 //=============================================================================
3 inline _zgematrix operator+(const zgbmatrix& matA, const _zgematrix& matB)
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] operator+(const zgbmatrix&, const _zgematrix&)"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10 #ifdef CPPL_DEBUG
11  if(matA.N!=matB.N || matA.M!=matB.M){
12  std::cerr << "[ERROR] operator+(zgbmatrix&, _zgematrix&)" << std::endl
13  << "These two matrises can not make a summation." << std::endl
14  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
15  << matB.M << "x" << matB.N << ")." << std::endl;
16  exit(1);
17  }
18 #endif//CPPL_DEBUG
19 
20  for(long i=0; i<matA.M; i++){
21  for(long j=max(0,i-matA.KL); j<min(matA.N,i+matA.KU+1); j++){
22  matB(i,j)+=matA(i,j);
23  }
24  }
25 
26  return matB;
27 }
28 
29 //=============================================================================
31 inline _zgematrix operator-(const zgbmatrix& matA, const _zgematrix& matB)
32 {
33 #ifdef CPPL_VERBOSE
34  std::cerr << "# [MARK] operator-(const zgbmatrix&, const _zgematrix&)"
35  << std::endl;
36 #endif//CPPL_VERBOSE
37 
38 #ifdef CPPL_DEBUG
39  if(matA.N!=matB.N || matA.M!=matB.M){
40  std::cerr << "[ERROR] operator+(zgbmatrix&, _zgematrix&)" << std::endl
41  << "These two matrises can not make a summation." << std::endl
42  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
43  << matB.M << "x" << matB.N << ")." << std::endl;
44  exit(1);
45  }
46 #endif//CPPL_DEBUG
47 
49  for(long i=0; i<matB.M*matB.N; i++){
50  matB.Array[i] = -matB.Array[i];
51  }
52 
54  for(long i=0; i<matA.M; i++){
55  for(long j=max(0,i-matA.KL); j<min(matA.N,i+matA.KU+1); j++){
56  matB(i,j) +=matA(i,j);
57  }
58  }
59 
60  return matB;
61 }
62 
63 //=============================================================================
65 inline _zgematrix operator*(const zgbmatrix& matA, const _zgematrix& matB)
66 {
67 #ifdef CPPL_VERBOSE
68  std::cerr << "# [MARK] operator*(const zgbmatrix&, const _zgematrix&)"
69  << std::endl;
70 #endif//CPPL_VERBOSE
71 
72 #ifdef CPPL_DEBUG
73  if(matA.N!=matB.M){
74  std::cerr << "[ERROR] operator*(zgbmatrix&, _zgematrix&)" << std::endl
75  << "These two matrises can not make a product." << std::endl
76  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
77  << matB.M << "x" << matB.N << ")." << std::endl;
78  exit(1);
79  }
80 #endif//CPPL_DEBUG
81 
82  zgematrix newmat( matA.M, matB.N );
83  newmat.zero();
84 
85  long i, j, k;
86 #pragma omp parallel for private(j,k)
87  for(i=0; i<newmat.m; i++){
88  for(j=0; j<newmat.n; j++){
89  for(k=max(0,i-matA.KL); k<min(matA.N,i+matA.KU+1); k++){
90  newmat(i,j)+=matA(i,k)*matB(k,j);
91  }
92  }
93  }
94 
95  matB.destroy();
96  return _(newmat);
97 }
long N
matrix column size
Definition: _zgematrix.hpp:8
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 destroy() const
Definition: _zgematrix-misc.hpp:3
void zero()
Definition: zgematrix-misc.hpp:26
Complex Double-precision General Band Matrix Class.
Definition: zgbmatrix.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
long const & m
matrix row size (readable)
Definition: zgematrix.hpp:14
long const & n
matrix column size (readable)
Definition: zgematrix.hpp:15
friend const _zrovector & operator+(const _zrovector &)
Definition: _zrovector-unary.hpp:3