CPPLapack
 All Classes Files Functions Variables Friends
dgsmatrix-_dgematrix.hpp
Go to the documentation of this file.
00001 //=============================================================================
00002 /*! dgsmatrix+_dgematrix operator */
00003 inline _dgematrix operator+(const dgsmatrix& matA, const _dgematrix& matB)
00004 {VERBOSE_REPORT;
00005 #ifdef  CPPL_DEBUG
00006   if(matA.m!=matB.m || matA.n!=matB.n){
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   for(std::vector<dcomponent>::const_iterator it=matA.data.begin(); it!=matA.data.end(); it++){
00015     matB(it->i,it->j) += it->v;
00016   }
00017   return matB;
00018 }
00019 
00020 //=============================================================================
00021 /*! dgsmatrix-_dgematrix operator */
00022 inline _dgematrix operator-(const dgsmatrix& matA, const _dgematrix& matB)
00023 {VERBOSE_REPORT;
00024 #ifdef  CPPL_DEBUG
00025   if(matA.m!=matB.m || matA.n!=matB.n){
00026     ERROR_REPORT;
00027     std::cerr << "These two matrises can not make a subtraction." << std::endl
00028               << "Your input was (" << matA.m << "x" << matA.n << ") - (" << matB.m << "x" << matB.n << ")." << std::endl;
00029     exit(1);
00030   }
00031 #endif//CPPL_DEBUG
00032   
00033   //// change sign ////
00034   for(long i=0; i<matB.m*matB.n; i++){
00035     matB.array[i]=-matB.array[i];
00036   }
00037   
00038   //// add ////
00039   for(std::vector<dcomponent>::const_iterator it=matA.data.begin(); it!=matA.data.end(); it++){
00040     matB(it->i,it->j) += it->v;
00041   }
00042   
00043   return matB;
00044 }
00045 
00046 //=============================================================================
00047 /*! dgsmatrix*_dgematrix operator */
00048 inline _dgematrix operator*(const dgsmatrix& matA, const _dgematrix& matB)
00049 {VERBOSE_REPORT;
00050 #ifdef  CPPL_DEBUG
00051   if(matA.n!=matB.m){
00052     ERROR_REPORT;
00053     std::cerr << "These two matrises can not make a product." << std::endl
00054               << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl;
00055     exit(1);
00056   }
00057 #endif//CPPL_DEBUG
00058   
00059   dgematrix newmat(matA.m, matB.n);
00060   newmat.zero();
00061   
00062   for(std::vector<dcomponent>::const_iterator it=matA.data.begin(); it!=matA.data.end(); it++){
00063     for(long j=0; j<matB.n; j++){
00064       newmat(it->i,j) += it->v *matB(it->j,j);
00065     }
00066   }
00067   
00068   matB.destroy();
00069   return _(newmat);
00070 }
 All Classes Files Functions Variables Friends