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

Real Double-precision Symmetric Sparse Matrix Class. More...

#include <dssmatrix.hpp>

List of all members.

Public Member Functions

 dssmatrix ()
 dssmatrix (const dssmatrix &)
 dssmatrix (const _dssmatrix &)
 dssmatrix (const long &, const long=0)
 dssmatrix (const char *)
 ~dssmatrix ()
_zhsmatrix to_zhsmatrix () const
_dgematrix to_dgematrix () const
_dsymatrix to_dsymatrix () const
_dgsmatrix to_dgsmatrix () const
double operator() (const long &, const long &) const
double & operator() (const long &, const long &)
dssmatrixput (const long &, const long &, const double &)
dssmatrixdel (const long, const long)
dssmatrixdel (const long)
void write (const char *) const
void read (const char *)
void clear ()
dssmatrixzero ()
void chsign ()
void copy (const dssmatrix &)
void shallow_copy (const _dssmatrix &)
dssmatrixresize (const long &, const long=0, const long=0)
void stretch (const long &)
bool isListed (const long &, const long &) const
long number (const long &, const long &) const
_drovector row (const long &) const
_dcovector col (const long &) const
void diet (const double=DBL_MIN)
long diag_front ()
void reorder (const bool=0)
void rebuild ()
void checkup ()
dssmatrixoperator= (const dssmatrix &)
dssmatrixoperator= (const _dssmatrix &)
dssmatrixoperator+= (const dssmatrix &)
dssmatrixoperator+= (const _dssmatrix &)
dssmatrixoperator-= (const dssmatrix &)
dssmatrixoperator-= (const _dssmatrix &)
dssmatrixoperator*= (const double &)
dssmatrixoperator/= (const double &)

Public Attributes

long const & m
 matrix row size
long n
 matrix column size
std::vector< dcomponentdata
 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 dssmatrix &)
void swap (dssmatrix &, dssmatrix &)
_dssmatrix _ (dssmatrix &)
_dssmatrix t (const dssmatrix &)
void idamax (long &, long &, const dssmatrix &)
double damax (const dssmatrix &)
const dssmatrixoperator+ (const dssmatrix &)
_dssmatrix operator- (const dssmatrix &)
_dgematrix operator+ (const dssmatrix &, const dgematrix &)
_dgematrix operator+ (const dssmatrix &, const _dgematrix &)
_dgematrix operator+ (const dssmatrix &, const dsymatrix &)
_dgematrix operator+ (const dssmatrix &, const _dsymatrix &)
_dgematrix operator+ (const dssmatrix &, const dgbmatrix &)
_dgematrix operator+ (const dssmatrix &, const _dgbmatrix &)
_dgsmatrix operator+ (const dssmatrix &, const dgsmatrix &)
_dgsmatrix operator+ (const dssmatrix &, const _dgsmatrix &)
_dssmatrix operator+ (const dssmatrix &, const dssmatrix &)
_dssmatrix operator+ (const dssmatrix &, const _dssmatrix &)
_dgematrix operator- (const dssmatrix &, const dgematrix &)
_dgematrix operator- (const dssmatrix &, const _dgematrix &)
_dgematrix operator- (const dssmatrix &, const dsymatrix &)
_dgematrix operator- (const dssmatrix &, const _dsymatrix &)
_dgematrix operator- (const dssmatrix &, const dgbmatrix &)
_dgematrix operator- (const dssmatrix &, const _dgbmatrix &)
_dgsmatrix operator- (const dssmatrix &, const dgsmatrix &)
_dgsmatrix operator- (const dssmatrix &, const _dgsmatrix &)
_dssmatrix operator- (const dssmatrix &, const dssmatrix &)
_dssmatrix operator- (const dssmatrix &, const _dssmatrix &)
_dcovector operator* (const dssmatrix &, const dcovector &)
_dcovector operator* (const dssmatrix &, const _dcovector &)
_dgematrix operator* (const dssmatrix &, const dgematrix &)
_dgematrix operator* (const dssmatrix &, const _dgematrix &)
_dgematrix operator* (const dssmatrix &, const dsymatrix &)
_dgematrix operator* (const dssmatrix &, const _dsymatrix &)
_dgematrix operator* (const dssmatrix &, const dgbmatrix &)
_dgematrix operator* (const dssmatrix &, const _dgbmatrix &)
_dgsmatrix operator* (const dssmatrix &, const dgsmatrix &)
_dgsmatrix operator* (const dssmatrix &, const _dgsmatrix &)
_dgsmatrix operator* (const dssmatrix &, const dssmatrix &)
_dgsmatrix operator* (const dssmatrix &, const _dssmatrix &)
_dssmatrix operator* (const dssmatrix &, const double &)
_dssmatrix operator/ (const dssmatrix &, const double &)
_dssmatrix operator* (const double &, const dssmatrix &)

