Menu

[r80]: / trunk / include / small / dgematrix_small.hpp  Maximize  Restore  History

Download this file

70 lines (62 with data), 2.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//=============================================================================
//! Base class for Small Real Double-precision General Dence Matrix Class
class dgematrix_small_base
{
public:
//////// constructor ////////
dgematrix_small_base(){;}
virtual ~dgematrix_small_base(){;}
};
//=============================================================================
//! Samll Real Double-precision General Dence Matrix Class
template<long m, long n> class dgematrix_small : public dgematrix_small_base
{
public:
//////// data ////////
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){ return array[n*i+j]; }
double operator()(const long& i, const long& j)const{ return array[n*i+j]; }
//long get_m(){ return m; }
//long get_n(){ return n; }
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<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;
}
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
template<long m, long n>
inline std::ostream& operator<<(std::ostream& s, const dgematrix_small<m,n>& A)
{
s << std::setiosflags(std::ios::showpos);
for(long i=0; i<m; i++){
for(long j=0; j<n; j++){
s << " " << A(i,j);
}
s << std::endl;
}
return s;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.