/*! _zssmatrix*_zgbmatrix operator */
inline _zgematrix operator*(const _zssmatrix& matA, const _zgbmatrix& matB)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator*(const _zssmatrix&, const _zgbmatrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(matA.N!=matB.M){
    std::cerr << "[ERROR] operator*(const _zssmatrix&, const _zgbmatrix&)"
              << 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
  
  zgematrix newmat( matA.M, matB.N );
  newmat.zero();
  
  for(long c=0; c<matA.VOL; c++){
    for(long k=max(0,matA.Jndx[c]-matB.KU);
        k<min(matB.M,matA.Jndx[c]+matB.KL+1); k++){
      newmat(matA.Indx[c],k) += matA.Array[c]*matB(matA.Jndx[c],k);
    }
  }
  
  matA.destroy();
  matB.destroy();
  return _(newmat);
}
Ejemplo n.º 2
0
/*! _zgbmatrix-_zhematrix operator */
inline _zgematrix operator-(const _zgbmatrix& matA, const _zhematrix& matB)
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(matA.m!=matB.n || matA.n!=matB.n){
    ERROR_REPORT;
    std::cerr << "These two matrises can not make a summation." << std::endl
              << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.n << "x" << matB.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  zgematrix newmat(matB.n, matB.n);
  for(long i=0; i<newmat.m; i++){
    for(long j=0; j<newmat.n; j++){
      newmat(i,j)=-matB(i,j);
    }
    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);
    }
  }
  
  matA.destroy();
  matB.destroy();
  return _(newmat);
}
Ejemplo n.º 3
0
/*! solve A*x=y using zgbsv\n
  The argument is zcovector y. y is overwritten and become the solution x.
  A is also overwritten. */
