CPPLapack
 All Classes Files Functions Variables Friends
dgsmatrix-dgsmatrix.hpp
Go to the documentation of this file.
00001 //=============================================================================
00002 /*! dgsmatrix=dgsmatrix operator */
00003 inline dgsmatrix& dgsmatrix::operator=(const dgsmatrix& mat)
00004 {VERBOSE_REPORT;
00005   if(&data!=&mat.data){ // if it is NOT self substitution
00006     copy(mat);
00007   }
00008   return *this;
00009 }
00010 
00011 ///////////////////////////////////////////////////////////////////////////////
00012 ///////////////////////////////////////////////////////////////////////////////
00013 ///////////////////////////////////////////////////////////////////////////////
00014 
00015 //=============================================================================
00016 /*! dgsmatrix+=dgsmatrix operator */
00017 inline dgsmatrix& dgsmatrix::operator+=(const dgsmatrix& mat)
00018 {VERBOSE_REPORT;
00019 #ifdef  CPPL_DEBUG
00020   if(n!=mat.n || m!=mat.m){
00021     ERROR_REPORT;
00022     std::cerr << "These two matrises can not make a summation." << std::endl
00023               << "Your input was (" << m << "x" << n << ") += (" << mat.m << "x" << mat.n << ")." << std::endl;
00024     exit(1);
00025   }
00026 #endif//CPPL_DEBUG
00027   
00028   for(std::vector<dcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
00029     (*this)(it->i,it->j) +=it->v;
00030   }
00031   return *this;
00032 }
00033 
00034 //=============================================================================
00035 /*! dgsmatrix-=dgsmatrix operator */
00036 inline dgsmatrix& dgsmatrix::operator-=(const dgsmatrix& mat)
00037 {VERBOSE_REPORT;
00038 #ifdef  CPPL_DEBUG
00039   if(n!=mat.n || m!=mat.m){
00040     ERROR_REPORT;
00041     std::cerr << "These two matrises can not make a sutraction." << std::endl
00042               << "Your input was (" << m << "x" << n << ") -= (" << mat.m << "x" << mat.n << ")." << std::endl;
00043     exit(1);
00044   }
00045 #endif//CPPL_DEBUG
00046   
00047   for(std::vector<dcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
00048     (*this)(it->i,it->j) -=it->v;
00049   }
00050   return *this;
00051 }
00052 
00053 //=============================================================================
00054 /*! dgsmatrix*=dgsmatrix operator */
00055 inline dgsmatrix& dgsmatrix::operator*=(const dgsmatrix& mat)
00056 {VERBOSE_REPORT;
00057 #ifdef  CPPL_DEBUG
00058   if(n!=mat.m){
00059     ERROR_REPORT;
00060     std::cerr << "These two matrises can not make a product." << std::endl
00061               << "Your input was (" << m << "x" << n << ") *= (" << mat.m << "x" << mat.n << ")." << std::endl;
00062     exit(1);
00063   }
00064 #endif//CPPL_DEBUG
00065   
00066   dgsmatrix newmat(m, mat.n);
00067   newmat.zero();
00068   
00069   for(std::vector<dcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
00070     long k(it->j);
00071     std::vector<uint32_t>::const_iterator p;
00072     for(p=mat.rows[k].begin(); p!=mat.rows[k].end(); p++){
00073       newmat(it->i,mat.data[*p].j) +=it->v*mat.data[*p].v;
00074     }
00075   }
00076   
00077   swap(*this,newmat);
00078   return *this;
00079 }
00080 
00081 ///////////////////////////////////////////////////////////////////////////////
00082 ///////////////////////////////////////////////////////////////////////////////
00083 ///////////////////////////////////////////////////////////////////////////////
00084 
00085 //=============================================================================
00086 /*! dgsmatrix+dgsmatrix operator */
00087 inline _dgsmatrix operator+(const dgsmatrix& matA, const dgsmatrix& matB)
00088 {VERBOSE_REPORT;
00089 #ifdef  CPPL_DEBUG
00090   if(matA.n!=matB.n || matA.m!=matB.m){
00091     ERROR_REPORT;
00092     std::cerr << "These two matrises can not make a summation." << std::endl
00093               << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.m << "x" << matB.n << ")." << std::endl;
00094     exit(1);
00095   }
00096 #endif//CPPL_DEBUG
00097   
00098   dgsmatrix newmat(matA);
00099   for(std::vector<dcomponent>::const_iterator it=matB.data.begin(); it!=matB.data.end(); it++){
00100     newmat(it->i, it->j) +=it->v;
00101   }
00102   return _(newmat);
00103 }
00104 
00105 //=============================================================================
00106 /*! dgsmatrix-dgsmatrix operator */
00107 inline _dgsmatrix operator-(const dgsmatrix& matA, const dgsmatrix& matB)
00108 {VERBOSE_REPORT;
00109 #ifdef  CPPL_DEBUG
00110   if(matA.n!=matB.n || matA.m!=matB.m){
00111     ERROR_REPORT;
00112     std::cerr << "These two matrises can not make a subtraction." << std::endl
00113               << "Your input was (" << matA.m << "x" << matA.n << ") - (" << matB.m << "x" << matB.n << ")." << std::endl;
00114     exit(1);
00115   }
00116 #endif//CPPL_DEBUG
00117 
00118   dgsmatrix newmat(matA);
00119   for(std::vector<dcomponent>::const_iterator it=matB.data.begin(); it!=matB.data.end(); it++){
00120     newmat(it->i, it->j) -=it->v;
00121   }
00122   return _(newmat);
00123 }
00124 
00125 //=============================================================================
00126 /*! dgsmatrix*dgsmatrix operator */
00127 inline _dgsmatrix operator*(const dgsmatrix& matA, const dgsmatrix& matB)
00128 {VERBOSE_REPORT;
00129 #ifdef  CPPL_DEBUG
00130   if(matA.n!=matB.m){
00131     ERROR_REPORT;
00132     std::cerr << "These two matrises can not make a product." << std::endl
00133               << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl;
00134     exit(1);
00135   }
00136 #endif//CPPL_DEBUG
00137   
00138   dgsmatrix newmat( matA.m, matB.n );
00139   
00140   for(std::vector<dcomponent>::const_iterator it=matA.data.begin(); it!=matA.data.end(); it++){
00141     long k(it->j);
00142     std::vector<uint32_t>::const_iterator p;
00143     for(p=matB.rows[k].begin(); p!=matB.rows[k].end(); p++){
00144       newmat(it->i,matB.data[*p].j) +=it->v*matB.data[*p].v;
00145     }
00146   }
00147   
00148   return _(newmat);
00149 }
 All Classes Files Functions Variables Friends