My Project
zssmatrix-zssmatrix.hpp
1 //=============================================================================
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] zssmatrix::operator=(const zssmatrix&)"
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 //=============================================================================
23 {
24 #ifdef CPPL_VERBOSE
25  std::cerr << "# [MARK] zssmatrix::operator+=(const zssmatrix&)"
26  << std::endl;
27 #endif//CPPL_VERBOSE
28 
29 #ifdef CPPL_DEBUG
30  if(N!=mat.N || M!=mat.M){
31  std::cerr << "[ERROR] zssmatrix::operator+=(const zssmatrix&)"
32  << std::endl
33  << "These two matrises can not make a summation." << std::endl
34  << "Your input was (" << M << "x" << N << ") += ("
35  << mat.M << "x" << mat.N << ")." << std::endl;
36  exit(1);
37  }
38 #endif//CPPL_DEBUG
39 
40  for(long c=0; c<mat.VOL; c++){
41  add(mat.Indx[c],mat.Jndx[c], mat.Array[c]);
42  }
43  return *this;
44 }
45 
46 //=============================================================================
49 {
50 #ifdef CPPL_VERBOSE
51  std::cerr << "# [MARK] zssmatrix::operator-=(const zssmatrix&)"
52  << std::endl;
53 #endif//CPPL_VERBOSE
54 
55 #ifdef CPPL_DEBUG
56  if(N!=mat.N || M!=mat.M){
57  std::cerr << "[ERROR] zssmatrix::operator-=(const zssmatrix&)"
58  << std::endl
59  << "These two matrises can not make a sutraction." << std::endl
60  << "Your input was (" << M << "x" << N << ") -= ("
61  << mat.M << "x" << mat.N << ")." << std::endl;
62  exit(1);
63  }
64 #endif//CPPL_DEBUG
65 
66  for(long c=0; c<mat.VOL; c++){
67  sub(mat.Indx[c],mat.Jndx[c], mat.Array[c]);
68  }
69  return *this;
70 }
71 
72 //=============================================================================
75 {
76 #ifdef CPPL_VERBOSE
77  std::cerr << "# [MARK] zssmatrix::operator*=(const zssmatrix&)"
78  << std::endl;
79 #endif//CPPL_VERBOSE
80 
81 #ifdef CPPL_DEBUG
82  if(N!=mat.M){
83  std::cerr << "[ERROR] zssmatrix::operator*=(const zssmatrix&)"
84  << std::endl
85  << "These two matrises can not make a product." << std::endl
86  << "Your input was (" << M << "x" << N << ") *= ("
87  << mat.M << "x" << mat.N << ")." << std::endl;
88  exit(1);
89  }
90 #endif//CPPL_DEBUG
91 
92  zssmatrix newmat( M, mat.N, 0 );
93 
94  for(long c=0; c<VOL; c++){
95  for(long d=0; d<mat.VOL; d++){
96  if(Jndx[c]==mat.Indx[d]){
97  newmat.add(Indx[c], mat.Jndx[d], Array[c]*mat.Array[d]);
98  }
99  }
100  }
101 
102  swap(*this,newmat);
103  return *this;
104 }
105 
109 
110 //=============================================================================
112 inline _zssmatrix operator+(const zssmatrix& matA, const zssmatrix& matB)
113 {
114 #ifdef CPPL_VERBOSE
115  std::cerr << "# [MARK] operator+(const zssmatrix&, const zssmatrix&)"
116  << std::endl;
117 #endif//CPPL_VERBOSE
118 
119 #ifdef CPPL_DEBUG
120  if(matA.N!=matB.N || matA.M!=matB.M){
121  std::cerr << "[ERROR] operator+(zssmatrix&, zssmatrix&)" << std::endl
122  << "These two matrises can not make a summation." << std::endl
123  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
124  << matB.M << "x" << matB.N << ")." << std::endl;
125  exit(1);
126  }
127 #endif//CPPL_DEBUG
128 
129  zssmatrix newmat(matA);
130 
131  for(long c=0; c<matB.VOL; c++){
132  newmat.add(matB.Indx[c], matB.Jndx[c], matB.Array[c]);
133  }
134 
135  return _(newmat);
136 }
137 
138 //=============================================================================
140 inline _zssmatrix operator-(const zssmatrix& matA, const zssmatrix& matB)
141 {
142 #ifdef CPPL_VERBOSE
143  std::cerr << "# [MARK] operator-(const zssmatrix&, const zssmatrix&)"
144  << std::endl;
145 #endif//CPPL_VERBOSE
146 
147 #ifdef CPPL_DEBUG
148  if(matA.N!=matB.N || matA.M!=matB.M){
149  std::cerr << "[ERROR] operator-(zssmatrix&, zssmatrix&)" << std::endl
150  << "These two matrises can not make a subtraction." << std::endl
151  << "Your input was (" << matA.M << "x" << matA.N << ") - ("
152  << matB.M << "x" << matB.N << ")." << std::endl;
153  exit(1);
154  }
155 #endif//CPPL_DEBUG
156 
157  zssmatrix newmat(matA);
158 
159  for(long c=0; c<matB.VOL; c++){
160  newmat.sub(matB.Indx[c], matB.Jndx[c], matB.Array[c]);
161  }
162 
163  return _(newmat);
164 }
165 
166 //=============================================================================
168 inline _zssmatrix operator*(const zssmatrix& matA, const zssmatrix& matB)
169 {
170 #ifdef CPPL_VERBOSE
171  std::cerr << "# [MARK] operator*(const zssmatrix&, const zssmatrix&)"
172  << std::endl;
173 #endif//CPPL_VERBOSE
174 
175 #ifdef CPPL_DEBUG
176  if(matA.N!=matB.M){
177  std::cerr << "[ERROR] operator*(zssmatrix&, zssmatrix&)" << std::endl
178  << "These two matrises can not make a product." << std::endl
179  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
180  << matB.M << "x" << matB.N << ")." << std::endl;
181  exit(1);
182  }
183 #endif//CPPL_DEBUG
184 
185  zssmatrix newmat( matA.M, matB.N, 0 );
186 
187  for(long c=0; c<matA.VOL; c++){
188  for(long d=0; d<matB.VOL; d++){
189  if(matA.Jndx[c]==matB.Indx[d]){
190  newmat.add(matA.Indx[c], matB.Jndx[d], matA.Array[c]*matB.Array[d]);
191  }
192  }
193  }
194 
195  return _(newmat);
196 }
zssmatrix & operator-=(const zssmatrix &)
Definition: zssmatrix-zssmatrix.hpp:48
(DO NOT USE) Smart-temporary Complex Double-precision Sparse Matrix Class
Definition: _zssmatrix.hpp:3
void add(const long &, const long &, const std::complex< double > &)
Definition: zssmatrix-io.hpp:120
zssmatrix & operator*=(const zssmatrix &)
Definition: zssmatrix-zssmatrix.hpp:74
friend _zrovector operator-(const _zrovector &)
Definition: _zrovector-unary.hpp:15
void copy(const zssmatrix &)
Definition: zssmatrix-misc.hpp:48
friend void swap(zssmatrix &, zssmatrix &)
Definition: zssmatrix-misc.hpp:228
void sub(const long &, const long &, const std::complex< double > &)
Definition: zssmatrix-io.hpp:157
friend _zrovector operator*(const zrovector &, const zgematrix &)
Definition: zrovector-zgematrix.hpp:3
zssmatrix & operator=(const zssmatrix &)
Definition: zssmatrix-zssmatrix.hpp:3
Complex Double-precision Sparse Matrix Class.
Definition: zssmatrix.hpp:3
friend const _zrovector & operator+(const _zrovector &)
Definition: _zrovector-unary.hpp:3
zssmatrix & operator+=(const zssmatrix &)
Definition: zssmatrix-zssmatrix.hpp:22
std::complex< double > * Array
1D Array to store vector data
Definition: _zrovector.hpp:8