Example #1
0
/*! return its largest absolute value */
inline double damax(const _dgematrix& mat)
{   VERBOSE_REPORT;
    double val( mat.array[idamax_(mat.m*mat.n, mat.array, 1) -1] );

    mat.destroy();
    return val;
}
/*! _dgbmatrix*_dgematrix operator */
inline _dgematrix operator*(const _dgbmatrix& matA, const _dgematrix& matB)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator*(const _dgbmatrix&, const _dgematrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(matA.N!=matB.M){
    std::cerr << "[ERROR] operator*(_dgbmatrix&, _dgematrix&)" << 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();
  
  long i, j, k;
  for(i=0; i<newmat.m; i++){
    for(j=0; j<newmat.n; j++){
      for(k=max(0,i-matA.KL); k<min(matA.N,i+matA.KU+1); k++){
        newmat(i,j)+=matA(i,k)*matB(k,j);
      }
    }
  }
  
  matA.destroy();
  matB.destroy();
  return _(newmat);
}
/*! _dgematrix*dcovector operator */
inline _dcovector operator*(const _dgematrix& mat, const dcovector& vec)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator*(const _dgematrix&, const dcovector&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(mat.N!=vec.L){
    std::cerr << "[ERROR] operator*(const _dgematrix&, 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);
  dgemv_( 'N', mat.M, mat.N, 1.0, mat.Array, mat.M,
          vec.Array, 1, 0.0, newvec.array, 1 );
  
  mat.destroy();
  return _(newvec);
}
/*! dssmatrix*_dgematrix operator */
inline _dgematrix operator*(const dssmatrix& matA, const _dgematrix& matB)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator*(const dssmatrix&, const _dgematrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(matA.N!=matB.M){
    std::cerr << "[ERROR] operator*(const dssmatrix&, 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(long c=0; c<matA.VOL; c++){
    for(long j=0; j<matB.N; j++){
      newmat(matA.Indx[c],j) += matA.Array[c]*matB(matA.Jndx[c],j);
    }
  }
  
  matB.destroy();
  return _(newmat);
}
Example #5
0
/*! search the index of element having the largest absolute value
  in 0-based numbering system */
inline void idamax(long& i, long& j, const _dgematrix& mat)
{   VERBOSE_REPORT;
    long index( idamax_(mat.m*mat.n, mat.array, 1) -1 );
    i =index%mat.m;
    j =index/mat.m;

    mat.destroy();
}
Example #6
0
/*! make a shallow copy of the matrix\n
  This function is not designed to be used in project codes. */
inline void dgematrix::shallow_copy(const _dgematrix& mat)
{   VERBOSE_REPORT;
    m =mat.m;
    n =mat.n;
    delete [] array;
    array =mat.array;
    delete [] darray;
    darray =mat.darray;

    mat.nullify();
}
Example #7
0
/*! return transposed dgematrix */
inline _dgematrix t(const _dgematrix& mat)
{   VERBOSE_REPORT;
    dgematrix newmat(mat.n,mat.m);

    for(long i=0; i<newmat.m; i++) {
        for(long j=0; j<newmat.n; j++) {
            newmat(i,j) =mat(j,i);
        }
    }

    mat.destroy();
    return _(newmat);
}
/*! _dgematrix*dgematrix operator */
inline _dgematrix operator*(const _dgematrix& matA, const dgematrix& 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 );
  dgemm_( 'n', 'n', matA.m, matB.n, matA.n, 1.0, matA.array, matA.m,
          matB.array, matB.m, 0.0, newmat.array, matA.m );
  
  matA.destroy();
  return _(newmat);
}
/*! _drovector*_dgematrix operator */
inline _drovector operator*(const _drovector& vec, const _dgematrix& 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);

    dgemv_( 'T', mat.m, mat.n, 1.0, mat.array, mat.m, vec.array, 1, 0.0, newvec.array, 1 );

    vec.destroy();
    mat.destroy();
    return _(newvec);
}
Example #10
0
/*! _dgematrix*dgsmatrix operator */
inline _dgematrix operator*(const _dgematrix& matA, const dgsmatrix& 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=matB.data.begin(); it!=matB.data.end(); it++){
    for(long i=0; i<matA.m; i++){
      newmat(i,it->j) += matA(i,it->i)*it->v;
    }
  }
  
  matA.destroy();
  return _(newmat);
}