//=============================================================================
/*! _zgsmatrix+zgsmatrix operator */
inline _zgsmatrix operator+(const _zgsmatrix& matA, const zgsmatrix& matB)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] operator+(const _zgsmatrix&, const zgsmatrix&)"
<< std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if(matA.N!=matB.N || matA.M!=matB.M){
std::cerr << "[ERROR] operator+(const _zgsmatrix&, const zgsmatrix&)"
<< 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
zgsmatrix newmat(matA);
for(long c=0; c<matB.VOL; c++){
newmat(matB.Indx[c], matB.Jndx[c]) +=matB.Array[c];
}
return _(newmat);
}
//=============================================================================
/*! _zgsmatrix-zgsmatrix operator */
inline _zgsmatrix operator-(const _zgsmatrix& matA, const zgsmatrix& matB)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] operator-(const _zgsmatrix&, const zgsmatrix&)"
<< std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if(matA.N!=matB.N || matA.M!=matB.M){
std::cerr << "[ERROR] operator-(const _zgsmatrix&, const zgsmatrix&)"
<< std::endl
<< "These two matrises can not make a subtraction." << std::endl
<< "Your input was (" << matA.M << "x" << matA.N << ") - ("
<< matB.M << "x" << matB.N << ")." << std::endl;
exit(1);
}
#endif//CPPL_DEBUG
zgsmatrix newmat(matA);
for(long c=0; c<matB.VOL; c++){
newmat(matB.Indx[c], matB.Jndx[c]) -=matB.Array[c];
}
return _(newmat);
}
//=============================================================================
/*! _zgsmatrix*zgsmatrix operator */
inline _zgsmatrix operator*(const _zgsmatrix& matA, const zgsmatrix& matB)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] operator*(const _zgsmatrix&, const zgsmatrix&)"
<< std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if(matA.N!=matB.M){
std::cerr << "[ERROR] operator*(const _zgsmatrix&, const zgsmatrix&)"
<< std::endl
<< "These two matrises can not make a product." << std::endl
<< "Your input was (" << matA.M << "x" << matA.N << ") * ("
<< matB.M << "x" << matB.N << ")." << std::endl;
exit(1);
}
#endif//CPPL_DEBUG
zgsmatrix newmat( matA.M, matB.N, 0 );
for(long c=0; c<matA.VOL; c++){
long k(matA.Jndx[c]);
std::vector< std::pair<long,long> >::iterator p;
for(p=matB.Rows[k].begin(); p!=matB.Rows[k].end(); p++){
newmat(matA.Indx[c],p->first) +=matA.Array[c]*matB.Array[p->second];
}
}
matA.destroy();
return _(newmat);
}