inline long zgbmatrix::zgbsv(zcovector& vec)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] zgbmatrix::zgbsv(zcovector&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(M!=N || N!=vec.L){
    std::cerr << "[ERROR] zgbmatrix::zgbsv(zcovector&) " << std::endl
              << "These matrix and vector cannot be solved." << std::endl
              << "Your input was (" << M << "x" << N << ") and ("
              << vec.L << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG 
  
  zgbmatrix newmat(M,N,KL,KU+KL);
  for(long i=0; i<M; i++){ for(long j=max(0,i-KL); j<min(n,i+KU+1); j++){
    newmat(i,j) =operator()(i,j);
  }}
  
  long NRHS(1), LDAB(2*KL+KU+1),
    *IPIV(new long[N]), LDB(vec.L), INFO(1);
  zgbsv_(N, KL, KU, NRHS, newmat.Array, LDAB, IPIV, vec.Array, LDB, INFO);
  delete [] IPIV;
  
  swap(*this,newmat);
  
  if(INFO!=0){
    std::cerr << "[WARNING] zgbmatrix::zgbsv(zcovector&) "
              << "Serious trouble happend. INFO = "<< INFO << "." << std::endl;
  }
  return INFO;
}
Ejemplo n.º 4
0
/*! solve A*X=Y using dgbsv\n
  The argument is dgematrix Y. Y is overwritten and become the solution X.
  A is also overwritten. */
inline long dgbmatrix::dgbsv(dgematrix& mat)
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(m!=n || n!=mat.m){
    ERROR_REPORT;
    std::cerr << "These matrix and vector cannot be solved." << std::endl
              << "Your input was (" << m << "x" << n << ") and (" << mat.m << "x" << mat.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG 
  
  dgbmatrix newmat(m,n,kl,ku+kl);
  for(long i=0; i<m; i++){ for(long j=std::max(long(0),i-kl); j<std::min(n,i+ku+1); j++){
    newmat(i,j) =operator()(i,j);
  }}
  
  long NRHS(mat.n), LDAB(2*kl+ku+1),
    *IPIV(new long[n]), LDB(mat.m), INFO(1);
  dgbsv_(n, kl, ku, NRHS, newmat.array, LDAB, IPIV, mat.array, LDB, INFO);
  delete [] IPIV;
  
  swap(*this,newmat);
  
  if(INFO!=0){
    WARNING_REPORT;
    std::cerr << "Serious trouble happend. INFO = " << INFO << "." << std::endl;
  }
  return INFO;
}
Ejemplo n.º 5
0
/*! _zssmatrix-zhematrix operator */
inline _zgematrix operator-(const _zssmatrix& matA, const zhematrix& matB)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator-(const _zssmatrix&, const zhematrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(matA.M!=matB.N || matA.N!=matB.N){
    std::cerr << "[ERROR] operator-(const _zssmatrix&, const zhematrix&)"
              << 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

  zgematrix newmat(-matB);
  for(long c=0; c<matA.VOL; c++){
    newmat(matA.Indx[c],matA.Jndx[c]) += matA.Array[c];
  }
  
  matA.destroy();
  return _(newmat);
}
/*! _zssmatrix-_zgbmatrix operator */
inline _zgematrix operator-(const _zssmatrix& matA, const _zgbmatrix& matB)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator-(const _zssmatrix&, const _zgbmatrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(matA.N!=matB.N || matA.M!=matB.M){
    std::cerr << "[ERROR] operator+(const _zssmatrix&, const _zgbmatrix&)"
              << 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
  
  zgematrix newmat(matA);
  
  for(long i=0; i<matB.M; i++){
    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);
}
Ejemplo n.º 7
0
int
o_mirror(	/* convert a mirror material */
	char	*mod,
	char	*typ,
	char	*id,
	register FUNARGS	*fa
)
{
	COLOR	cxyz, rrgb;
	double	d;

	if (fa->nsargs == 1) {			/* use alternate material */
		newmat(id, fa->sarg[0]);
		return(0);
	}
	if (fa->nfargs != 3)
		return(-1);
	newmat(id, NULL);
	rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2];
	rgb_cie(cxyz, rrgb);
	puts("\tc");				/* put specular component */
	d = cxyz[0] + cxyz[1] + cxyz[2];
	if (d > FTINY)
		printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
	printf("\trs %.4f 0\n", cxyz[1]);
	return(0);
}
Ejemplo n.º 8
0
/*! dgematrix+dssmatrix operator */
inline _dgematrix operator+(const dgematrix& matA, const dssmatrix& matB)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator+(const dgematrix&, const dssmatrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(matA.M!=matB.M || matA.N!=matB.N){
    std::cerr << "[ERROR] operator+(const dgematrix&, const dssmatrix&)"
              << 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(matA);
  for(long c=0; c<matB.VOL; c++){
    newmat(matB.Indx[c],matB.Jndx[c]) += matB.Array[c];
  }
  
  return _(newmat);
}
Ejemplo n.º 9
0
/*! zgematrix*=zgbmatrix operator */
inline zgematrix& zgematrix::operator*=(const zgbmatrix& mat)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] zgematrix::operator*=(const zgbmatrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(N!=mat.M){
    std::cerr << "[ERROR] zgematrix::operator*=(const zgbmatrix&)" << std::endl
              << "These two matrises can not make a product." << std::endl
              << "Your input was (" << M << "x" << N << ") *= ("
              << mat.M << "x" << mat.N << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  zgematrix newmat(M,mat.N);
  newmat.zero();
  
  for(long i=0; i<newmat.m; i++){ for(long j=0; j<newmat.n; j++){
    for(long k=max(0,j-mat.KU); k<min(mat.M,j+mat.KL+1); k++){
      newmat(i,j)+=operator()(i,k)*mat(k,j);
    }
  }}
  
  swap(*this,newmat);
  return *this;
}
Ejemplo n.º 10
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);
}
Ejemplo n.º 11
0
/*! _dcovector*_drovector operator */
inline _dgematrix operator*(const _dcovector& covec, const _drovector& rovec)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator*(const _dcovector&, const _drovector&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(covec.L!=rovec.L){
    std::cerr << "[ERROR] operator*(const dcovector&, const drovector&)"
              << std::endl
              << "These two vectors can not make a product." << std::endl
              << "Your input was (" << covec.L << ") * (" << rovec.L << ")."
              << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  dgematrix newmat(covec.L, covec.L);
  for(long i=0; i<newmat.m; i++){
    for(long j=0; j<newmat.n; j++){
      newmat(i,j) =covec(i)*rovec(j);
    }
  }
  
  covec.destroy();
  rovec.destroy();
  return _(newmat);
}
Ejemplo n.º 12
0
/*! dgematrix*_dssmatrix operator */
inline _dgematrix operator*(const dgematrix& matA, const _dssmatrix& matB)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator*(const dgematrix&, const _dssmatrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(matA.N!=matB.M){
    std::cerr << "[ERROR] operator*(const dgematrix&, const _dssmatrix&)"
              << 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<matB.VOL; c++){
    for(long i=0; i<matA.M; i++){
      newmat(i,matB.Jndx[c]) += matA(i,matB.Indx[c])*matB.Array[c];
    }
  }
  
  matB.destroy();
  return _(newmat);
}
Ejemplo n.º 13
0
/*! dgbmatrix*dsymatrix operator */
inline _dgematrix operator*(const dgbmatrix& matA, const dsymatrix& matB)
{
#ifdef  CPPL_VERBOSE
  std::cerr << "# [MARK] operator*(const dgbmatrix&, const dsymatrix&)"
            << std::endl;
#endif//CPPL_VERBOSE
  
#ifdef  CPPL_DEBUG
  if(matA.N!=matB.N){
    std::cerr << "[ERROR] operator*(dgbmatrix&, dsymatrix&)" << 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();
  
  long i, j, k;
#pragma omp parallel for private(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);
      }
    }
  }
  
  return _(newmat);
}
Ejemplo n.º 14
0
/*! 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);
    }
  }
  
  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);
}
Ejemplo n.º 16
0
inline dgematrix_small<n,n> dsymatrix_small<n>::to_dgematrix_small() const
{VERBOSE_REPORT;
  dgematrix_small<n,n> newmat;
  for(long i=0; i<n; i++){
    for(long j=0;   j<=i; j++){ newmat(i,j) =(*this)(i,j); }
    for(long j=i+1; j<n;  j++){ newmat(i,j) =(*this)(j,i); }
  }
  return newmat;
}
Ejemplo n.º 17
0
/*! return transposed zgematrix */
inline _zhematrix t(const zhematrix& mat)
{VERBOSE_REPORT;
  zhematrix newmat(mat.n);
  for(long i=0; i<newmat.n; i++){ for(long j=0; j<=i; j++){
    newmat(i,j) =mat(j,i);
  }}
  
  return _(newmat);
}
Ejemplo n.º 18
0
mat funcop(const mat m, double (*f)(double)) {
  mat newmat(m.n_rows, m.n_cols);
  for (uint32_t i = 0 ; i < m.n_rows ; ++i) {
    for (uint32_t j = 0 ; j < m.n_cols ; ++j) {
      newmat(i, j) = f(m(i, j));
    }
  }
  return newmat;
}
Ejemplo n.º 19
0
/*! -zgematrix operator */
inline _zhematrix operator-(const zhematrix& mat)
{VERBOSE_REPORT;
  zhematrix newmat(mat.n);
  for(long i=0; i<mat.n; i++){ for(long j=0; j<=i; j++){
    newmat(i,j) =-mat(i,j);
  }}
  
  return _(newmat);
}
Ejemplo n.º 20
0
mat addcol(const mat m, const double val) {
  mat newmat(m.n_rows, m.n_cols+1);
  for (uint32_t i = 0 ; i < m.n_rows ; ++i) {
    newmat(i, 0) = val;
    for (uint32_t j = 0 ; j < m.n_cols ; ++j) {
      newmat(i, j+1) = m(i, j);
    }
  }
  return newmat;
}
Ejemplo n.º 21
0
inline dsymatrix dsymatrix_small<n>::to_dsymatrix() const
{VERBOSE_REPORT;
  dsymatrix newmat(n);
  for(long i=0; i<n; i++){
    for(long j=0; j<=i; j++){
      newmat(i,j) =(*this)(i,j);
    }
  }
  return newmat;
}
Ejemplo n.º 22
0
/*! convert to _dsymatrix */
inline _dsymatrix dssmatrix::to_dsymatrix() const
{VERBOSE_REPORT;
  dsymatrix newmat(n);
  newmat.zero();
  for(std::vector<dcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
    newmat(it->i, it->j) =it->v;
  }
  
  return _(newmat);
}
Ejemplo n.º 23
0
/*! convert to _dgematrix */
inline _dgematrix dgbmatrix::to_dgematrix() const
{VERBOSE_REPORT;
  dgematrix newmat( dgematrix(m,n).zero() );
  for(long i=0; i<m; i++){
    for(long j=std::max(long(0),i-kl); j<std::min(n,i+ku+1); j++){
      newmat(i,j) =(*this)(i,j);
    }
  }
  
  return _(newmat);
}
Ejemplo n.º 24
0
/*! convert to _zgematrix */
inline _zgematrix zhematrix::to_zgematrix() const
{VERBOSE_REPORT;
  zgematrix newmat(n,n);
  for(long i=0; i<n; i++){
    for(long j=0; j<n; j++){
      newmat(i,j) =(*this)(i,j);
    }
  }
  
  return _(newmat);
}
Ejemplo n.º 25
0
/*! cast to _zhematrix */
inline _zhematrix dsymatrix::to_zhematrix() const
{VERBOSE_REPORT;
  zhematrix newmat(n);
  for(long i=0; i<n; i++){
    for(long j=0; j<=i; j++){
      newmat(i,j) =comple((*this)(i,j),0.0);
    }
  }
  
  return _(newmat);
}
Ejemplo n.º 26
0
/*! convert to _dssmatrix */
inline _dssmatrix dsymatrix::to_dssmatrix(const double eps) const
{VERBOSE_REPORT;
  dssmatrix newmat(n);
  for(long i=0; i<n; i++){
    for(long j=0; j<=i; j++){
      if( fabs((*this)(i,j))>eps ){ newmat(i,j) =(*this)(i,j); }
    }
  }
  
  return _(newmat);
}
Ejemplo n.º 27
0
/*! convert to _dgematrix */
inline _dgematrix _dsymatrix::to_dgematrix() const
{VERBOSE_REPORT;
  dgematrix newmat(n,n);
  for(long i=0; i<n; i++){
    for(long j=0; j<n; j++){
      newmat(i,j) =(*this)(i,j);
    }
  }
  
  destroy();
  return _(newmat);
}
Ejemplo n.º 28
0
/*! convert to _zgematrix */
inline _zgematrix _zhsmatrix::to_zgematrix() const
{VERBOSE_REPORT;
  zgematrix newmat( zgematrix(m,n).zero() );
  
  for(std::vector<zcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
    newmat(it->i, it->j) =it->v;
    newmat(it->j, it->i) =std::conj(it->v);
  }
  
  destroy();
  return _(newmat);
}
Ejemplo n.º 29
0
/*! return its conjugate matrix */
inline _zhematrix conj(const zhematrix& mat)
{VERBOSE_REPORT;
  zhematrix newmat(mat.n);
  
  for(long i=0; i<mat.n; i++){
    for(long j=0; j<=i; j++){
      newmat(i,j) =std::conj(mat(i,j));
    }
  }
  
  return _(newmat);
}
Ejemplo n.º 30
0
/*! return its conjugate transposed matrix */
inline _zgematrix conjt(const _zgematrix& mat)
{VERBOSE_REPORT;
  zgematrix newmat(mat.n,mat.m);
  for(long i=0; i<newmat.m; i++){
    for(long j=0; j<newmat.n; j++){
      newmat(i,j) =std::conj(mat(j,i));
    }
  }
  
  mat.destroy();
  return _(newmat);
}