Detailed Description

Real Double-precision Symmetric Sparse Matrix Class.

Definition at line 3 of file dssmatrix.hpp.


Constructor & Destructor Documentation

dssmatrix::dssmatrix ( ) [inline]

dssmatrix constructor without arguments

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

References data, line, and n.

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

dssmatrix copy constructor

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

References copy(), data, and line.

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

dssmatrix constructor to cast _dssmatrix

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

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

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

dssmatrix constructor with size specification

Definition at line 47 of file dssmatrix-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);
}
dssmatrix::dssmatrix ( const char *  filename) [inline]

dssmatrix constructor with filename

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

References data, line, and read().

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

dssmatrix destructor

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

References data, and line.

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

Member Function Documentation

_zhsmatrix dssmatrix::to_zhsmatrix ( ) const [inline]

cast to _zhsmatrix

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

References _, data, n, and zhsmatrix::put().

{VERBOSE_REPORT;
  zhsmatrix newmat(n,data.size());
  for(std::vector<dcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
    newmat.put(it->i, it->j, comple(it->v,0.0));
  }
  
  return _(newmat);
}
_dgematrix dssmatrix::to_dgematrix ( ) const [inline]

convert to _dgematrix

Definition at line 19 of file dssmatrix-cast.hpp.

References _, data, m, n, and dgematrix::zero().

{VERBOSE_REPORT;
  dgematrix newmat(m,n);
  newmat.zero();
  for(std::vector<dcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
    newmat(it->i, it->j) =it->v;
    newmat(it->j, it->i) =it->v;
  }
  
  return _(newmat);
}
_dsymatrix dssmatrix::to_dsymatrix ( ) const [inline]

convert to _dsymatrix

Definition at line 33 of file dssmatrix-cast.hpp.

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

{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);
}
_dgsmatrix dssmatrix::to_dgsmatrix ( ) const [inline]

convert to _dgsmatrix

Definition at line 46 of file dssmatrix-cast.hpp.

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

{VERBOSE_REPORT;
  dgsmatrix newmat( dgsmatrix(m,n,data.size()*2) );
  newmat.zero();
  for(std::vector<dcomponent>::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, it->v);
    }
  }
  
  return _(newmat);
}
double dssmatrix::operator() ( const long &  i,
const long &  j 
) const [inline]

operator() for const object

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

References 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].i==ii && data[*p].j==jj){ return data[*p].v; }
  }
  
  //// (i,j) component was not found ////
  return 0.0;
}
double & dssmatrix::operator() ( const long &  i,
const long &  j 
) [inline]

operator() for const object

Definition at line 26 of file dssmatrix-io.hpp.

References 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>::iterator p=line[ii].begin(); p!=line[ii].end(); p++){
    if(data[*p].i==ii && data[*p].j==jj){ return data[*p].v; }
  }
  
  //////// (i,j) component not found ////////
  line[ii].push_back(data.size());
  if(i!=j){//off-diagonal
    line[jj].push_back(data.size());
  }
  data.push_back(dcomponent(ii,jj,0.));
  return data.back().v;
}
dssmatrix & dssmatrix::put ( const long &  i,
const long &  j,
const double &  v 
) [inline]

put value with volume cheack without isListed check

Definition at line 58 of file dssmatrix-io.hpp.

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

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

{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(dcomponent(ii,jj,v));
  return *this;
}
dssmatrix & dssmatrix::del ( const long  i,
const long  j 
) [inline]

delete the entry of a component

Definition at line 92 of file dssmatrix-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]@dssmatrix::del(long&, long&): The required component was not listed. Your input was (" << i << "," << j << ")." << std::endl;
#endif//CPPL_DEBUG
  
  return *this;
}
dssmatrix & dssmatrix::del ( const long  c) [inline]

delete the entry of an element

Definition at line 147 of file dssmatrix-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 dssmatrix::write ( const char *  filename) const [inline]

Definition at line 244 of file dssmatrix-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 << "#dssmatrix" << " " << n << std::endl;
  for(std::vector<dcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
    ofs << it->i << " " << it->j << " " << it->v << std::endl;
  }
  
  ofs.close();
}
void dssmatrix::read ( const char *  filename) [inline]

