CPPLapack
Public Member Functions | Public Attributes | Friends
zhsmatrix Class Reference

Complex Double-precision Hermitian Sparse Matrix Class. More...

#include <zhsmatrix.hpp>

List of all members.

Public Member Functions

 zhsmatrix ()
 zhsmatrix (const zhsmatrix &)
 zhsmatrix (const _zhsmatrix &)
 zhsmatrix (const long &, const long=0)
 zhsmatrix (const char *)
 zhsmatrix (const zgematrix &)
 ~zhsmatrix ()
_zgematrix to_zgematrix () const
_zhematrix to_zhematrix () const
_zgsmatrix to_zgsmatrix () const
comple operator() (const long &, const long &) const
zhecomplex operator() (const long &, const long &)
zhsmatrixput (const long &, const long &, const comple &)
zhsmatrixdel (const long, const long)
zhsmatrixdel (const long)
void write (const char *) const
void read (const char *)
void clear ()
zhsmatrixzero ()
void chsign ()
void copy (const zhsmatrix &)
void shallow_copy (const _zhsmatrix &)
zhsmatrixresize (const long &, const long=0, const long=0)
void stretch (const long &)
void expand (const long &)
bool isListed (const long &, const long &) const
long number (const long &, const long &) const
void checkup ()
_zrovector row (const long &) const
_zcovector col (const long &) const
void diet (const double=DBL_MIN)
zhsmatrixoperator= (const zhsmatrix &)
zhsmatrixoperator= (const _zhsmatrix &)
zhsmatrixoperator+= (const zhsmatrix &)
zhsmatrixoperator+= (const _zhsmatrix &)
zhsmatrixoperator-= (const zhsmatrix &)
zhsmatrixoperator-= (const _zhsmatrix &)
zhsmatrixoperator*= (const double &)
zhsmatrixoperator/= (const double &)

Public Attributes

long const & m
 matrix row size
long n
 matrix column size
std::vector< zcomponentdata
 matrix data
std::vector< std::vector
< uint32_t > > 
line
 vector of vector to store the entry information of component for each row and column

Friends

std::ostream & operator<< (std::ostream &, const zhsmatrix &)
void swap (zhsmatrix &, zhsmatrix &)
_zhsmatrix _ (zhsmatrix &)
_zhsmatrix t (const zhsmatrix &)
void idamax (long &, long &, const zhsmatrix &)
comple damax (const zhsmatrix &)
const zhsmatrixoperator+ (const zhsmatrix &)
_zhsmatrix operator- (const zhsmatrix &)
_zgematrix operator+ (const zhsmatrix &, const zgematrix &)
_zgematrix operator+ (const zhsmatrix &, const _zgematrix &)
_zgematrix operator+ (const zhsmatrix &, const zhematrix &)
_zgematrix operator+ (const zhsmatrix &, const _zhematrix &)
_zgematrix operator+ (const zhsmatrix &, const zgbmatrix &)
_zgematrix operator+ (const zhsmatrix &, const _zgbmatrix &)
_zgsmatrix operator+ (const zhsmatrix &, const zgsmatrix &)
_zgsmatrix operator+ (const zhsmatrix &, const _zgsmatrix &)
_zhsmatrix operator+ (const zhsmatrix &, const zhsmatrix &)
_zhsmatrix operator+ (const zhsmatrix &, const _zhsmatrix &)
_zgematrix operator- (const zhsmatrix &, const zgematrix &)
_zgematrix operator- (const zhsmatrix &, const _zgematrix &)
_zgematrix operator- (const zhsmatrix &, const zhematrix &)
_zgematrix operator- (const zhsmatrix &, const _zhematrix &)
_zgematrix operator- (const zhsmatrix &, const zgbmatrix &)
_zgematrix operator- (const zhsmatrix &, const _zgbmatrix &)
_zgsmatrix operator- (const zhsmatrix &, const zgsmatrix &)
_zgsmatrix operator- (const zhsmatrix &, const _zgsmatrix &)
_zhsmatrix operator- (const zhsmatrix &, const zhsmatrix &)
_zhsmatrix operator- (const zhsmatrix &, const _zhsmatrix &)
_zcovector operator* (const zhsmatrix &, const zcovector &)
_zcovector operator* (const zhsmatrix &, const _zcovector &)
_zgematrix operator* (const zhsmatrix &, const zgematrix &)
_zgematrix operator* (const zhsmatrix &, const _zgematrix &)
_zgematrix operator* (const zhsmatrix &, const zhematrix &)
_zgematrix operator* (const zhsmatrix &, const _zhematrix &)
_zgematrix operator* (const zhsmatrix &, const zgbmatrix &)
_zgematrix operator* (const zhsmatrix &, const _zgbmatrix &)
_zgsmatrix operator* (const zhsmatrix &, const zgsmatrix &)
_zgsmatrix operator* (const zhsmatrix &, const _zgsmatrix &)
_zgsmatrix operator* (const zhsmatrix &, const zhsmatrix &)
_zgsmatrix operator* (const zhsmatrix &, const _zhsmatrix &)
_zhsmatrix operator* (const zhsmatrix &, const double &)
_zgsmatrix operator* (const zhsmatrix &, const comple &)
_zhsmatrix operator/ (const zhsmatrix &, const double &)
_zgsmatrix operator/ (const zhsmatrix &, const comple &)
_zhsmatrix operator* (const double &, const zhsmatrix &)
_zgsmatrix operator* (const comple &, const zhsmatrix &)

