예제 #1
0
/*! _dgbmatrix*_dgbmatrix operator */
inline _dgbmatrix operator*(const _dgbmatrix& matA, const _dgbmatrix& matB)
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(matA.n!=matB.m){
    ERROR_REPORT;
    std::cerr << "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
  
  dgbmatrix newmat( matA.m, matB.n, std::min(matA.kl+matB.kl,matA.m-1), std::min(matA.ku+matB.ku,matB.n-1) );
  newmat.zero();
  
  for(long i=0; i<newmat.m; i++){
    for(long j=std::max(long(0),i-newmat.kl); j<std::min(newmat.n,i+newmat.ku+1); j++){
      for(long k=std::max( std::max(long(0),i-matA.kl), std::max(long(0),j-matB.ku) );
          k< std::min( std::min(matA.n,i+matA.ku+1), std::min(matB.m,j+matB.kl+1) ); k++){
        newmat(i,j)+= matA(i,k)*matB(k,j);
      }
    }
  }
  
  matA.destroy();
  matB.destroy();
  return _(newmat);
}
예제 #2
0
/*! _dgbmatrix+_dgbmatrix operator */
inline _dgbmatrix operator+(const _dgbmatrix& matA, const _dgbmatrix& matB)
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(matA.n!=matB.n || matA.m!=matB.m){
    ERROR_REPORT;
    std::cerr << "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
  
  if(matA.kl>matB.kl && matA.ku>matB.ku){
    for(long i=0; i<matB.m; i++){
      for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
        matA(i,j)+=matB(i,j);
      }
    }
    
    matB.destroy();
    return matA;
  }

  else if(matB.kl>matA.kl && matB.ku>matA.ku){
    for(long i=0; i<matA.m; i++){
      for(long j=std::max(long(0),i-matA.kl); j<std::min(matA.n,i+matA.ku+1); j++){
        matB(i,j)+=matA(i,j);
      }
    }
    
    matA.destroy();
    return matB;
  }
  
  else{
    dgbmatrix newmat(matA.m,matA.n,std::max(matA.kl,matB.kl),std::max(matA.ku,matB.ku));
    newmat.zero();
    
    for(long i=0; i<matA.m; i++){
      for(long j=std::max(long(0),i-matA.kl); j<std::min(matA.n,i+matA.ku+1); j++){
        newmat(i,j)+=matA(i,j);
      }
      for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
        newmat(i,j)+=matB(i,j);
      }
    }
    
    matA.destroy();
    matB.destroy();
    return _(newmat);
  }
}
/*! _dsymatrix*_dgbmatrix operator */
inline _dgematrix operator*(const _dsymatrix& matA, const _dgbmatrix& matB)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator*(const _dsymatrix&, const _dgbmatrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(matA.N!=matB.M){
    std::cerr << "[ERROR] operator*(_dsymatrix&, _dgbmatrix&)" << std::endl
              << "These two matrises can not make a product." << std::endl
              << "Your input was (" << matA.N << "x" << matA.N << ") * ("
              << matB.M << "x" << matB.N << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  dgematrix newmat( matA.N, matB.N );
  newmat.zero();
  
  long i, j, k;
  for(i=0; i<newmat.m; i++){
    for(j=0; j<newmat.n; j++){
      for(k=max(0,j-matB.KU); k<min(matB.M,j+matB.KL+1); k++){
        newmat(i,j)+=matA(i,k)*matB(k,j);
      }
    }
  }
  
  matA.destroy();
  matB.destroy();
  return _(newmat);
}
/*! _dsymatrix-_dgbmatrix operator */
inline _dgematrix operator-(const _dsymatrix& matA, const _dgbmatrix& matB)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator-(const _dsymatrix&, const _dgbmatrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(matA.N!=matB.N || matA.N!=matB.M){
    std::cerr << "[ERROR] operator+(_dsymatrix&, _dgbmatrix&)" << std::endl
              << "These two matrises can not make a summation." << std::endl
              << "Your input was (" << matA.N << "x" << matA.N << ") + ("
              << matB.M << "x" << matB.N << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  dgematrix newmat(matA.N, matA.N);
  for(long i=0; i<matB.M; i++){
    for(long j=i; j<matA.N; j++){
      newmat(i,j) = newmat(j,i) = matA(i,j);
    }
    for(long j=max(0,i-matB.KL); j<min(matB.N,i+matB.KU+1); j++){
      newmat(i,j) -= matB(i,j);
    }
  }

  matA.destroy();
  matB.destroy();
  return _(newmat);
}
/*! _dgbmatrix*_dcovector operator */
inline _dcovector operator*(const _dgbmatrix& mat, const _dcovector& vec)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator*(const _dgbmatrix&, const _dcovector&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(mat.N!=vec.L){
    std::cerr << "[ERROR] operator*(const _dgbmatrix&, const _dcovector&)"
              << std::endl
              << "These matrix and vector can not make a product." << std::endl
              << "Your input was (" << mat.M << "x" << mat.N << ") * ("
              << vec.L << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  dcovector newvec(mat.M);
  dgbmv_( 'N', mat.M, mat.N, mat.KL, mat.KU, 1.0, mat.Array,
          mat.KL+mat.KU+1, vec.Array, 1, 0.0, newvec.array, 1 );
  
  mat.destroy();
  vec.destroy();
  return _(newvec);
}
/*! dssmatrix*_dgbmatrix operator */
inline _dgematrix operator*(const dssmatrix& matA, const _dgbmatrix& matB)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator*(const dssmatrix&, const _dgbmatrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(matA.N!=matB.M){
    std::cerr << "[ERROR] operator*(const dssmatrix&, const _dgbmatrix&)"
              << 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<matA.VOL; c++){
    for(long j=max(0,matA.Jndx[c]-matB.KL);
        j<min(matB.N,matA.Jndx[c]+matB.KU+1); j++){
      newmat(matA.Indx[c],j) += matA.Array[c]*matB(matA.Jndx[c],j);
    }
  }
  
  matB.destroy();
  return _(newmat);
}
예제 #7
0
/*! return its transposed dgbmatrix */
inline _dgbmatrix t(const _dgbmatrix& mat)
{VERBOSE_REPORT;
  dgbmatrix newmat(mat.n, mat.m, mat.ku, mat.kl);
  
  for(long i=0; i<newmat.m; i++){
    for(long j=std::max(long(0),i-newmat.kl); j<std::min(newmat.n,i+newmat.ku+1); j++){
      newmat(i,j) =mat(j,i);
    }
  }
  
  mat.destroy();
  return _(newmat);
}
예제 #8
0
/*! return its transposed dgbmatrix */
inline _dgbmatrix t(const _dgbmatrix& mat)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] t(const _dgbmatrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
  dgbmatrix newmat(mat.N, mat.M, mat.KU, mat.KL);
  for(long i=0; i<newmat.m; i++){
    for(long j=max(0,i-newmat.kl); j<min(newmat.n,i+newmat.ku+1); j++){
      newmat(i,j) =mat(j,i);
    }
  }
  
  mat.destroy();
  return _(newmat);
}
예제 #9
0
/*! _drovector*_dgbmatrix operator */
inline _drovector operator*(const _drovector& vec, const _dgbmatrix& mat)
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(vec.l!=mat.m){
    ERROR_REPORT;
    std::cerr << "These vector and matrix can not make a product." << std::endl
              << "Your input was (" << vec.l << ") * (" << mat.m << "x" << mat.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  drovector newvec(mat.n);
  
  dgbmv_( 'T', mat.m, mat.n, mat.kl, mat.ku, 1.0, mat.array, mat.kl+mat.ku+1, vec.array, 1, 0.0, newvec.array, 1 );
  
  vec.destroy();
  mat.destroy();
  return _(newvec);
}
예제 #10
0
/*! dgsmatrix-_dgbmatrix operator */
inline _dgematrix operator-(const dgsmatrix& matA, const _dgbmatrix& matB)
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(matA.n!=matB.n || matA.m!=matB.m){
    ERROR_REPORT;
    std::cerr << "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( matA.to_dgematrix() );
  
  for(long i=0; i<matB.m; i++){
    for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
      newmat(i,j)-=matB(i,j);
    }
  }
  
  matB.destroy();
  return _(newmat);
}
예제 #11
0
/*! dgsmatrix*_dgbmatrix operator */
inline _dgematrix operator*(const dgsmatrix& matA, const _dgbmatrix& matB)
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(matA.n!=matB.m){
    ERROR_REPORT;
    std::cerr << "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(std::vector<dcomponent>::const_iterator it=matA.data.begin(); it!=matA.data.end(); it++){
    for(long j=std::max(long(0),long(it->j)-matB.kl); j<std::min(matB.n,long(it->j)+matB.ku+1); j++){
      newmat(it->i,j) += it->v*matB(it->j,j);
    }
  }
  
  matB.destroy();
  return _(newmat);
}