Definition at line 261 of file dssmatrix-io.hpp.

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

Referenced by dssmatrix().

{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 != "dssmatrix" && id != "#dssmatrix" ){
    ERROR_REPORT;
    std::cerr << "The type name of the file \"" << filename << "\" is not dssmatrix." << std::endl
              << "Its type name was " << id << " ." << std::endl;
    exit(1);
  }
  
  s >> n;
  resize(n);
  
  double 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 dssmatrix::clear ( ) [inline]

clear all the matrix data and set the sizes 0

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

References data, line, and n.

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

change the matrix into a zero matrix

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

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

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

change sign(+/-) of the matrix

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

References data.

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

make a deep copy of the matrix

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

References data, line, and n.

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

{VERBOSE_REPORT;
  n =mat.n;
  data =mat.data;
  line =mat.line;
}
void dssmatrix::shallow_copy ( const _dssmatrix 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 dssmatrix-misc.hpp.

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

Referenced by operator=().

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

resize the matrix

Definition at line 54 of file dssmatrix-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, the length of arrays, and line size 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 dssmatrix::stretch ( const long &  dn) [inline]

stretch the matrix size

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

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

{VERBOSE_REPORT;
#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
  
  //////// zero ////////
  if(dn==0){ return; }

  //////// non-zero ////////
  n +=dn;
  
  if(dn<0){
    //// delete components over the new size ////
    for(std::vector<dcomponent>::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) );
    }
  }
}
bool dssmatrix::isListed ( const long &  i,
const long &  j 
) const [inline]

check if the component is listed

Definition at line 116 of file dssmatrix-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].i==ii && data[*p].j==jj){ return 1; }
  }
  
  return 0;
}
long dssmatrix::number ( const long &  i,
const long &  j 
) const [inline]

return the element number of the component

Definition at line 137 of file dssmatrix-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].i==ii && data[*p].j==jj){ return *p; }
  }
  
  return -1;
}
_drovector dssmatrix::row ( const long &  _m) const [inline]

get row of the matrix

Definition at line 162 of file dssmatrix-misc.hpp.

References _, data, i(), line, m, n, and drovector::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
  
  drovector vec(n);
  vec.zero();
  for(std::vector<uint32_t>::const_iterator p=line[_m].begin(); p!=line[_m].end(); p++){
    if(long(data[*p].i)==_m){
      vec(data[*p].j) =data[*p].v;
    }
    else{
      vec(data[*p].i) =data[*p].v;
    }
  }
  return _(vec);
}
_dcovector dssmatrix::col ( const long &  _n) const [inline]

get column of the matrix

Definition at line 188 of file dssmatrix-misc.hpp.

References _, data, i(), line, m, n, and dcovector::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
  
  dcovector vec(m);
  vec.zero();
  for(std::vector<uint32_t>::const_iterator p=line[_n].begin(); p!=line[_n].end(); p++){
    if(long(data[*p].i)==_n){
      vec(data[*p].j) =data[*p].v;
    }
    else{
      vec(data[*p].i) =data[*p].v;
    }
  }
  return _(vec);
}
void dssmatrix::diet ( const double  eps = DBL_MIN) [inline]

erase components less than DBL_MIN

Definition at line 218 of file dssmatrix-misc.hpp.

References data, and del().

{VERBOSE_REPORT;
  for(std::vector<dcomponent>::reverse_iterator it=data.rbegin(); it!=data.rend(); it++){
    if( fabs(it->v)<eps ){ del(data.rend()-it-1); }
  }
}
long dssmatrix::diag_front ( ) [inline]

reorder components so that all diagonal componets are placed in front

Definition at line 227 of file dssmatrix-misc.hpp.

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