Detailed Description

Complex Double-precision Hermitian Sparse Matrix Class.

Definition at line 3 of file zhsmatrix.hpp.


Constructor & Destructor Documentation

zhsmatrix::zhsmatrix ( ) [inline]

zhsmatrix constructor without arguments

Definition at line 3 of file zhsmatrix-constructor.hpp.

References data, line, and n.

  : m(n)
{VERBOSE_REPORT;
  //////// initialize ////////
  n =0;
  data.clear();
  line.clear();
}
zhsmatrix::zhsmatrix ( const zhsmatrix mat) [inline]

zhsmatrix copy constructor

Definition at line 18 of file zhsmatrix-constructor.hpp.

References copy(), data, and line.

  : m(n)
{VERBOSE_REPORT;
  data.clear();
  line.clear();
  copy(mat);
}
zhsmatrix::zhsmatrix ( const _zhsmatrix mat) [inline]

zhsmatrix constructor to cast _zhsmatrix

Definition at line 28 of file zhsmatrix-constructor.hpp.

References data, _zhsmatrix::data, line, _zhsmatrix::line, _zhsmatrix::n, n, and _zhsmatrix::nullify().

  : m(n)
{VERBOSE_REPORT;
  n =mat.n;
  data.clear();
  line.clear();
  
  data.swap(mat.data);
  line.swap(mat.line);
  
  mat.nullify();
}
zhsmatrix::zhsmatrix ( const long &  _n,
const long  _c = 0 
) [inline]

zhsmatrix constructor with size specification

Definition at line 47 of file zhsmatrix-constructor.hpp.

References data, line, and n.

  : m(n)
{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if( _n<0 || _c<0 ){
    ERROR_REPORT;
    std::cerr << "Matrix sizes and the length of arrays must be positive integers. " << std::endl
              << "Your input was (" << _n << "," << _c << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  //////// initialize ////////
  n =_n;
  data.resize(0);
  data.reserve(_c);
  line.resize(n);
}
zhsmatrix::zhsmatrix ( const char *  filename) [inline]

zhsmatrix constructor with filename

Definition at line 68 of file zhsmatrix-constructor.hpp.

References data, line, and read().

  : m(n)
{VERBOSE_REPORT;
  data.clear();
  line.clear();
  
  //// read ////
  read(filename);
}
zhsmatrix::zhsmatrix ( const zgematrix ) [inline]
zhsmatrix::~zhsmatrix ( ) [inline]

zhsmatrix destructor

Definition at line 84 of file zhsmatrix-constructor.hpp.

References data, and line.

{VERBOSE_REPORT;
  data.clear();
  line.clear();
}

Member Function Documentation

_zgematrix zhsmatrix::to_zgematrix ( ) const [inline]

convert to _zgematrix

Definition at line 3 of file zhsmatrix-cast.hpp.

References _, conj(), data, m, n, and zero().

{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);
  }
  
  return _(newmat);
}
_zhematrix zhsmatrix::to_zhematrix ( ) const [inline]

convert to _zhematrix

Definition at line 17 of file zhsmatrix-cast.hpp.

References _, data, n, and zhematrix::zero().

{VERBOSE_REPORT;
  zhematrix newmat(n);
  newmat.zero();
  
  for(std::vector<zcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
    newmat(it->i, it->j) =it->v;
  }
  
  return _(newmat);
}
_zgsmatrix zhsmatrix::to_zgsmatrix ( ) const [inline]

convert to _zgsmatrix

Definition at line 31 of file zhsmatrix-cast.hpp.

References _, conj(), data, m, n, zgsmatrix::put(), and zgsmatrix::zero().

Referenced by operator*(), and operator/().

{VERBOSE_REPORT;
  zgsmatrix newmat(m,n);
  newmat.zero();
  
  for(std::vector<zcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
    newmat.put(it->i, it->j, it->v);
    if(it->i!=it->j){
      newmat.put(it->j, it->i, std::conj(it->v));
    }
  }
  
  return _(newmat);
}
comple zhsmatrix::operator() ( const long &  i,
const long &  j 
) const [inline]

operator() for const object

Definition at line 3 of file zhsmatrix-io.hpp.

References conj(), data, line, and n.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if( i<0 || j<0 || n<=i || n<=j ){
    ERROR_REPORT;
    std::cerr << "The required component is out of the matrix size." << std::endl
              << "Your input was (" << i << "," << j << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  //// search (i,j) component ////
  const uint32_t ii(std::max(i,j)), jj(std::min(i,j));
  for(std::vector<uint32_t>::const_iterator p=line[ii].begin(); p!=line[ii].end(); p++){
    if(data[*p].j==jj){
      if( i>j ){ return data[*p].v; }//ii=i
      else{      return std::conj(data[*p].v); }//ii=j
    }
  }
  
  //// (i,j) component was not found ////
  return comple(0.0,0.0);
}
zhecomplex zhsmatrix::operator() ( const long &  i,
const long &  j 
) [inline]

operator()

Definition at line 29 of file zhsmatrix-io.hpp.

