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