{VERBOSE_REPORT;
  //////// set initial dsize ////////
  long dsize(0);
  for(std::vector<dcomponent>::iterator it=data.begin(); it!=data.end(); it++){
    if(it->i==it->j){ dsize++; }
    else{ break; }
  }
  
  //////// swapping loop ////////
  for(std::vector<dcomponent>::reverse_iterator it=data.rbegin(); it!=data.rend()-dsize; it++){
    if(it->i==it->j){//is diag
      long c(data.rend()-it-1);//current it's index
      long i(data[dsize].i), j(data[dsize].j), k(it->i);
      //// search (k,k) line ////
      for(std::vector<uint32_t>::iterator p=line[k].begin(); p!=line[k].end(); p++){
        if(long(data[*p].i)==k && long(data[*p].j)==k){ *p=dsize; }
      }
      //// search (i,j) line ////
      for(std::vector<uint32_t>::iterator p=line[i].begin(); p!=line[i].end(); p++){
        if(long(*p)==dsize){ *p=c; }
      }
      //// search (j,i) line ////
      if(i!=j){
        for(std::vector<uint32_t>::iterator p=line[j].begin(); p!=line[j].end(); p++){
          if(long(*p)==dsize){ *p=c; }
        }
      }
      else{//i==j
        it--;
      }
      //// swap ////
      std::swap(data[dsize],data[c]);
      //// update ////
      dsize++;
    }
  }
  
  return dsize;
}
void dssmatrix::reorder ( const bool  mode = 0) [inline]

reorder components

Definition at line 270 of file dssmatrix-misc.hpp.

References data, ilt(), jlt(), and rebuild().

{VERBOSE_REPORT;
  //// sort data ////
  if(mode==0){
    std::sort(data.begin(), data.end(), dcomponent::ilt);
  }
  else{
    std::sort(data.begin(), data.end(), dcomponent::jlt);
  }
  //// rebuild line ////
  rebuild();
}
void dssmatrix::rebuild ( ) [inline]

rebuild line

Definition at line 285 of file dssmatrix-misc.hpp.

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

Referenced by reorder().

{VERBOSE_REPORT;
  //// clear line ////
  for(long i=0; i<n; i++){ line[i].resize(0); }
  
  //// build line ////
  uint32_t c(0);
  for(std::vector<dcomponent>::iterator it=data.begin(); it!=data.end(); it++){
    line[it->i].push_back(c);
    if( (it->i) != (it->j) ){
      line[it->j].push_back(c);
    }
    c++;
  }
}
void dssmatrix::checkup ( ) [inline]

health checkup

Definition at line 307 of file dssmatrix-misc.hpp.

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

{VERBOSE_REPORT;
  //////// write ////////
  for(std::vector<dcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
    std::cerr << "array[" << it-data.begin() << "] = (" << it->i << "," << it->j << ") = " << it->v << std::endl;
  }
  std::cerr << std::endl;
  
  for(long i=0; i<n; i++){
    std::cerr << "line[" << i << "] =" << std::flush;
    for(unsigned long k=0; k<line[i].size(); k++){
      std::cerr << " " << line[i][k] << std::flush;
    }
    std::cerr << std::endl;
  }
  std::cerr << std::endl;
  
  //////// Elements ////////
  for(std::vector<dcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
    //// m bound ////
    if(long(it->i)>=n){
      ERROR_REPORT;
      std::cerr << "The indx of the " << it-data.begin() << "th element is out of the matrix size." << std::endl
                << "Its i index was " << it->i << "." << std::endl;
      exit(1);
    }
    
    //// n bound ////
    if(long(it->j)>=n){
      ERROR_REPORT;
      std::cerr << "The jndx of the " << it-data.begin() << "th element is out of the matrix size." << std::endl
                << "Its j index was " << it->j << "." << std::endl;
      exit(1);
    }
    
    //// double-listed ////
    for(std::vector<dcomponent>::const_iterator IT=it+1; IT!=data.end(); IT++){
      if( it->i==IT->i && it->j==IT->j ){
        ERROR_REPORT;
        std::cerr << "The (" << it->i << ", " << it->j << ") component is double-listed at the " << it-data.begin() << "th and the" << IT-data.begin() << "the elements."<< std::endl;
        exit(1);
      }
    }
  }
  
  //////// NOTE ////////
  std::cerr << "# [NOTE]@dssmatrix::checkup(): This symmetric sparse matrix is fine." << std::endl;
}
dssmatrix & dssmatrix::operator= ( const dssmatrix mat) [inline]

dssmatrix=dssmatrix operator

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

References copy(), and data.

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

dssmatrix=_dssmatrix operator

Definition at line 3 of file dssmatrix-_dssmatrix.hpp.

References shallow_copy().

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

dssmatrix+=dssmatrix operator

Definition at line 17 of file dssmatrix-dssmatrix.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<dcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    (*this)(it->i,it->j) +=it->v;
  }
  return *this;
}
dssmatrix & dssmatrix::operator+= ( const _dssmatrix mat) [inline]

dssmatrix+=_dssmatrix operator

