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