//=============================================================================
//! Base class for Small Real Double-precision Symmetric Matrix Class
class dsymatrix_small_base
{
public:
//////// constructor ////////
dsymatrix_small_base(){;}
virtual ~dsymatrix_small_base(){;}
};
//=============================================================================
//! Samll Real Double-precision Symmetric Matrix Class
template<long n> class dsymatrix_small : public dsymatrix_small_base
{
public:
//////// data ////////
double array[(n*(n+1))/2];
//////// constructor ////////
dsymatrix_small(){;}
dsymatrix_small(const double& x){
for(long k=0; k<(n*(n+1))/2; k++){ array[k]=x; }
}
~dsymatrix_small(){;}
//////// function ////////
double& operator()(const long& i, const long& j){
#ifdef CPPL_DEBUG
if(i<j){ std::cerr << "[ERROR]dsymatrix_small::operator(): i<j" << std::endl; exit(1); }
#endif
//const long I(max(i,j)), J(min(i,j)); return array[(I*(I+1))/2 +J];
return array[(i*(i+1))/2 +j];
}
double operator()(const long& i, const long& j) const{
#ifdef CPPL_DEBUG
if(i<j){ std::cerr << "[ERROR]dsymatrix_small::operator(): i<j" << std::endl; exit(1); }
#endif
//const long I(max(i,j)), J(min(i,j)); return array[(I*(I+1))/2 +J];
return array[(i*(i+1))/2 +j];
}
//long get_m(){ return n; }
//long get_n(){ return n; }
dsymatrix_small<n>& zero(){
for(long i=0; i<n; i++){ for(long j=0; j<=i; j++){ (*this)(i,j)=0.; } }
return *this;
}
dsymatrix_small<n>& identity(){
zero();
for(long k=0; k<n; k++){ (*this)(k,k)=1.; }
return *this;
}
};
//=============================================================================
template<long n>
inline std::ostream& operator<<(std::ostream& s, const dsymatrix_small<n>& A)
{
s << std::setiosflags(std::ios::showpos);
for(long i=0; i<n; i++){
for(long j=0; j<=i; j++){ s << " " << A(i,j) << " "<< std::flush; }
for(long j=i+1; j<n; j++){ s << "{" << A(j,i) << "}" << std::flush; }
s << std::endl;
}
return s;
}