References data, i(), line, and n.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if( i<0 || j<0 || n<=i || n<=j ){
    ERROR_REPORT;
    std::cerr << "The required component is out of the matrix size." << std::endl
              << "Your input was (" << i << "," << j << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  //////// search (i,j) component ////////
  const uint32_t ii(std::max(i,j)), jj(std::min(i,j));
  for(std::vector<uint32_t>::const_iterator p=line[ii].begin(); p!=line[ii].end(); p++){
    if(data[*p].j==jj){
      return zhecomplex(i,j, data[*p].v);
    }
  }
  
  //////// (i,j) component not found ////////
  line[i].push_back(data.size());
  if(i!=j){//off-diagonal
    line[j].push_back(data.size());
  }
  data.push_back(zcomponent(ii,jj,comple(0.,0.)));
  return zhecomplex(i,j, data.back().v);
}
zhsmatrix & zhsmatrix::put ( const long &  i,
const long &  j,
const comple &  v 
) [inline]

put value with volume cheack without isListed check

Definition at line 63 of file zhsmatrix-io.hpp.

References data, isListed(), line, and n.

Referenced by read(), _dssmatrix::to_zhsmatrix(), and dssmatrix::to_zhsmatrix().

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if( i<0 || j<0 || n<=i || n<=j ){
    ERROR_REPORT;
    std::cerr << "The required component is out of the matrix size." << std::endl
              << "Your input was (" << i << "," << j << ")." << std::endl;
    exit(1);
  }
  
  if( isListed(i,j) ){
    ERROR_REPORT;
    std::cerr << "The required component is already listed." << std::endl
              << "Your input was (" << i << "," << j << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  //// push ////
  const long ii(std::max(i,j)), jj(std::min(i,j));
  line[ii].push_back(data.size());
  if(i!=j){//off-diagonal
    line[jj].push_back(data.size());
  }
  data.push_back(zcomponent(ii,jj,v));
  return *this;
}
zhsmatrix & zhsmatrix::del ( const long  i,
const long  j 
) [inline]

delete the entry of a component

Definition at line 97 of file zhsmatrix-io.hpp.

References data, line, and n.

Referenced by diet(), and stretch().

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if( i<0 || j<0 || n<=i || n<=j ){
    ERROR_REPORT;
    std::cerr << "The required component is out of the matrix size." << std::endl
              << "Your input was (" << i << "," << j << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG

  const long ii(std::max(i,j)), jj(std::min(i,j));

  //////// search (i,j) component ////////
  for(std::vector<uint32_t>::iterator p=line[ii].begin(); p!=line[ii].end(); p++){
    if( long(data[*p].i)==ii && long(data[*p].j)==jj ){//exists
      //// save position ////
      uint32_t c(*p);
      uint32_t C(data.size()-1);

      //// data translation ////
      data[c]=data.back();
      data.pop_back();

      //// remove from List ////
      line[ii].erase(p);
      if(i!=j){//off-diagonal
        for(std::vector<uint32_t>::iterator pj=line[jj].begin(); pj!=line[jj].end(); pj++){
          if(*pj==c){ line[jj].erase(pj); break; }
        }
      }

      //// modify the entry of translated component ////
      uint32_t I(data[c].i), J(data[c].j);
      for(std::vector<uint32_t>::iterator q=line[I].begin(); q!=line[I].end(); q++){
        if(*q==C){ *q=c; break; }
      }
      if(I!=J){//off-diagonal
        for(std::vector<uint32_t>::iterator q=line[J].begin(); q!=line[J].end(); q++){
          if(*q==C){ *q=c; break; }
        }
      }
      return *this;
    }
  }
  
#ifdef  CPPL_DEBUG
  std::cerr << "# [NOTE]@zhsmatrix::del(long&, long&): The required component was not listed. Your input was (" << i << "," << j << ")." << std::endl;
#endif//CPPL_DEBUG
  
  return *this;
}
zhsmatrix & zhsmatrix::del ( const long  c) [inline]

delete the entry of an element

Definition at line 152 of file zhsmatrix-io.hpp.

References data, i(), and line.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if( c<0 || c>=long(data.size()) ){
    ERROR_REPORT;
    std::cerr << "The required element is out of the matrix volume." << std::endl
              << "Your input was (" << c << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  if( c==long(data.size()-1) ){//if c is the last element
    long i(data[c].i), j(data[c].j);
    for(std::vector<uint32_t>::iterator q=line[i].begin(); q!=line[i].end(); q++){
      if( long(*q)==c ){ line[i].erase(q); break; }
    }
    if(i!=j){//off-diagonal
      for(std::vector<uint32_t>::iterator q=line[j].begin(); q!=line[j].end(); q++){
        if( long(*q)==c ){ line[j].erase(q); break; }
      }
    }
    data.pop_back();
  }
  
  else{//c is NOT the last element
    //// data translation ////
    uint32_t C(data.size()-1);
    long i(data[c].i), j(data[c].j), I(data.back().i), J(data.back().j);
    data[c]=data.back();
    //std::cerr << "c=" << c   << " i=" << i << " j=" << j << " C=" << vol << " I=" << I << " J=" << J << std::endl;
    //// remove entry of component ////
    for(std::vector<uint32_t>::iterator q=line[i].begin(); q!=line[i].end(); q++){
      if( long(*q)==c ){ line[i].erase(q); break; }
    }
    if(i!=j){//off-diagonal
      for(std::vector<uint32_t>::iterator q=line[j].begin(); q!=line[j].end(); q++){
        if( long(*q)==c ){ line[j].erase(q); break; }
      }
    }
    //// modify the entry of translated component ////
    for(std::vector<uint32_t>::iterator q=line[I].begin(); q!=line[I].end(); q++){
      if(*q==C){ *q=c; break; }
    }
    if(I!=J){//off-diagonal
      for(std::vector<uint32_t>::iterator q=line[J].begin(); q!=line[J].end(); q++){
        if(*q==C){ *q=c; break; }
      }
    }
    //// pop_back ////
    data.pop_back();
  }
  
  return *this;
}
void zhsmatrix::write ( const char *  filename) const [inline]

