1 | #include "machdefs.h"
|
---|
2 | #include "pexceptions.h"
|
---|
3 |
|
---|
4 | #include <math.h>
|
---|
5 |
|
---|
6 | #include "smtx.h"
|
---|
7 |
|
---|
8 | //--------------------------------------------------------
|
---|
9 | // Test d'expression template sur tableaux
|
---|
10 | // Reza - Avril 2003
|
---|
11 | //--------------------------------------------------------
|
---|
12 |
|
---|
13 | // ---------------------------------------------------
|
---|
14 | // ------------- Classe de matrice -------------------
|
---|
15 | // ---------------------------------------------------
|
---|
16 |
|
---|
17 | template <class T>
|
---|
18 | SimpleMatrix<T>::SimpleMatrix()
|
---|
19 | : MtxSize(), JETExpression<T, JETExpMtx<T> >(), dbv_(&data_, this)
|
---|
20 | {
|
---|
21 | Expression().JETExpMtxSet(&data_, this);
|
---|
22 | }
|
---|
23 |
|
---|
24 | template <class T>
|
---|
25 | SimpleMatrix<T>::SimpleMatrix(sa_size_t nr, sa_size_t nc)
|
---|
26 | : MtxSize(nr, nc), JETExpression<T, JETExpMtx<T> >(), data_(nr*nc), dbv_(&data_, this)
|
---|
27 | {
|
---|
28 | Expression().JETExpMtxSet(&data_, this);
|
---|
29 | }
|
---|
30 |
|
---|
31 | template <class T>
|
---|
32 | SimpleMatrix<T>::SimpleMatrix(const SimpleMatrix & m)
|
---|
33 | : MtxSize(m), JETExpression<T, JETExpMtx<T> >(), data_(m.data_), dbv_(&data_, this)
|
---|
34 | {
|
---|
35 | Expression().JETExpMtxSet(&data_, this);
|
---|
36 | }
|
---|
37 |
|
---|
38 | template <class T>
|
---|
39 | SimpleMatrix<T>::SimpleMatrix(const SimpleMatrix & m, bool share)
|
---|
40 | : MtxSize(m), JETExpression<T, JETExpMtx<T> >(dbv_), data_(m.data_, share), dbv_(&data_, this)
|
---|
41 | {
|
---|
42 | }
|
---|
43 |
|
---|
44 | template <class T>
|
---|
45 | SimpleMatrix<T>::~SimpleMatrix()
|
---|
46 | {
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 | template <class T>
|
---|
51 | void SimpleMatrix<T>::ReSize(const MtxSize & a)
|
---|
52 | {
|
---|
53 | if (CompareSize(a)) return;
|
---|
54 | if (this == &a) return;
|
---|
55 | MtxSize::ReSize(a);
|
---|
56 | data_.Realloc(nrow_*ncol_);
|
---|
57 | return;
|
---|
58 | }
|
---|
59 |
|
---|
60 | template <class T>
|
---|
61 | SimpleMatrix<T>& SimpleMatrix<T>::Set(const SimpleMatrix & b)
|
---|
62 | {
|
---|
63 | if (this == &b) return(*this);
|
---|
64 | if ((b.nrow_ == 0) || (b.ncol_ == 0) )
|
---|
65 | throw RangeCheckError("SimpleMatrix::Set() Size(b) = 0");
|
---|
66 | if (nrow_ == 0) {
|
---|
67 | nrow_ = b.nrow_; ncol_ = b.ncol_;
|
---|
68 | }
|
---|
69 | else if ((nrow_ > 0) && ((nrow_ != b.nrow_) || (ncol_ != b.ncol_)) )
|
---|
70 | throw(SzMismatchError("SimpleMatrix::Set() Size(a) != Size(b)"));
|
---|
71 | data_ = b.data_;
|
---|
72 | return(*this);
|
---|
73 | }
|
---|
74 |
|
---|
75 | template <class T>
|
---|
76 | SimpleMatrix<T>& SimpleMatrix<T>::Init(T c)
|
---|
77 | {
|
---|
78 | if ((nrow_ == 0) || (ncol_ == 0))
|
---|
79 | throw RangeCheckError("SimpleMatrix<T>::Init(T c) Size=0");
|
---|
80 | data_ = c;
|
---|
81 | return(*this);
|
---|
82 | }
|
---|
83 |
|
---|
84 | template <class T>
|
---|
85 | SimpleMatrix<T>& SimpleMatrix<T>::Init(T c, T step)
|
---|
86 | {
|
---|
87 | if ((nrow_ == 0) || (ncol_ == 0))
|
---|
88 | throw RangeCheckError("SimpleMatrix<T>::Init(T c. T s) Size=0");
|
---|
89 | for(sa_size_t k=0; k<nrow_*ncol_; k++) {
|
---|
90 | data_(k) = c; c += step;
|
---|
91 | }
|
---|
92 | return(*this);
|
---|
93 | }
|
---|
94 |
|
---|
95 | template <class T>
|
---|
96 | void SimpleMatrix<T>::Print(ostream& os) const
|
---|
97 | {
|
---|
98 | os << " SimpleMatrix<T>(nr=" << nrow_ << ",nc=" << ncol_ << ")" << endl;
|
---|
99 | for(sa_size_t r=0; r<nrow_; r++) {
|
---|
100 | for(sa_size_t c=0; c<ncol_; c++)
|
---|
101 | os << (*this)(r,c) << " , " ;
|
---|
102 | os << endl;
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | template <class T>
|
---|
107 | SimpleMatrix<T>& SimpleMatrix<T>::AddCst(T c)
|
---|
108 | {
|
---|
109 | if ((nrow_ == 0) || (ncol_ == 0))
|
---|
110 | throw RangeCheckError("SimpleMatrix<T>::AddCst() Size=0");
|
---|
111 | data_ += c;
|
---|
112 | return(*this);
|
---|
113 | }
|
---|
114 |
|
---|
115 | template <class T>
|
---|
116 | SimpleMatrix<T>& SimpleMatrix<T>::MulCst(T c)
|
---|
117 | {
|
---|
118 | if ((nrow_ == 0) || (ncol_ == 0))
|
---|
119 | throw RangeCheckError("SimpleMatrix<T>::MulCst() Size=0");
|
---|
120 | data_ *= c;
|
---|
121 | return(*this);
|
---|
122 | }
|
---|
123 |
|
---|
124 | template <class T>
|
---|
125 | SimpleMatrix<T>& SimpleMatrix<T>::AddElt(const SimpleMatrix & b)
|
---|
126 | {
|
---|
127 | if (! CompareSize(b) )
|
---|
128 | throw(SzMismatchError("SimpleMatrix::AddElt() Size(a) != Size(b)"));
|
---|
129 | data_ += b.data_;
|
---|
130 | return(*this);
|
---|
131 | }
|
---|
132 |
|
---|
133 | template <class T>
|
---|
134 | SimpleMatrix<T>& SimpleMatrix<T>::MulElt(const SimpleMatrix & b)
|
---|
135 | {
|
---|
136 | if (! CompareSize(b) )
|
---|
137 | throw(SzMismatchError("SimpleMatrix::MulElt() Size(a) != Size(b)"));
|
---|
138 | data_ *= b.data_;
|
---|
139 | return(*this);
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|