Definition at line 15 of file dssmatrix-_dssmatrix.hpp.

References _dssmatrix::data, _dssmatrix::destroy(), n, and _dssmatrix::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<dcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    (*this)(it->i,it->j) +=it->v;
  }
  
  mat.destroy();
  return *this;
}
dssmatrix & dssmatrix::operator-= ( const dssmatrix mat) [inline]

dssmatrix-=dssmatrix operator

Definition at line 36 of file dssmatrix-dssmatrix.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<dcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    (*this)(it->i,it->j) -=it->v;
  }
  return *this;
}
dssmatrix & dssmatrix::operator-= ( const _dssmatrix mat) [inline]

dssmatrix-=_dssmatrix operator

Definition at line 36 of file dssmatrix-_dssmatrix.hpp.

References _dssmatrix::data, _dssmatrix::destroy(), n, and _dssmatrix::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<dcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    (*this)(it->i,it->j) -=it->v;
  }
  
  mat.destroy();
  return *this;
}
dssmatrix & dssmatrix::operator*= ( const double &  d) [inline]

dssmatrix*=double operator

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

References data.

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

dssmatrix/=double operator

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

References data.

{VERBOSE_REPORT;
  for(std::vector<dcomponent>::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 dssmatrix mat 
) [friend]

Definition at line 210 of file dssmatrix-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 << "{" << mat.data[c].v << "}";
        }
      }
    }
    s << std::endl;
  }
  
  return s;
}
void swap ( dssmatrix A,
dssmatrix B 
) [friend]

swap two matrices

Definition at line 362 of file dssmatrix-misc.hpp.

Referenced by diag_front().

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

convert user object to smart-temporary object

Definition at line 371 of file dssmatrix-misc.hpp.

Referenced by col(), row(), to_dgematrix(), to_dgsmatrix(), to_dsymatrix(), and to_zhsmatrix().

{VERBOSE_REPORT;
  _dssmatrix 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;
}
_dssmatrix t ( const dssmatrix mat) [friend]

return transposed dssmatrix

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

{VERBOSE_REPORT;
#ifdef  CPPL_DEBUG
  WARNING_REPORT;
  std::cerr << "This function call has no effect since the matrix is symmetric." << std::endl;
#endif//CPPL_DEBUG

  dssmatrix newmat(mat);
  return _(newmat);
}
void idamax ( long &  i,
long &  j,
const dssmatrix mat 
) [friend]

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

Definition at line 21 of file dssmatrix-calc.hpp.

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

return its largest absolute value

Definition at line 37 of file dssmatrix-calc.hpp.

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

+dssmatrix operator

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

{VERBOSE_REPORT;
  return mat;
}
_dssmatrix operator- ( const dssmatrix mat) [friend]

-dssmatrix operator

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

{VERBOSE_REPORT;
  dssmatrix newmat(mat);
  for(std::vector<dcomponent>::iterator it=newmat.data.begin(); it!=newmat.data.end(); it++){
    it->v =-it->v;
  }
  
  return _(newmat);
}
_dgematrix operator+ ( const dssmatrix ,
const dgematrix  
) [friend]
_dgematrix operator+ ( const dssmatrix ,
const _dgematrix  
) [friend]
_dgematrix operator+ ( const dssmatrix ,
const dsymatrix  
) [friend]
_dgematrix operator+ ( const dssmatrix ,
const _dsymatrix  
) [friend]
_dgematrix operator+ ( const dssmatrix ,
const dgbmatrix  
) [friend]
_dgematrix operator+ ( const dssmatrix ,
const _dgbmatrix  
) [friend]
_dgsmatrix operator+ ( const dssmatrix ,
const dgsmatrix  
) [friend]
_dgsmatrix operator+ ( const dssmatrix ,
const _dgsmatrix  
) [friend]
_dssmatrix operator+ ( const dssmatrix matA,
const dssmatrix matB 
) [friend]

dssmatrix+dssmatrix operator

Definition at line 59 of file dssmatrix-dssmatrix.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
  
  dssmatrix newmat(matA);
  for(std::vector<dcomponent>::const_iterator it=matB.data.begin(); it!=matB.data.end(); it++){
    newmat(it->i,it->j) +=it->v;
  }
  return _(newmat);
}
_dssmatrix operator+ ( const dssmatrix matA,
const _dssmatrix matB 
) [friend]

dssmatrix+_dssmatrix operator