Definition at line 246 of file zhsmatrix-io.hpp.

References data, and n.

{VERBOSE_REPORT;
  std::ofstream ofs(filename, std::ios::trunc);
  ofs.setf(std::cout.flags());
  ofs.precision(std::cout.precision());
  ofs.width(std::cout.width());
  ofs.fill(std::cout.fill());
  
  ofs << "#zhsmatrix" << " " << n << std::endl;
  for(std::vector<zcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
    ofs << it->i << " " << it->j << " " << it->v << std::endl;
  }
  ofs.close();
}
void zhsmatrix::read ( const char *  filename) [inline]

Definition at line 262 of file zhsmatrix-io.hpp.

References i(), n, put(), and resize().

Referenced by zhsmatrix().

{VERBOSE_REPORT;
  std::ifstream s( filename );
  if(!s){
    ERROR_REPORT;
    std::cerr << "The file \"" << filename << "\" can not be opened." << std::endl;
    exit(1);
  }

  std::string id;
  s >> id;
  if( id != "zhsmatrix" && id != "#zhsmatrix" ){
    ERROR_REPORT;
    std::cerr << "The type name of the file \"" << filename << "\" is not zhsmatrix." << std::endl
              << "Its type name was " << id << " ." << std::endl;
    exit(1);
  }
  
  s >> n;
  resize(n);
  
  comple val;
  long i, j,  pos, tmp;
  while(!s.eof()){
    s >> i >> j >> val;
    put(i,j, val);
    pos =s.tellg();
    s >> tmp;
    s.seekg(pos);
  }
  
  if(!s.eof()){
    ERROR_REPORT;
    std::cerr << "There is something is wrong with the file \"" << filename << " ." << std::endl
              << "Most likely, there are too many data components over the context." << std::endl;
    exit(1);
  }
  s.close();
}
void zhsmatrix::clear ( ) [inline]

clear all the matrix data and set the sizes 0

Definition at line 3 of file zhsmatrix-misc.hpp.

References data, line, and n.

{VERBOSE_REPORT;
  n =0;
  data.clear();
  line.clear();
}
zhsmatrix & zhsmatrix::zero ( ) [inline]

change the matrix into a zero matrix

Definition at line 12 of file zhsmatrix-misc.hpp.

References data, i(), line, and n.

Referenced by col(), row(), and to_zgematrix().

{VERBOSE_REPORT;
  data.resize(0);
  for(long i=0; i<n; i++){ line[i].resize(0); }
  return *this;
}
void zhsmatrix::chsign ( ) [inline]

change sign(+/-) of the matrix

Definition at line 21 of file zhsmatrix-misc.hpp.

References data.

{VERBOSE_REPORT;
  for(std::vector<zcomponent>::iterator it=data.begin(); it!=data.end(); it++){
    it->v =-it->v;
  }
}
void zhsmatrix::copy ( const zhsmatrix mat) [inline]

make a deep copy of the matrix

Definition at line 30 of file zhsmatrix-misc.hpp.

References data, line, and n.

Referenced by operator=(), and zhsmatrix().

{VERBOSE_REPORT;
  n =mat.n;
  data =mat.data;
  line =mat.line;
}
void zhsmatrix::shallow_copy ( const _zhsmatrix mat) [inline]

make a shallow copy of the matrix
This function is not designed to be used in project codes.

Definition at line 40 of file zhsmatrix-misc.hpp.

References data, _zhsmatrix::data, line, _zhsmatrix::line, _zhsmatrix::n, n, and _zhsmatrix::nullify().

Referenced by operator=().

{VERBOSE_REPORT;
  data.clear();
  line.clear();
  
  n =mat.n;
  data.swap(mat.data);
  line.swap(mat.line);
  
  mat.nullify();
}
zhsmatrix & zhsmatrix::resize ( const long &  _n,
const long  _c = 0,
const long  _l = 0 
) [inline]

resize the matrix

Definition at line 54 of file zhsmatrix-misc.hpp.

References data, i(), line, and n.

Referenced by read().

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if( _n<0 || _c<0 || _l<0 ){
    ERROR_REPORT;
    std::cerr << "Matrix sizes and the length of arrays must be positive integers. " << std::endl
              << "Your input was (" << _n << "," << _c << "," << _l << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  n =_n;
  data.resize(0);
  data.reserve(_c);
  line.resize(n);
  for(long i=0; i<n; i++){
    line[i].resize(0);
    line[i].reserve(_l);
  }
  
  return *this;
}
void zhsmatrix::stretch ( const long &  dn) [inline]

stretch the matrix size

Definition at line 79 of file zhsmatrix-misc.hpp.

References data, del(), i(), line, and n.

