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 operator+(const _dgbmatrix& matA, const _dgbmatrix& matB)
00004 {VERBOSE_REPORT;
00005 #ifdef  CPPL_DEBUG
00006   if(matA.n!=matB.n || matA.m!=matB.m){
00007     ERROR_REPORT;
00008     std::cerr << "These two matrises can not make a summation." << std::endl
00009               << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.m << "x" << matB.n << ")." << std::endl;
00010     exit(1);
00011   }
00012 #endif//CPPL_DEBUG
00013   
00014   if(matA.kl>matB.kl && matA.ku>matB.ku){
00015     for(long i=0; i<matB.m; i++){
00016       for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
00017         matA(i,j)+=matB(i,j);
00018       }
00019     }
00020     
00021     matB.destroy();
00022     return matA;
00023   }
00024 
00025   else if(matB.kl>matA.kl && matB.ku>matA.ku){
00026     for(long i=0; i<matA.m; i++){
00027       for(long j=std::max(long(0),i-matA.kl); j<std::min(matA.n,i+matA.ku+1); j++){
00028         matB(i,j)+=matA(i,j);
00029       }
00030     }
00031     
00032     matA.destroy();
00033     return matB;
00034   }
00035   
00036   else{
00037     dgbmatrix newmat(matA.m,matA.n,std::max(matA.kl,matB.kl),std::max(matA.ku,matB.ku));
00038     newmat.zero();
00039     
00040     for(long i=0; i<matA.m; i++){
00041       for(long j=std::max(long(0),i-matA.kl); j<std::min(matA.n,i+matA.ku+1); j++){
00042         newmat(i,j)+=matA(i,j);
00043       }
00044       for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
00045         newmat(i,j)+=matB(i,j);
00046       }
00047     }
00048     
00049     matA.destroy();
00050     matB.destroy();
00051     return _(newmat);
00052   }
00053 }
00054 
00055 //=============================================================================
00056 /*! _dgbmatrix-_dgbmatrix operator */
00057 inline _dgbmatrix operator-(const _dgbmatrix& matA, const _dgbmatrix& matB)
00058 {VERBOSE_REPORT;
00059 #ifdef  CPPL_DEBUG
00060   if(matA.n!=matB.n || matA.m!=matB.m){
00061     ERROR_REPORT;
00062     std::cerr << "These two matrises can not make a subtraction." << std::endl
00063               << "Your input was (" << matA.m << "x" << matA.n << ") - (" << matB.m << "x" << matB.n << ")." << std::endl;
00064     exit(1);
00065   }
00066 #endif//CPPL_DEBUG
00067   
00068   if(matA.kl>matB.kl && matA.ku>matB.ku){
00069     for(long i=0; i<matB.m; i++){
00070       for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
00071         matA(i,j)-=matB(i,j);
00072       }
00073     }
00074     
00075     matB.destroy();
00076     return matA;
00077   }
00078   
00079   else{
00080     dgbmatrix newmat(matA.m,matA.n,std::max(matA.kl,matB.kl),std::max(matA.ku,matB.ku));
00081     newmat.zero();
00082     
00083     for(long i=0; i<matA.m; i++){
00084       for(long j=std::max(long(0),i-matA.kl); j<std::min(matA.n,i+matA.ku+1); j++){
00085         newmat(i,j)+=matA(i,j);
00086       }
00087       for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
00088         newmat(i,j)-=matB(i,j);
00089       }
00090     }
00091     
00092     matA.destroy();
00093     matB.destroy();
00094     return _(newmat);
00095   }
00096 }
00097 
00098 //=============================================================================
00099 /*! _dgbmatrix*_dgbmatrix operator */
00100 inline _dgbmatrix operator*(const _dgbmatrix& matA, const _dgbmatrix& matB)
00101 {VERBOSE_REPORT;
00102 #ifdef  CPPL_DEBUG
00103   if(matA.n!=matB.m){
00104     ERROR_REPORT;
00105     std::cerr << "These two matrises can not make a product." << std::endl
00106               << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl;
00107     exit(1);
00108   }
00109 #endif//CPPL_DEBUG
00110   
00111   dgbmatrix newmat( matA.m, matB.n, std::min(matA.kl+matB.kl,matA.m-1), std::min(matA.ku+matB.ku,matB.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-matA.kl), std::max(long(0),j-matB.ku) );
00117           k< std::min( std::min(matA.n,i+matA.ku+1), std::min(matB.m,j+matB.kl+1) ); k++){
00118         newmat(i,j)+= matA(i,k)*matB(k,j);
00119       }
00120     }
00121   }
00122   
00123   matA.destroy();
00124   matB.destroy();
00125   return _(newmat);
00126 }
 All Classes Files Functions Variables Friends