//=============================================================================
/*! dgbmatrix+dgsmatrix operator */
inline _dgematrix operator+(const dgbmatrix& matA, const dgsmatrix& matB)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] operator+(const dgbmatrix&, const dgsmatrix&)"
<< std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if(matA.N!=matB.N || matA.M!=matB.M){
std::cerr << "[ERROR] operator+(const dgbmatrix&, const dgsmatrix&)"
<< 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(long i=0; i<matA.M; i++){
for(long j=max(0,i-matA.KL); j<min(matA.N,i+matA.KU+1); j++){
newmat(i,j)+=matA(i,j);
}
}
return _(newmat);
}
//=============================================================================
/*! dgbmatrix-dgsmatrix operator */
inline _dgematrix operator-(const dgbmatrix& matA, const dgsmatrix& matB)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] operator-(const dgbmatrix&, const dgsmatrix&)"
<< std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if(matA.N!=matB.N || matA.M!=matB.M){
std::cerr << "[ERROR] operator+(const dgbmatrix&, const dgsmatrix&)"
<< 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(long i=0; i<matA.M; i++){
for(long j=max(0,i-matA.KL); j<min(matA.N,i+matA.KU+1); j++){
newmat(i,j)-=matA(i,j);
}
}
return _(newmat);
}
//=============================================================================
/*! dgbmatrix*dgsmatrix operator */
inline _dgematrix operator*(const dgbmatrix& matA, const dgsmatrix& matB)
{
#ifdef CPPL_VERBOSE
std::cerr << "# [MARK] operator*(const dgbmatrix&, const dgsmatrix&)"
<< std::endl;
#endif//CPPL_VERBOSE
#ifdef CPPL_DEBUG
if(matA.N!=matB.M){
std::cerr << "[ERROR] operator*(const dgbmatrix&, const dgsmatrix&)"
<< 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
dgematrix newmat( matA.M, matB.N );
newmat.zero();
for(long c=0; c<matB.VOL; c++){
for(long i=max(0,matB.Indx[c]-(matA.KU+1));
i<min(matA.M,matB.Indx[c]+matA.KL); i++){
newmat(i,matB.Jndx[c]) += matA(i,matB.Indx[c])*matB.Array[c];
}
}
return _(newmat);
}