{VERBOSE_REPORT;
  if(dn==0){ return; }
  
#ifdef  CPPL_DEBUG
  if( n+dn<0 ){
    ERROR_REPORT;
    std::cerr << "The new matrix size must be larger than zero." << std::endl
              << "Your input was (" << dn << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  n +=dn;
  
  if(dn<0){
    //// delete components over the new size ////
    for(std::vector<zcomponent>::reverse_iterator it=data.rbegin(); it!=data.rend(); it++){
      if( long(it->i)>=n ){ del(data.rend()-it-1); }
    }
    //// shrink line ////
    for(long i=0; i<-dn; i++){
      line.pop_back();
    }
  }
  else{//dn>0
    //// expand line ////
    for(long i=0; i<dn; i++){
      line.push_back( std::vector<uint32_t>(0) );
    }
  }
}
void zhsmatrix::expand ( const long &  ) [inline]
bool zhsmatrix::isListed ( const long &  i,
const long &  j 
) const [inline]

check if the component is listed

Definition at line 114 of file zhsmatrix-misc.hpp.

References data, line, and n.

Referenced by put().

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if( i<0 || j<0 || n<=i || n<=j ){
    ERROR_REPORT;
    std::cerr << "The required component is out of the matrix size." << std::endl
              << "Your input was (" << i << "," << j << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  const uint32_t ii(std::max(i,j)), jj(std::min(i,j));
  for(std::vector<uint32_t>::const_iterator p=line[ii].begin(); p!=line[ii].end(); p++){
    if(data[*p].j==jj){ return 1; }
  }
  return 0;
}
long zhsmatrix::number ( const long &  i,
const long &  j 
) const [inline]

return the element number of the component

Definition at line 135 of file zhsmatrix-misc.hpp.

References data, line, and n.

Referenced by operator<<().

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if( i<0 || j<0 || n<=i || n<=j ){
    ERROR_REPORT;
    std::cerr << "The required component is out of the matrix size." << std::endl
              << "Your input was (" << i << "," << j << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  const uint32_t ii(std::max(i,j)), jj(std::min(i,j));
  for(std::vector<uint32_t>::const_iterator p=line[ii].begin(); p!=line[ii].end(); p++){
    if(data[*p].j==jj){ return *p; }
  }
  return -1;
}
void zhsmatrix::checkup ( ) [inline]

health checkup

Definition at line 251 of file zhsmatrix-misc.hpp.

References i(), imag(), and m.

{VERBOSE_REPORT;
  //////// complex diagonal ////////
  for(long i=0; i<m; i++){
    if( std::fabs((*this)(i,i).imag()) > DBL_MIN ){
      ERROR_REPORT;
      std::cerr << "Diagonal components of a Hermitian matrix have to be real numbers." << std::endl
                << "(*this)(" << i << "," << i << ") was a complex number, " << (*this)(i,i) << "." << std::endl;
      exit(1);
    }
  }
  
  //////// NOTE ////////
  std::cerr << "# [NOTE]@zhsmatrix::checkup(): This symmetric sparse matrix is fine." << std::endl;
}
_zrovector zhsmatrix::row ( const long &  _m) const [inline]

get row of the matrix

Definition at line 159 of file zhsmatrix-misc.hpp.

References _, conj(), data, i(), line, m, n, and zero().

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if( _m<0 || _m>m ){
    ERROR_REPORT;
    std::cerr << "Input row number must be between 0 and " << m << "." << std::endl
              << "Your input was " << _m << "." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  zrovector vec( zrovector(n).zero() );
  for(std::vector<uint32_t>::const_iterator p=line[_m].begin(); p!=line[_m].end(); p++){
    if( long(data[*p].i)==_m ){//i>=j
      vec(data[*p].j) =data[*p].v;
    }
    else{//i<j
      vec(data[*p].i) =std::conj(data[*p].v);
    }
  }
  return _(vec);
}
_zcovector zhsmatrix::col ( const long &  _n) const [inline]

get column of the matrix

Definition at line 184 of file zhsmatrix-misc.hpp.

References _, conj(), data, i(), line, m, n, and zero().

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if( _n<0 || _n>n ){
    ERROR_REPORT;
    std::cerr << "Input row number must be between 0 and " << n << "." << std::endl
              << "Your input was " << _n << "." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  zcovector vec( zcovector(m).zero() );
  for(std::vector<uint32_t>::const_iterator p=line[_n].begin(); p!=line[_n].end(); p++){
    if( long(data[*p].i)==_n ){//i<j
      vec(data[*p].j) =std::conj(data[*p].v);
    }
    else{//i>=j
      vec(data[*p].i) =data[*p].v;
    }
  }
  return _(vec);
}
void zhsmatrix::diet ( const double  eps = DBL_MIN) [inline]

erase components less than DBL_MIN

Definition at line 209 of file zhsmatrix-misc.hpp.

References data, and del().

{VERBOSE_REPORT;
  for(std::vector<zcomponent>::reverse_iterator it=data.rbegin(); it!=data.rend(); it++){
    if( fabs(it->v.real())<eps && fabs(it->v.imag())<eps ){
      del(data.rend()-it-1);
    }
  }
}
zhsmatrix & zhsmatrix::operator= ( const zhsmatrix mat) [inline]

zhsmatrix=zhsmatrix operator

Definition at line 3 of file zhsmatrix-zhsmatrix.hpp.

References copy(), and data.

{VERBOSE_REPORT;
  if(&data!=&mat.data){ // if it is NOT self substitution
    copy(mat);
  }
  return *this;
}
zhsmatrix & zhsmatrix::operator= ( const _zhsmatrix mat) [inline]

zhsmatrix=_zhsmatrix operator

Definition at line 3 of file zhsmatrix-_zhsmatrix.hpp.

References shallow_copy().

{VERBOSE_REPORT;
  shallow_copy(mat);
  return *this;
}
zhsmatrix & zhsmatrix::operator+= ( const zhsmatrix mat) [inline]

zhsmatrix+=zhsmatrix operator

Definition at line 17 of file zhsmatrix-zhsmatrix.hpp.

References data, and n.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(n!=mat.n){
    ERROR_REPORT;
    std::cerr << "These two matrises can not make a summation." << std::endl
              << "Your input was (" << n << "x" << n << ") += (" << mat.n << "x" << mat.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    (*this)(it->i,it->j) +=it->v;
  }
  
  return *this;
}
zhsmatrix & zhsmatrix::operator+= ( const _zhsmatrix mat) [inline]

