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