My Project
_dssmatrix-_dgematrix.hpp
1 //=============================================================================
3 inline _dgematrix operator+(const _dssmatrix& matA, const _dgematrix& matB)
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] operator+(const _dssmatrix&, const _dgematrix&)"
7  << std::endl;
8 #endif//CPPL_VERBOSE
9 
10 #ifdef CPPL_DEBUG
11  if(matA.M!=matB.M || matA.N!=matB.N){
12  std::cerr << "[ERROR] operator+(const _dssmatrix&, const _dgematrix&)"
13  << std::endl
14  << "These two matrises can not make a summation." << std::endl
15  << "Your input was (" << matA.M << "x" << matA.N << ") + ("
16  << matB.M << "x" << matB.N << ")." << std::endl;
17  exit(1);
18  }
19 #endif//CPPL_DEBUG
20 
21  for(long c=0; c<matA.VOL; c++){
22  matB(matA.Indx[c],matA.Jndx[c]) += matA.Array[c];
23  }
24 
25  matA.destroy();
26  return matB;
27 }
28 
29 //=============================================================================
31 inline _dgematrix operator-(const _dssmatrix& matA, const _dgematrix& matB)
32 {
33 #ifdef CPPL_VERBOSE
34  std::cerr << "# [MARK] operator-(const _dssmatrix&, const _dgematrix&)"
35  << std::endl;
36 #endif//CPPL_VERBOSE
37 
38 #ifdef CPPL_DEBUG
39  if(matA.M!=matB.M || matA.N!=matB.N){
40  std::cerr << "[ERROR] operator-(const _dssmatrix&, const _dgematrix&)"
41  << std::endl
42  << "These two matrises can not make a subtraction." << std::endl
43  << "Your input was (" << matA.M << "x" << matA.N << ") - ("
44  << matB.N << "x" << matB.N << ")." << std::endl;
45  exit(1);
46  }
47 #endif//CPPL_DEBUG
48 
50  for(int i=0; i<matB.M*matB.N; i++){
51  matB.Array[i] = -matB.Array[i];
52  }
53 
54  for(long c=0; c<matA.VOL; c++){
55  matB(matA.Indx[c],matA.Jndx[c]) += matA.Array[c];
56  }
57 
58  matA.destroy();
59  return matB;
60 }
61 
62 //=============================================================================
64 inline _dgematrix operator*(const _dssmatrix& matA, const _dgematrix& matB)
65 {
66 #ifdef CPPL_VERBOSE
67  std::cerr << "# [MARK] operator*(const _dssmatrix&, const _dgematrix&)"
68  << std::endl;
69 #endif//CPPL_VERBOSE
70 
71 #ifdef CPPL_DEBUG
72  if(matA.N!=matB.M){
73  std::cerr << "[ERROR] operator*(const _dssmatrix&, const _dgematrix&)"
74  << std::endl
75  << "These two matrises can not make a product." << std::endl
76  << "Your input was (" << matA.M << "x" << matA.N << ") * ("
77  << matB.N << "x" << matB.N << ")." << std::endl;
78  exit(1);
79  }
80 #endif//CPPL_DEBUG
81 
82  dgematrix newmat(matA.M, matB.N);
83  newmat.zero();
84 
85  for(long c=0; c<matA.VOL; c++){
86  for(long j=0; j<matB.N; j++){
87  newmat(matA.Indx[c],j) += matA.Array[c]*matB(matA.Jndx[c],j);
88  }
89  }
90 
91  matA.destroy();
92  matB.destroy();
93  return _(newmat);
94 }
double * Array
1D array to store non-zero matrix data
Definition: _dssmatrix.hpp:11
(DO NOT USE) Smart-temporary Real Double-precision Sparse Matrix Class
Definition: _dssmatrix.hpp:3
long M
matrix row size
Definition: _dssmatrix.hpp:7
Real Double-precision General Dence Matrix Class.
Definition: dgematrix.hpp:3
friend _drovector _(drovector &)
Definition: drovector-misc.hpp:131
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
(DO NOT USE) Smart-temporary Real Double-precision General Dence Matrix Class
Definition: _dgematrix.hpp:3
long N
matrix column size
Definition: _dgematrix.hpp:8
long VOL
the number of non-zero components
Definition: _dssmatrix.hpp:10
double * Array
1D array to store matrix data
Definition: _dgematrix.hpp:9
friend const drovector & operator+(const drovector &)
Definition: drovector-unary.hpp:3
long N
matrix column size
Definition: _dssmatrix.hpp:8
void destroy() const
Definition: _dgematrix-misc.hpp:3
long * Indx
1D array to store the i-index of non-zero matrix components
Definition: _dssmatrix.hpp:12
void destroy() const
Definition: _dssmatrix-misc.hpp:3
friend _drovector operator-(const drovector &)
Definition: drovector-unary.hpp:15
long M
matrix row size
Definition: _dgematrix.hpp:7