zhsmatrix+=_zhsmatrix operator

Definition at line 15 of file zhsmatrix-_zhsmatrix.hpp.

References _zhsmatrix::data, _zhsmatrix::destroy(), n, and _zhsmatrix::n.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(n!=mat.n){
    ERROR_REPORT;
    std::cerr << "These two matrises can not make a summation." << std::endl
              << "Your input was (" << n << "x" << n << ") += (" << mat.n << "x" << mat.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    (*this)(it->i,it->j) +=it->v;
  }
  
  mat.destroy();
  return *this;
}
zhsmatrix & zhsmatrix::operator-= ( const zhsmatrix mat) [inline]

zhsmatrix-=zhsmatrix operator

Definition at line 37 of file zhsmatrix-zhsmatrix.hpp.

References data, and n.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(n!=mat.n){
    ERROR_REPORT;
    std::cerr << "These two matrises can not make a sutraction." << std::endl
              << "Your input was (" << n << "x" << n << ") -= (" << mat.n << "x" << mat.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    (*this)(it->i,it->j) -=it->v;
  }
  
  return *this;
}
zhsmatrix & zhsmatrix::operator-= ( const _zhsmatrix mat) [inline]

zhsmatrix-=_zhsmatrix operator

Definition at line 36 of file zhsmatrix-_zhsmatrix.hpp.

References _zhsmatrix::data, _zhsmatrix::destroy(), n, and _zhsmatrix::n.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(n!=mat.n){
    ERROR_REPORT;
    std::cerr << "These two matrises can not make a sutraction." << std::endl
              << "Your input was (" << n << "x" << n << ") -= (" << mat.n << "x" << mat.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    (*this)(it->i,it->j) -=it->v;
  }
  
  mat.destroy();
  return *this;
}
zhsmatrix & zhsmatrix::operator*= ( const double &  d) [inline]

zhsmatrix*=double operator

Definition at line 3 of file zhsmatrix-double.hpp.

References data.

{VERBOSE_REPORT;
  for(std::vector<zcomponent>::iterator it=data.begin(); it!=data.end(); it++){
    it->v *=d;
  }
  return *this;
}
zhsmatrix & zhsmatrix::operator/= ( const double &  d) [inline]

zhsmatrix/=double operator

Definition at line 13 of file zhsmatrix-double.hpp.

References data.

{VERBOSE_REPORT;
  for(std::vector<zcomponent>::iterator it=data.begin(); it!=data.end(); it++){
    it->v /=d;
  }
  return *this;
}

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  s,
const zhsmatrix mat 
) [friend]

Definition at line 212 of file zhsmatrix-io.hpp.

{VERBOSE_REPORT;
  for(long i=0; i<mat.n; i++){
    for(long j=0; j<mat.n; j++){
      if( i >= j ){
        long c =mat.number(i,j);
        if(c<0){
          s << " x ";
        }
        else{
          s << " " << mat.data[c].v << " ";
        }
      }
      else{//i<j
        long c =mat.number(i,j);
        if(c<0){
          s << "{x}";
        }
        else{
          s << "{" << std::conj(mat.data[c].v) << "}";
        }
      }
    }
    s << std::endl;
  }
  
  return s;
}
void swap ( zhsmatrix A,
zhsmatrix B 
) [friend]

swap two matrices

Definition at line 224 of file zhsmatrix-misc.hpp.

{VERBOSE_REPORT;
  std::swap(A.n,B.n);
  std::swap(A.data,B.data);
  std::swap(A.line,B.line);
}
_zhsmatrix _ ( zhsmatrix mat) [friend]

convert user object to smart-temporary object

Definition at line 233 of file zhsmatrix-misc.hpp.

Referenced by col(), row(), to_zgematrix(), to_zgsmatrix(), and to_zhematrix().

{VERBOSE_REPORT;
  _zhsmatrix newmat;
  //////// shallow copy ////////
  newmat.n =mat.n;
  std::swap(newmat.data, mat.data);
  std::swap(newmat.line, mat.line);
  //////// nullify ////////
  mat.n =0;
  return newmat;
}
_zhsmatrix t ( const zhsmatrix mat) [friend]

return transposed zhsmatrix

Definition at line 3 of file zhsmatrix-calc.hpp.

{VERBOSE_REPORT;
  zhsmatrix newmat(mat);
  
  for(std::vector<zcomponent>::iterator it=newmat.data.begin(); it!=newmat.data.end(); it++){
    it->v =std::conj(it->v);
  }
  
  return _(newmat);
}
void idamax ( long &  i,
long &  j,
const zhsmatrix mat 
) [friend]

search the index of element having the largest absolute value in 0-based numbering system

Definition at line 51 of file zhsmatrix-calc.hpp.

{VERBOSE_REPORT;
  std::vector<zcomponent>::const_iterator itx(mat.data.begin());
  double vmax =0.;
  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    if( vmax < norm(it->v) ){
      vmax =norm(it->v);
      itx =it;
    }
  }
  i =itx->i;
  j =itx->j;
}
comple damax ( const zhsmatrix mat) [friend]

