My Project
dsymatrix-dsymatrix.hpp
1 //=============================================================================
3 inline dsymatrix& dsymatrix::operator=(const dsymatrix& mat)
4 {
5 #ifdef CPPL_VERBOSE
6  std::cerr << "# [MARK] dsymatrix::operator=(const dsymatrix&)"
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 //=============================================================================
22 inline dsymatrix& dsymatrix::operator+=(const dsymatrix& mat)
23 {
24 #ifdef CPPL_VERBOSE
25  std::cerr << "# [MARK] dsymatrix::operator+=(const dsymatrix&)"
26  << std::endl;
27 #endif//CPPL_VERBOSE
28 
29 #ifdef CPPL_DEBUG
30  if(N!=mat.N){
31  std::cerr << "[ERROR] dsymatrix::operator+=(dsymatrix&)" << std::endl
32  << "These two matrises can not make a summation." << std::endl
33  << "Your input was (" << N << "x" << N << ") += ("
34  << mat.N << "x" << mat.N << ")." << std::endl;
35  exit(1);
36  }
37 #endif//CPPL_DEBUG
38 
39  for(long i=0; i<N*N; i++){
40  Array[i]+=mat.Array[i];
41  }
42  return *this;
43 }
44 
45 //=============================================================================
47 inline dsymatrix& dsymatrix::operator-=(const dsymatrix& mat)
48 {
49 #ifdef CPPL_VERBOSE
50  std::cerr << "# [MARK] dsymatrix::operator-=(const dsymatrix&)"
51  << std::endl;
52 #endif//CPPL_VERBOSE
53 
54 #ifdef CPPL_DEBUG
55  if(N!=mat.N){
56  std::cerr << "[ERROR] dsymatrix::operator-=(dsymatrix&)" << std::endl
57  << "These two matrises can not make a sutraction." << std::endl
58  << "Your input was (" << N << "x" << N << ") -= ("
59  << mat.N << "x" << mat.N << ")." << std::endl;
60  exit(1);
61  }
62 #endif//CPPL_DEBUG
63 
64  for(long i=0; i<N*N; i++){
65  Array[i]-=mat.Array[i];
66  }
67  return *this;
68 }
69 
70 //=============================================================================
72 inline _dsymatrix operator+(const dsymatrix& matA, const dsymatrix& matB)
73 {
74 #ifdef CPPL_VERBOSE
75  std::cerr << "# [MARK] operator+(const dsymatrix&, const dsymatrix&)"
76  << std::endl;
77 #endif//CPPL_VERBOSE
78 
79 #ifdef CPPL_DEBUG
80  if(matA.N!=matB.N){
81  std::cerr << "[ERROR] operator+(dsymatrix&, dsymatrix&)" << std::endl
82  << "These two matrises can not make a summation." << std::endl
83  << "Your input was (" << matA.N << "x" << matA.N << ") + ("
84  << matB.N << "x" << matB.N << ")." << std::endl;
85  exit(1);
86  }
87 #endif//CPPL_DEBUG
88 
89  long N = matA.N;
90  dsymatrix newmat(N);
91  for(long i=0; i<N*N; i++){
92  newmat.Array[i] = matA.Array[i] + matB.Array[i];
93  }
94  return _(newmat);
95 }
96 
97 //=============================================================================
99 inline _dsymatrix operator-(const dsymatrix& matA, const dsymatrix& matB)
100 {
101 #ifdef CPPL_VERBOSE
102  std::cerr << "# [MARK] operator-(const dsymatrix&, const dsymatrix&)"
103  << std::endl;
104 #endif//CPPL_VERBOSE
105 
106 #ifdef CPPL_DEBUG
107  if(matA.N!=matB.N){
108  std::cerr << "[ERROR] operator-(dsymatrix&, dsymatrix&)" << std::endl
109  << "These two matrises can not make a subtraction." << std::endl
110  << "Your input was (" << matA.N << "x" << matA.N << ") - ("
111  << matB.N << "x" << matB.N << ")." << std::endl;
112  exit(1);
113  }
114 #endif//CPPL_DEBUG
115 
116  long N = matA.N;
117  dsymatrix newmat(N);
118  for(long i=0; i<N*N; i++){
119  newmat.Array[i] =matA.Array[i]-matB.Array[i];
120  }
121 
122  return _(newmat);
123 }
124 
125 //=============================================================================
127 inline _dgematrix operator*(const dsymatrix& matA, const dsymatrix& matB)
128 {
129 #ifdef CPPL_VERBOSE
130  std::cerr << "# [MARK] operator*(const dsymatrix&, const dsymatrix&)"
131  << std::endl;
132 #endif//CPPL_VERBOSE
133 
134 #ifdef CPPL_DEBUG
135  if(matA.N!=matB.N){
136  std::cerr << "[ERROR] operator*(dsymatrix&, dsymatrix&)" << std::endl
137  << "These two matrises can not make a product." << std::endl
138  << "Your input was (" << matA.N << "x" << matA.N << ") * ("
139  << matB.N << "x" << matB.N << ")." << std::endl;
140  exit(1);
141  }
142 #endif//CPPL_DEBUG
143 
144  matA.complete();
145  matB.complete();
146  dgematrix newmat(matA.N, matA.N);
147 
148  dgemm_( 'N', 'N', matA.N, matB.N, matA.N, 1.0, matA.Array, matA.N,
149  matB.Array, matB.N, 0.0, newmat.array, matA.N );
150 
151  return _(newmat);
152 }
dsymatrix & operator-=(const dsymatrix &)
Definition: dsymatrix-dsymatrix.hpp:47
friend _dgematrix i(const dsymatrix &)
Definition: dsymatrix-calc.hpp:22
double * Array
1D Array to store vector data
Definition: _drovector.hpp:8
Real Double-precision General Dence Matrix Class.
Definition: dgematrix.hpp:3
Real Double-precision Symmetric Matrix Class [L-type (UPLO=L) Strage].
Definition: dsymatrix.hpp:3
friend _drovector operator-(const _drovector &)
Definition: _drovector-unary.hpp:15
(DO NOT USE) Smart-temporary Real Double-precision General Dence Matrix Class
Definition: _dgematrix.hpp:3
dsymatrix & operator+=(const dsymatrix &)
Definition: dsymatrix-dsymatrix.hpp:22
dsymatrix & operator=(const dsymatrix &)
Definition: dsymatrix-dsymatrix.hpp:3
friend _drovector operator*(const drovector &, const dgematrix &)
Definition: drovector-dgematrix.hpp:3
(DO NOT USE) Smart-temporary Real Double-precision Symmetric Matrix Class
Definition: _dsymatrix.hpp:3
void complete() const
Definition: dsymatrix-misc.hpp:3
void copy(const dsymatrix &)
Definition: dsymatrix-misc.hpp:78
friend const _drovector & operator+(const _drovector &)
Definition: _drovector-unary.hpp:3