CPPLapack
 All Classes Files Functions Variables Friends
dgbmatrix-dgbmatrix.hpp
Go to the documentation of this file.
00001 //=============================================================================
00002 /*! dgbmatrix=dgbmatrix operator\n
00003   The left side matrix is overwritten thoroughly including band width. */
00004 inline dgbmatrix& dgbmatrix::operator=(const dgbmatrix& mat)
00005 {VERBOSE_REPORT;
00006   if(array!=mat.array){ // if it is NOT self substitution
00007     copy(mat);
00008   }
00009   return *this;
00010 }
00011 
00012 ///////////////////////////////////////////////////////////////////////////////
00013 ///////////////////////////////////////////////////////////////////////////////
00014 ///////////////////////////////////////////////////////////////////////////////
00015 
00016 //=============================================================================
00017 /*! dgbmatrix+=dgbmatrix operator\n
00018   If the band width of the left side matrix is narrower than the right side matrix, the band width of the left side matrix become thicker as same as the right side matrix. */
00019 inline dgbmatrix& dgbmatrix::operator+=(const dgbmatrix& mat)
00020 {VERBOSE_REPORT;
00021 #ifdef  CPPL_DEBUG
00022   if(n!=mat.n || m!=mat.m){
00023     ERROR_REPORT;
00024     std::cerr << "These two matrises can not make a summation." << std::endl
00025               << "Your input was" << "(" << m <<"x"<< n <<","<< kl <<":"<< ku << ") "<< "+=" << "("<< mat.m <<"x"<< mat.n <<","<< mat.kl <<":"<< mat.ku <<") " << std::endl;
00026     exit(1);
00027   }
00028 #endif//CPPL_DEBUG
00029   
00030   if(kl>=mat.kl && ku>=mat.ku){
00031     for(long i=0; i<m; i++){
00032       for(long j=std::max(long(0),i-mat.kl); j<std::min(n,i+mat.ku+1); j++){
00033         operator()(i,j)+=mat(i,j);
00034       }
00035     }
00036     
00037     return *this;
00038   }
00039   
00040   else{
00041     dgbmatrix newmat(m,n,std::max(kl,mat.kl),std::max(ku,mat.ku));
00042     newmat.zero();
00043     for(long i=0; i<m; i++){
00044       for(long j=std::max(long(0),i-kl); j<std::min(n,i+ku+1); j++){
00045         newmat(i,j)+=operator()(i,j);
00046       }
00047       for(long j=std::max(long(0),i-mat.kl); j<std::min(mat.n,i+mat.ku+1); j++){
00048         newmat(i,j)+=mat(i,j);
00049       }
00050     }
00051     
00052     swap(*this,newmat);
00053     return *this;
00054   }
00055 }
00056 
00057 //=============================================================================
00058 /*! dgbmatrix-=dgbmatrix operator\n
00059   If the band width of the left side matrix is narrower than the right side matrix, the band width of the left side matrix become thicker as same as the right side matrix. */
00060 inline dgbmatrix& dgbmatrix::operator-=(const dgbmatrix& mat)
00061 {VERBOSE_REPORT;
00062 #ifdef  CPPL_DEBUG
00063   if(n!=mat.n || m!=mat.m){
00064     ERROR_REPORT;
00065     std::cerr << "These two matrises can not make a subtraction." << std::endl
00066               << "Your input was" << "(" << m <<"x"<< n <<","<< kl <<":"<< ku << ") "<< "-=" << "("<< mat.m <<"x"<< mat.n <<","<< mat.kl <<":"<< mat.ku <<") " << std::endl;
00067     exit(1);
00068   }
00069 #endif//CPPL_DEBUG
00070   
00071   if(kl>=mat.kl && ku>=mat.ku){
00072     for(long i=0; i<m; i++){
00073       for(long j=std::max(long(0),i-mat.kl); j<std::min(n,i+mat.ku+1); j++){
00074         operator()(i,j)-=mat(i,j);
00075       }
00076     }
00077     
00078     return *this;
00079   }
00080   
00081   else{
00082     dgbmatrix newmat(m,n,std::max(kl,mat.kl),std::max(ku,mat.ku));
00083     newmat.zero();
00084     for(long i=0; i<m; i++){
00085       for(long j=std::max(long(0),i-kl); j<std::min(n,i+ku+1); j++){
00086         newmat(i,j)+=operator()(i,j);
00087       }
00088       for(long j=std::max(long(0),i-mat.kl); j<std::min(mat.n,i+mat.ku+1); j++){
00089         newmat(i,j)-=mat(i,j);
00090       }
00091     }
00092     
00093     swap(*this,newmat);
00094     return *this;
00095   }
00096 }
00097 
00098 //=============================================================================
00099 /*! dgbmatrix*=dgbmatrix operator */
00100 inline dgbmatrix& dgbmatrix::operator*=(const dgbmatrix& mat)
00101 {VERBOSE_REPORT;
00102 #ifdef  CPPL_DEBUG
00103   if(n!=mat.m){
00104     ERROR_REPORT;
00105     std::cerr << "These two matrises can not make a product." << std::endl
00106               << "Your input was (" << m << "x" << n << ") * (" << mat.m << "x" << mat.n << ")." << std::endl;
00107     exit(1);
00108   }
00109 #endif//CPPL_DEBUG
00110   
00111   dgbmatrix newmat( m, mat.n, std::min(kl+mat.kl, m-1), std::min(ku+mat.ku, mat.n-1) );
00112   newmat.zero();
00113   
00114   for(long i=0; i<newmat.m; i++){
00115     for(long j=std::max(long(0),i-newmat.kl); j<std::min(newmat.n,i+newmat.ku+1); j++){
00116       for(long k=std::max( std::max(long(0),i-kl), std::max(long(0),j-mat.ku) );
00117           k< std::min( std::min(n,i+ku+1), std::min(mat.m,j+mat.kl+1) ); k++){
00118         newmat(i,j)+= operator()(i,k)*mat(k,j);
00119       }
00120     }
00121   }
00122   
00123   swap(*this,newmat);
00124   return *this;
00125 }
00126 
00127 ///////////////////////////////////////////////////////////////////////////////
00128 ///////////////////////////////////////////////////////////////////////////////
00129 ///////////////////////////////////////////////////////////////////////////////
00130 
00131 //=============================================================================
00132 /*! dgbmatrix+dgbmatrix operator */
00133 inline _dgbmatrix operator+(const dgbmatrix& matA, const dgbmatrix& matB)
00134 {VERBOSE_REPORT;
00135 #ifdef  CPPL_DEBUG
00136   if(matA.n!=matB.n || matA.m!=matB.m){
00137     ERROR_REPORT;
00138     std::cerr << "These two matrises can not make a summation." << std::endl
00139               << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.m << "x" << matB.n << ")." << std::endl;
00140     exit(1);
00141   }
00142 #endif//CPPL_DEBUG
00143   
00144   dgbmatrix newmat(matA.m,matA.n,std::max(matA.kl,matB.kl),std::max(matA.ku,matB.ku));
00145   newmat.zero();
00146   
00147   for(long i=0; i<matA.m; i++){
00148     for(long j=std::max(long(0),i-matA.kl); j<std::min(matA.n,i+matA.ku+1); j++){
00149       newmat(i,j)+=matA(i,j);
00150     }
00151     for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
00152       newmat(i,j)+=matB(i,j);
00153     }
00154   }
00155   
00156   return _(newmat);
00157 }
00158 
00159 //=============================================================================
00160 /*! dgbmatrix-dgbmatrix operator */
00161 inline _dgbmatrix operator-(const dgbmatrix& matA, const dgbmatrix& matB)
00162 {VERBOSE_REPORT;
00163 #ifdef  CPPL_DEBUG
00164   if(matA.n!=matB.n || matA.m!=matB.m){
00165     ERROR_REPORT;
00166     std::cerr << "These two matrises can not make a subtraction." << std::endl
00167               << "Your input was (" << matA.m << "x" << matA.n << ") - (" << matB.m << "x" << matB.n << ")." << std::endl;
00168     exit(1);
00169   }
00170 #endif//CPPL_DEBUG
00171   
00172   dgbmatrix newmat(matA.m,matA.n,std::max(matA.kl,matB.kl),std::max(matA.ku,matB.ku));
00173   newmat.zero();
00174   
00175   for(long i=0; i<matA.m; i++){
00176     for(long j=std::max(long(0),i-matA.kl); j<std::min(matA.n,i+matA.ku+1); j++){
00177       newmat(i,j)+=matA(i,j);
00178     }
00179     for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
00180       newmat(i,j)-=matB(i,j);
00181     }
00182   }
00183   
00184   return _(newmat);
00185 }
00186 
00187 //=============================================================================
00188 /*! dgbmatrix*dgbmatrix operator */
00189 inline _dgbmatrix operator*(const dgbmatrix& matA, const dgbmatrix& matB)
00190 {VERBOSE_REPORT;
00191 #ifdef  CPPL_DEBUG
00192   if(matA.n!=matB.m){
00193     ERROR_REPORT;
00194     std::cerr << "These two matrises can not make a product." << std::endl
00195               << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl;
00196     exit(1);
00197   }
00198 #endif//CPPL_DEBUG
00199   
00200   dgbmatrix newmat( matA.m, matB.n, std::min(matA.kl+matB.kl,matA.m-1), std::min(matA.ku+matB.ku,matB.n-1) );
00201   newmat.zero();
00202   
00203   for(long i=0; i<newmat.m; i++){
00204     for(long j=std::max(long(0),i-newmat.kl); j<std::min(newmat.n,i+newmat.ku+1); j++){
00205       for(long k=std::max( std::max(long(0),i-matA.kl), std::max(long(0),j-matB.ku) );
00206           k< std::min( std::min(matA.n,i+matA.ku+1), std::min(matB.m,j+matB.kl+1) ); k++){
00207         newmat(i,j)+= matA(i,k)*matB(k,j);
00208       }
00209     }
00210   }
00211   
00212   return _(newmat);
00213 }
 All Classes Files Functions Variables Friends