return its largest absolute value

Definition at line 67 of file zhsmatrix-calc.hpp.

{VERBOSE_REPORT;
  std::vector<zcomponent>::const_iterator itx(mat.data.begin());
  double vmax =0.;
  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    if( vmax < norm(it->v) ){
      vmax =norm(it->v);
      itx =it;
    }
  }
  return itx->v;
}
const zhsmatrix& operator+ ( const zhsmatrix mat) [friend]

+zhsmatrix operator

Definition at line 3 of file zhsmatrix-unary.hpp.

{VERBOSE_REPORT;
  return mat;
}
_zhsmatrix operator- ( const zhsmatrix mat) [friend]

-zhsmatrix operator

Definition at line 10 of file zhsmatrix-unary.hpp.

{VERBOSE_REPORT;
  zhsmatrix newmat(mat);
  for(std::vector<zcomponent>::iterator it=newmat.data.begin(); it!=newmat.data.end(); it++){
    it->v =-it->v;
  }
  return _(newmat);
}
_zgematrix operator+ ( const zhsmatrix ,
const zgematrix  
) [friend]
_zgematrix operator+ ( const zhsmatrix ,
const _zgematrix  
) [friend]
_zgematrix operator+ ( const zhsmatrix ,
const zhematrix  
) [friend]
_zgematrix operator+ ( const zhsmatrix ,
const _zhematrix  
) [friend]
_zgematrix operator+ ( const zhsmatrix ,
const zgbmatrix  
) [friend]
_zgematrix operator+ ( const zhsmatrix ,
const _zgbmatrix  
) [friend]
_zgsmatrix operator+ ( const zhsmatrix ,
const zgsmatrix  
) [friend]
_zgsmatrix operator+ ( const zhsmatrix ,
const _zgsmatrix  
) [friend]
_zhsmatrix operator+ ( const zhsmatrix matA,
const zhsmatrix matB 
) [friend]

zhsmatrix+zhsmatrix operator

Definition at line 61 of file zhsmatrix-zhsmatrix.hpp.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(matA.n!=matB.n){
    ERROR_REPORT;
    std::cerr << "These two matrises can not make a summation." << std::endl
              << "Your input was (" << matA.n << "x" << matA.n << ") + (" << matB.n << "x" << matB.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  zhsmatrix newmat(matA);
  
  for(std::vector<zcomponent>::const_iterator it=matB.data.begin(); it!=matB.data.end(); it++){
    newmat(it->i,it->j) +=it->v;
  }
  
  return _(newmat);
}
_zhsmatrix operator+ ( const zhsmatrix matA,
const _zhsmatrix matB 
) [friend]

zhsmatrix+_zhsmatrix operator

Definition at line 61 of file zhsmatrix-_zhsmatrix.hpp.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(matA.n!=matB.n){
    ERROR_REPORT;
    std::cerr << "These two matrises can not make a summation." << std::endl
              << "Your input was (" << matA.n << "x" << matA.n << ") + (" << matB.n << "x" << matB.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG

  zhsmatrix newmat(matB);
  
  for(std::vector<zcomponent>::const_iterator it=matA.data.begin(); it!=matA.data.end(); it++){
    newmat(it->i,it->j) +=it->v;
  }
  
  return _(newmat);
}
_zgematrix operator- ( const zhsmatrix ,
const zgematrix  
) [friend]
_zgematrix operator- ( const zhsmatrix ,
const _zgematrix  
) [friend]
_zgematrix operator- ( const zhsmatrix ,
const zhematrix  
) [friend]
_zgematrix operator- ( const zhsmatrix ,
const _zhematrix  
) [friend]
_zgematrix operator- ( const zhsmatrix ,
const zgbmatrix  
) [friend]
_zgematrix operator- ( const zhsmatrix ,
const _zgbmatrix  
) [friend]
_zgsmatrix operator- ( const zhsmatrix ,
const zgsmatrix  
) [friend]
_zgsmatrix operator- ( const zhsmatrix ,
const _zgsmatrix  
) [friend]
_zhsmatrix operator- ( const zhsmatrix matA,
const zhsmatrix matB 
) [friend]

zhsmatrix-zhsmatrix operator

Definition at line 83 of file zhsmatrix-zhsmatrix.hpp.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(matA.n!=matB.n){
    ERROR_REPORT;
    std::cerr << "These two matrises can not make a subtraction." << std::endl
              << "Your input was (" << matA.n << "x" << matA.n << ") - (" << matB.n << "x" << matB.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  zhsmatrix newmat(matA);
  
  for(std::vector<zcomponent>::const_iterator it=matB.data.begin(); it!=matB.data.end(); it++){
    newmat(it->i,it->j) -=it->v;
  }
  
  return _(newmat);
}
_zhsmatrix operator- ( const zhsmatrix matA,
const _zhsmatrix matB 
) [friend]

zhsmatrix-_zhsmatrix operator

Definition at line 83 of file zhsmatrix-_zhsmatrix.hpp.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(matA.n!=matB.n){
    ERROR_REPORT;
    std::cerr << "These two matrises can not make a subtraction." << std::endl
              << "Your input was (" << matA.n << "x" << matA.n << ") - (" << matB.n << "x" << matB.n << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  zhsmatrix newmat(-matB);
  
  for(std::vector<zcomponent>::const_iterator it=matA.data.begin(); it!=matA.data.end(); it++){
    newmat(it->i,it->j) +=it->v;
  }
  
  return _(newmat);
}
_zcovector operator* ( const zhsmatrix mat,
const zcovector vec 
) [friend]

