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