VERB_code_2.3
dssmatrix-_dssmatrix.hpp
1 //=============================================================================
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] dssmatrix::operator=(const _dssmatrix&)"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10  shallow_copy(mat);
11  return *this;
12 }
13 
17 
18 //=============================================================================
21 {
22 #ifdef CPPL_VERBOSE
23  std::cerr << "# [MARK] dssmatrix::operator+=(const _dssmatrix&)"
24  << std::endl;
25 #endif//CPPL_VERBOSE
26 
27 #ifdef CPPL_DEBUG
28  if(N!=mat.N || M!=mat.M){
29  std::cerr << "[ERROR] dssmatrix::operator+=(const _dssmatrix&)"
30  << std::endl
31  << "These two matrises can not make a summation." << std::endl
32  << "Your input was (" << M << "x" << N << ") += ("
33  << mat.M << "x" << mat.N << ")." << std::endl;
34  exit(1);
35  }
36 #endif//CPPL_DEBUG
37 
38  for(long c=0; c<mat.VOL; c++){
39  add(mat.Indx[c],mat.Jndx[c], mat.Array[c]);
40  }
41 
42  mat.destroy();
43  return *this;
44 }
45 
46 //=============================================================================
49 {
50 #ifdef CPPL_VERBOSE
51  std::cerr << "# [MARK] dssmatrix::operator-=(const _dssmatrix&)"
52  << std::endl;
53 #endif//CPPL_VERBOSE
54 
55 #ifdef CPPL_DEBUG
56  if(N!=mat.N || M!=mat.M){
57  std::cerr << "[ERROR] dssmatrix::operator-=(const _dssmatrix&)"
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 
70  mat.destroy();
71  return *this;
72 }
73 
74 //=============================================================================
77 {
78 #ifdef CPPL_VERBOSE
79  std::cerr << "# [MARK] dssmatrix::operator*=(const _dssmatrix&)"
80  << std::endl;
81 #endif//CPPL_VERBOSE
82 
83 #ifdef CPPL_DEBUG
84  if(N!=mat.M){
85  std::cerr << "[ERROR] dssmatrix::operator*=(const _dssmatrix&)"
86  << std::endl
87  << "These two matrises can not make a product." << std::endl
88  << "Your input was (" << M << "x" << N << ") *= ("
89  << mat.M << "x" << mat.N << ")." << std::endl;
90  exit(1);
91  }
92 #endif//CPPL_DEBUG
93 
94  dssmatrix newmat( M, mat.N, 0 );
95 
96  for(long c=0; c<VOL; c++){
97  for(long d=0; d<mat.VOL; d++){
98  if(Jndx[c]==mat.Indx[d]){
99  newmat.add(Indx[c], mat.Jndx[d], Array[c]*mat.Array[d]);
100  }
101  }
102  }
103 
104  swap(*this,newmat);
105  mat.destroy();
106  return *this;
107 }
108 
112 
113 //=============================================================================
115 inline _dssmatrix operator+(const dssmatrix& matA, const _dssmatrix& matB)
116 {
117 #ifdef CPPL_VERBOSE
118  std::cerr << "# [MARK] operator+(const dssmatrix&, const _dssmatrix&)"
119  << std::endl;
120 #endif//CPPL_VERBOSE
121 
122 #ifdef CPPL_DEBUG
123  if(matA.N!=matB.N || matA.M!=matB.M){
124  std::cerr << "[ERROR] operator+(const dssmatrix&, const _dssmatrix&)"
125  << std::endl
126  << "These two matrises can not make a summation." << std::endl
127  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
128  << matB.M << "x" << matB.N << ")." << std::endl;
129  exit(1);
130  }
131 #endif//CPPL_DEBUG
132 
133  dssmatrix newmat(matB);
134 
135  for(long c=0; c<matA.VOL; c++){
136  newmat.add(matA.Indx[c], matA.Jndx[c], matA.Array[c]);
137  }
138 
139  return _(newmat);
140 }
141 
142 //=============================================================================
144 inline _dssmatrix operator-(const dssmatrix& matA, const _dssmatrix& matB)
145 {
146 #ifdef CPPL_VERBOSE
147  std::cerr << "# [MARK] operator-(const dssmatrix&, const _dssmatrix&)"
148  << std::endl;
149 #endif//CPPL_VERBOSE
150 
151 #ifdef CPPL_DEBUG
152  if(matA.N!=matB.N || matA.M!=matB.M){
153  std::cerr << "[ERROR] operator-(const dssmatrix&, const dssmatrix&)"
154  << std::endl
155  << "These two matrises can not make a subtraction." << std::endl
156  << "Your input was (" << matA.M << "x" << matA.N << ") - ("
157  << matB.M << "x" << matB.N << ")." << std::endl;
158  exit(1);
159  }
160 #endif//CPPL_DEBUG
161 
162  dssmatrix newmat(matB);
163  newmat.chsign();
164 
166  for(long c=0; c<matA.VOL; c++){
167  newmat.add(matA.Indx[c], matA.Jndx[c], matA.Array[c]);
168  }
169 
170  return _(newmat);
171 }
172 
173 //=============================================================================
175 inline _dssmatrix operator*(const dssmatrix& matA, const _dssmatrix& matB)
176 {
177 #ifdef CPPL_VERBOSE
178  std::cerr << "# [MARK] operator*(const dssmatrix&, const _dssmatrix&)"
179  << std::endl;
180 #endif//CPPL_VERBOSE
181 
182 #ifdef CPPL_DEBUG
183  if(matA.N!=matB.M){
184  std::cerr << "[ERROR] operator*(const dssmatrix&, const dssmatrix&)"
185  << std::endl
186  << "These two matrises can not make a product." << std::endl
187  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
188  << matB.M << "x" << matB.N << ")." << std::endl;
189  exit(1);
190  }
191 #endif//CPPL_DEBUG
192 
193  dssmatrix newmat( matA.M, matB.N, 0 );
194 
195  for(long c=0; c<matA.VOL; c++){
196  for(long d=0; d<matB.VOL; d++){
197  if(matA.Jndx[c]==matB.Indx[d]){
198  newmat.add(matA.Indx[c], matB.Jndx[d], matA.Array[c]*matB.Array[d]);
199  }
200  }
201  }
202 
203  matB.destroy();
204  return _(newmat);
205 }
(DO NOT USE) Smart-temporary Real Double-precision Sparse Matrix Class
Definition: _dssmatrix.hpp:3
friend void swap(dssmatrix &, dssmatrix &)
Definition: dssmatrix-misc.hpp:228
void chsign()
Definition: dssmatrix-misc.hpp:36
dssmatrix & operator+=(const dssmatrix &)
Definition: dssmatrix-dssmatrix.hpp:22
long M
matrix row size
Definition: _dssmatrix.hpp:7
void shallow_copy(const _dssmatrix &)
Definition: dssmatrix-misc.hpp:77
long * Indx
1D array to store the i-index of non-zero matrix components
Definition: _dssmatrix.hpp:12
friend _drovector operator-(const _drovector &)
Definition: _drovector-unary.hpp:15
double * Array
1D array to store non-zero matrix data
Definition: _dssmatrix.hpp:11
void sub(const long &, const long &, const double &)
Definition: dssmatrix-io.hpp:157
long VOL
the number of non-zero components
Definition: _dssmatrix.hpp:10
long * Jndx
1D array to store the j-index of non-zero matrix components
Definition: _dssmatrix.hpp:13
friend _drovector operator*(const drovector &, const dgematrix &)
Definition: drovector-dgematrix.hpp:3
dssmatrix & operator=(const dssmatrix &)
Definition: dssmatrix-dssmatrix.hpp:3
void add(const long &, const long &, const double &)
Definition: dssmatrix-io.hpp:120
long N
matrix column size
Definition: _dssmatrix.hpp:8
dssmatrix & operator-=(const dssmatrix &)
Definition: dssmatrix-dssmatrix.hpp:48
Real Double-precision Sparse Matrix Class.
Definition: dssmatrix.hpp:3
dssmatrix & operator*=(const dssmatrix &)
Definition: dssmatrix-dssmatrix.hpp:74
double * Array
1D Array to store vector data
Definition: _drovector.hpp:8
void destroy() const
Definition: _dssmatrix-misc.hpp:3
friend const _drovector & operator+(const _drovector &)
Definition: _drovector-unary.hpp:3