//=============================================================================
/*! dgsmatrix+dgematrix operator */
inline _dgematrix operator+(const dgsmatrix& matA, const dgematrix& matB)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] operator+(const dgsmatrix&, const dgematrix&)" << std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if(matA.M!=matB.M || matA.N!=matB.N){
std::cerr << "[ERROR] operator+(const dgsmatrix&, const dgematrix&)" << std::endl
<< "These two matrises can not make a summation." << std::endl
<< "Your input was (" << matA.M << "x" << matA.N << ") + (" << matB.M << "x" << matB.N << ")." << std::endl;
exit(1);
}
#endif//CPPL_DEBUG
dgematrix newmat(matB);
for(std::vector<dcomponent>::const_iterator it=matA.Data.begin(); it!=matA.Data.end(); it++){
newmat(it->i,it->j) += it->v;
}
return _(newmat);
}
//=============================================================================
/*! dgsmatrix-dgematrix operator */
inline _dgematrix operator-(const dgsmatrix& matA, const dgematrix& matB)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] operator-(const dgsmatrix&, const dgematrix&)" << std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if(matA.M!=matB.M || matA.N!=matB.N){
std::cerr << "[ERROR] operator-(const dgsmatrix&, const dgematrix&)" << std::endl
<< "These two matrises can not make a subtraction." << std::endl
<< "Your input was (" << matA.M << "x" << matA.N << ") - (" << matB.N << "x" << matB.N << ")." << std::endl;
exit(1);
}
#endif//CPPL_DEBUG
dgematrix newmat(-matB);
for(std::vector<dcomponent>::const_iterator it=matA.Data.begin(); it!=matA.Data.end(); it++){
newmat(it->i,it->j) += it->v;
}
return _(newmat);
}
//=============================================================================
/*! dgsmatrix*dgematrix operator */
inline _dgematrix operator*(const dgsmatrix& matA, const dgematrix& matB)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] operator*(const dgsmatrix&, const dgematrix&)" << std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if(matA.N!=matB.M){
std::cerr << "[ERROR] operator*(const dgsmatrix&, const dgematrix&)" << std::endl
<< "These two matrises can not make a product." << std::endl
<< "Your input was (" << matA.M << "x" << matA.N << ") * (" << matB.N << "x" << matB.N << ")." << std::endl;
exit(1);
}
#endif//CPPL_DEBUG
dgematrix newmat(matA.M, matB.N);
newmat.zero();
for(std::vector<dcomponent>::const_iterator it=matA.Data.begin(); it!=matA.Data.end(); it++){
for(long j=0; j<matB.N; j++){
newmat(it->i,j) += it->v*matB(it->j,j);
}
}
return _(newmat);
}