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