//=============================================================================
//! Samll Real Double-precision General Dence Matrix Class
template<long M, long N> class dgematrix_small
{
public:
//////// data ////////
static const long m =M;
static const long n =N;
double array[M*N];
//////// constructor ////////
dgematrix_small(){;}
dgematrix_small(const double& x){
for(long k=0; k<M*N; k++){ array[k]=x; }
}
~dgematrix_small(){;}
//////// function ////////
double& operator()(const long& i, const long& j);
double operator()(const long& i, const long& j)const;
dgematrix_small<M,N>& zero(){
for(long k=0; k<M*N; k++){ array[k]=0.; }
return *this;
}
dgematrix_small<M,N>& identity(){
zero();
for(long k=0; k<std::min(M,N); k++){ (*this)(k,k)=1.; }
return *this;
}
dgematrix_small<M,N>& set(const long& i, const long& j, const double& v){
(*this)(i,j)=v;
return *this;
}
dcovector_small<M> col(const long& j) const{
dcovector_small<M> vec;
for(long i=0; i<M; i++){ vec(i)=(*this)(i,j); }
return vec;
}
drovector_small<N> row(const long& i) const{
drovector_small<N> vec;
for(long j=0; j<N; j++){ vec(j)=(*this)(i,j); }
return vec;
}
void write(const char* filename) const;
void read(const char* filename);
_dgematrix to_dgematrix() const{
dgematrix mat(M,N);
for(long i=0; i<M; i++){
for(long j=0; j<N; j++){
mat(i,j)=(*this)(i,j);
}
}
return _(mat);
}
};