Definition at line 61 of file dssmatrix-_dssmatrix.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

  dssmatrix newmat(matB);
  
  for(std::vector<dcomponent>::const_iterator it=matA.data.begin(); it!=matA.data.end(); it++){
    newmat(it->i,it->j) +=it->v;
  }
  
  return _(newmat);
}
_dgematrix operator- ( const dssmatrix ,
const dgematrix  
) [friend]
_dgematrix operator- ( const dssmatrix ,
const _dgematrix  
) [friend]
_dgematrix operator- ( const dssmatrix ,
const dsymatrix  
) [friend]
_dgematrix operator- ( const dssmatrix ,
const _dsymatrix  
) [friend]
_dgematrix operator- ( const dssmatrix ,
const dgbmatrix  
) [friend]
_dgematrix operator- ( const dssmatrix ,
const _dgbmatrix  
) [friend]
_dgsmatrix operator- ( const dssmatrix ,
const dgsmatrix  
) [friend]
_dgsmatrix operator- ( const dssmatrix ,
const _dgsmatrix  
) [friend]
_dssmatrix operator- ( const dssmatrix matA,
const dssmatrix matB 
) [friend]

dssmatrix-dssmatrix operator

Definition at line 79 of file dssmatrix-dssmatrix.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

  dssmatrix newmat(matA);
  for(std::vector<dcomponent>::const_iterator it=matB.data.begin(); it!=matB.data.end(); it++){
    newmat(it->i,it->j) -=it->v;
  }
  return _(newmat);
}
_dssmatrix operator- ( const dssmatrix matA,
const _dssmatrix matB 
) [friend]

dssmatrix-_dssmatrix operator

Definition at line 83 of file dssmatrix-_dssmatrix.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
  
  dssmatrix newmat(matB);
  
  for(std::vector<dcomponent>::const_iterator it=matA.data.begin(); it!=matA.data.end(); it++){
    newmat(it->i,it->j) -=it->v;
  }
  
  return _(newmat);
}
_dcovector operator* ( const dssmatrix mat,
const dcovector vec 
) [friend]

dssmatrix*dcovector operator

Definition at line 3 of file dssmatrix-dcovector.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

  dcovector newvec(mat.n);
  newvec.zero();
  
  for(std::vector<dcomponent>::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) +=it->v*vec(it->i);
    }
  }
  
  return _(newvec);
}
_dcovector operator* ( const dssmatrix mat,
const _dcovector vec 
) [friend]

dssmatrix*_dcovector operator

Definition at line 3 of file dssmatrix-_dcovector.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
  
  dcovector newvec(dcovector(mat.n));
  newvec.zero();
  
  for(std::vector<dcomponent>::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) +=it->v*vec(it->i);
    }
  }
  
  vec.destroy();
  return _(newvec);
}
_dgematrix operator* ( const dssmatrix ,
const dgematrix  
) [friend]
_dgematrix operator* ( const dssmatrix ,
const _dgematrix  
) [friend]
_dgematrix operator* ( const dssmatrix ,
const dsymatrix  
) [friend]
_dgematrix operator* ( const dssmatrix ,
const _dsymatrix  
) [friend]
_dgematrix operator* ( const dssmatrix ,
const dgbmatrix  
) [friend]
_dgematrix operator* ( const dssmatrix ,
const _dgbmatrix  
) [friend]
_dgsmatrix operator* ( const dssmatrix ,
const dgsmatrix  
) [friend]
_dgsmatrix operator* ( const dssmatrix ,
const _dgsmatrix  
) [friend]
_dgsmatrix operator* ( const dssmatrix ,
const dssmatrix  
) [friend]
_dgsmatrix operator* ( const dssmatrix ,
const _dssmatrix  
) [friend]
_dssmatrix operator* ( const dssmatrix mat,
const double &  d 
) [friend]

dssmatrix*double operator

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

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

dssmatrix/double operator

Definition at line 38 of file dssmatrix-double.hpp.

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

double*dssmatrix operator

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

{VERBOSE_REPORT;
  dssmatrix newmat(mat.n, mat.data.size());
  for(std::vector<dcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    newmat.put(it->i, it->j, d*it->v);
  }
  return _(newmat);
}

Member Data Documentation

long const& dssmatrix::m

matrix row size

Definition at line 9 of file dssmatrix.hpp.

Referenced by col(), operator*(), row(), to_dgematrix(), and to_dgsmatrix().

std::vector< std::vector<uint32_t> > dssmatrix::line

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

Definition at line 12 of file dssmatrix.hpp.

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


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