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