zhsmatrix*zcovector operator

Definition at line 3 of file zhsmatrix-zcovector.hpp.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(mat.n!=vec.l){
    ERROR_REPORT;
    std::cerr << "These matrix and vector can not make a product." << std::endl
              << "Your input was (" << mat.n << "x" << mat.n << ") * (" << vec.l << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  zcovector newvec(mat.n);
  newvec.zero();
  
  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    newvec(it->i) +=it->v*vec(it->j);
    if(it->i!=it->j){
      newvec(it->j) +=std::conj(it->v)*vec(it->i);
    }
  }
  
  return _(newvec);
}
_zcovector operator* ( const zhsmatrix mat,
const _zcovector vec 
) [friend]

zhsmatrix*_zcovector operator

Definition at line 3 of file zhsmatrix-_zcovector.hpp.

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  if(mat.n!=vec.l){
    ERROR_REPORT;
    std::cerr << "These matrix and vector can not make a product." << std::endl
              << "Your input was (" << mat.n << "x" << mat.n << ") * (" << vec.l << ")." << std::endl;
    exit(1);
  }
#endif//CPPL_DEBUG
  
  zcovector newvec(mat.n);
  newvec.zero();
  
  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    newvec(it->i) +=it->v*vec(it->j);
    if(it->i!=it->j){
      newvec(it->j) +=std::conj(it->v)*vec(it->i);
    }
  }
  
  vec.destroy();
  return _(newvec);
}
_zgematrix operator* ( const zhsmatrix ,
const zgematrix  
) [friend]
_zgematrix operator* ( const zhsmatrix ,
const _zgematrix  
) [friend]
_zgematrix operator* ( const zhsmatrix ,
const zhematrix  
) [friend]
_zgematrix operator* ( const zhsmatrix ,
const _zhematrix  
) [friend]
_zgematrix operator* ( const zhsmatrix ,
const zgbmatrix  
) [friend]
_zgematrix operator* ( const zhsmatrix ,
const _zgbmatrix  
) [friend]
_zgsmatrix operator* ( const zhsmatrix ,
const zgsmatrix  
) [friend]
_zgsmatrix operator* ( const zhsmatrix ,
const _zgsmatrix  
) [friend]
_zgsmatrix operator* ( const zhsmatrix ,
const zhsmatrix  
) [friend]
_zgsmatrix operator* ( const zhsmatrix ,
const _zhsmatrix  
) [friend]
_zhsmatrix operator* ( const zhsmatrix mat,
const double &  d 
) [friend]

zhsmatrix*double operator

Definition at line 27 of file zhsmatrix-double.hpp.

{VERBOSE_REPORT;
  zhsmatrix newmat(mat);
  
  for(std::vector<zcomponent>::iterator it=newmat.data.begin(); it!=newmat.data.end(); it++){
    it->v *=d;
  }
  
  return _(newmat);
}
_zgsmatrix operator* ( const zhsmatrix mat,
const comple &  d 
) [friend]

zhsmatrix*complex operator

Definition at line 3 of file zhsmatrix-complex.hpp.

{VERBOSE_REPORT;
  zgsmatrix newmat( mat.to_zgsmatrix() );
  return newmat*d;
}
_zhsmatrix operator/ ( const zhsmatrix mat,
const double &  d 
) [friend]

zhsmatrix/double operator

Definition at line 40 of file zhsmatrix-double.hpp.

{VERBOSE_REPORT;
  zhsmatrix newmat(mat);
  
  for(std::vector<zcomponent>::iterator it=newmat.data.begin(); it!=newmat.data.end(); it++){
    it->v /=d;
  }
  
  return _(newmat);
}
_zgsmatrix operator/ ( const zhsmatrix mat,
const comple &  d 
) [friend]

zhsmatrix/complex operator

Definition at line 11 of file zhsmatrix-complex.hpp.

{VERBOSE_REPORT;
  zgsmatrix newmat( mat.to_zgsmatrix() );
  return newmat/d;
}
_zhsmatrix operator* ( const double &  d,
const zhsmatrix mat 
) [friend]

double*zhsmatrix operator

Definition at line 3 of file double-zhsmatrix.hpp.

{VERBOSE_REPORT;
  zhsmatrix newmat(mat);
  
  for(std::vector<zcomponent>::iterator it=newmat.data.begin(); it!=newmat.data.end(); it++){
    it->v *=d;
  }
  
  return _(newmat);
}
_zgsmatrix operator* ( const comple &  d,
const zhsmatrix mat 
) [friend]

complex*zhsmatrix operator

Definition at line 3 of file complex-zhsmatrix.hpp.

{VERBOSE_REPORT;
  zgsmatrix newmat( mat.to_zgsmatrix() );
  return d*newmat;
}

Member Data Documentation

long const& zhsmatrix::m

matrix row size

Definition at line 9 of file zhsmatrix.hpp.

Referenced by checkup(), col(), operator*(), row(), to_zgematrix(), and to_zgsmatrix().

std::vector< std::vector<uint32_t> > zhsmatrix::line

vector of vector to store the entry information of component for each row and column

Definition at line 12 of file zhsmatrix.hpp.

Referenced by _(), clear(), col(), copy(), del(), isListed(), number(), operator()(), put(), resize(), row(), shallow_copy(), stretch(), swap(), zero(), zhsmatrix(), and ~zhsmatrix().


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Friends