CPPLapack
 All Classes Files Functions Variables Friends Pages
dgematrix-_dgbmatrix.hpp
Go to the documentation of this file.
1 //=============================================================================
2 /*! dgematrix+=_dgbmatrix operator */
4 {CPPL_VERBOSE_REPORT;
5 #ifdef CPPL_DEBUG
6  if(n!=mat.n || m!=mat.m){
7  ERROR_REPORT;
8  std::cerr << "These two matrises can not make a summation." << std::endl
9  << "Your input was (" << m << "x" << n << ") += (" << mat.m << "x" << mat.n << ")." << std::endl;
10  exit(1);
11  }
12 #endif//CPPL_DEBUG
13 
14  for(CPPL_INT i=0; i<mat.m; i++){
15  const CPPL_INT jmax =std::min(n,i+mat.ku+1);
16  for(CPPL_INT j=std::max(CPPL_INT(0),i-mat.kl); j<jmax; j++){
17  operator()(i,j) += mat(i,j);
18  }
19  }
20 
21  mat.destroy();
22  return *this;
23 }
24 
25 //=============================================================================
26 /*! dgematrix-=_dgbmatrix operator */
28 {CPPL_VERBOSE_REPORT;
29 #ifdef CPPL_DEBUG
30  if(n!=mat.n || m!=mat.m){
31  ERROR_REPORT;
32  std::cerr << "These two matrises can not make a subtraction." << std::endl
33  << "Your input was (" << m << "x" << n << ") -= (" << mat.m << "x" << mat.n << ")." << std::endl;
34  exit(1);
35  }
36 #endif//CPPL_DEBUG
37 
38  for(CPPL_INT i=0; i<mat.m; i++){
39  const CPPL_INT jmax =std::min(n,i+mat.ku+1);
40  for(CPPL_INT j=std::max(CPPL_INT(0),i-mat.kl); j<jmax; j++){
41  operator()(i,j) -= mat(i,j);
42  }
43  }
44 
45  mat.destroy();
46  return *this;
47 }
48 //=============================================================================
49 /*! dgematrix*=_dgbmatrix operator */
51 {CPPL_VERBOSE_REPORT;
52 #ifdef CPPL_DEBUG
53  if(n!=mat.m){
54  ERROR_REPORT;
55  std::cerr << "These two matrises can not make a product." << std::endl
56  << "Your input was (" << m << "x" << n << ") *= (" << mat.m << "x" << mat.n << ")." << std::endl;
57  exit(1);
58  }
59 #endif//CPPL_DEBUG
60 
61  dgematrix newmat(m,mat.n);
62  newmat.zero();
63 
64  for(CPPL_INT i=0; i<newmat.m; i++){
65  for(CPPL_INT j=0; j<newmat.n; j++){
66  const CPPL_INT kmax =std::min(mat.m,j+mat.kl+1);
67  for(CPPL_INT k=std::max(CPPL_INT(0),j-mat.ku); k<kmax; k++){
68  newmat(i,j) += operator()(i,k)*mat(k,j);
69  }
70  }
71  }
72 
73  swap(*this, newmat);
74  mat.destroy();
75  return *this;
76 }
77 
78 ///////////////////////////////////////////////////////////////////////////////
79 ///////////////////////////////////////////////////////////////////////////////
80 ///////////////////////////////////////////////////////////////////////////////
81 
82 //=============================================================================
83 /*! dgematrix+_dgbmatrix operator */
84 inline _dgematrix operator+(const dgematrix& matA, const _dgbmatrix& matB)
85 {CPPL_VERBOSE_REPORT;
86 #ifdef CPPL_DEBUG
87  if(matA.n!=matB.n || matA.m!=matB.m){
88  ERROR_REPORT;
89  std::cerr << "These two matrises can not make a summation." << std::endl
90  << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.m << "x" << matB.n << ")." << std::endl;
91  exit(1);
92  }
93 #endif//CPPL_DEBUG
94 
95  dgematrix newmat(matA);
96 
97  for(CPPL_INT i=0; i<matB.m; i++){
98  const CPPL_INT jmax =std::min(matB.n,i+matB.ku+1);
99  for(CPPL_INT j=std::max(CPPL_INT(0),i-matB.kl); j<jmax; j++){
100  newmat(i,j) += matB(i,j);
101  }
102  }
103 
104  matB.destroy();
105  return _(newmat);
106 }
107 
108 //=============================================================================
109 /*! dgematrix-_dgbmatrix operator */
110 inline _dgematrix operator-(const dgematrix& matA, const _dgbmatrix& matB)
111 {CPPL_VERBOSE_REPORT;
112 #ifdef CPPL_DEBUG
113  if(matA.n!=matB.n || matA.m!=matB.m){
114  ERROR_REPORT;
115  std::cerr << "These two matrises can not make a summation." << std::endl
116  << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.m << "x" << matB.n << ")." << std::endl;
117  exit(1);
118  }
119 #endif//CPPL_DEBUG
120 
121  dgematrix newmat(matA);
122 
123  for(CPPL_INT i=0; i<matB.m; i++){
124  const CPPL_INT jmax =std::min(matB.n,i+matB.ku+1);
125  for(CPPL_INT j=std::max(CPPL_INT(0),i-matB.kl); j<jmax; j++){
126  newmat(i,j) -= matB(i,j);
127  }
128  }
129 
130  matB.destroy();
131  return _(newmat);
132 }
133 
134 //=============================================================================
135 /*! dgematrix*_dgbmatrix operator */
136 inline _dgematrix operator*(const dgematrix& matA, const _dgbmatrix& matB)
137 {CPPL_VERBOSE_REPORT;
138 #ifdef CPPL_DEBUG
139  if(matA.n!=matB.m){
140  ERROR_REPORT;
141  std::cerr << "These two matrises can not make a product." << std::endl
142  << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl;
143  exit(1);
144  }
145 #endif//CPPL_DEBUG
146 
147  dgematrix newmat( matA.m, matB.n );
148  newmat.zero();
149 
150  for(CPPL_INT i=0; i<newmat.m; i++){
151  for(CPPL_INT j=0; j<newmat.n; j++){
152  const CPPL_INT kmax =std::min(matB.m,j+matB.kl+1);
153  for(CPPL_INT k=std::max(CPPL_INT(0),j-matB.ku); k<kmax; k++){
154  newmat(i,j) += matA(i,k)*matB(k,j);
155  }
156  }
157  }
158 
159  matB.destroy();
160  return _(newmat);
161 }
CPPL_INT m
matrix row size
Definition: dgematrix.hpp:9
CPPL_INT ku
upper band width
Definition: _dgbmatrix.hpp:12
void destroy() const
dgematrix & zero()
_dgematrix i(const _dgbmatrix &mat)
friend void swap(dgematrix &, dgematrix &)
double & operator()(const CPPL_INT &, const CPPL_INT &)
Definition: dgematrix-io.hpp:3
CPPL_INT n
matrix column size
Definition: dgematrix.hpp:10
Real Double-precision General Dence Matrix Class.
Definition: dgematrix.hpp:3
CPPL_INT kl
lower band width
Definition: _dgbmatrix.hpp:11
_dgematrix operator*(const dgematrix &matA, const _dgbmatrix &matB)
CPPL_INT n
matrix column size
Definition: _dgbmatrix.hpp:10
_dgematrix operator-(const dgematrix &matA, const _dgbmatrix &matB)
dgematrix & operator*=(const dgematrix &)
(DO NOT USE) Smart-temporary Real Double-precision General Dence Matrix Class
Definition: _dgematrix.hpp:3
_dgematrix operator+(const dgematrix &matA, const _dgbmatrix &matB)
(DO NOT USE) Smart-temporary Real Double-precision General Band Matrix Class
Definition: _dgbmatrix.hpp:3
dgematrix & operator-=(const dgematrix &)
friend _dgematrix i(const dgematrix &)
dgematrix & operator+=(const dgematrix &)
_dcovector _(dcovector &vec)
CPPL_INT m
matrix row size
Definition: _dgbmatrix.hpp:9