source: Sophya/branches/Reza/Eval/JET/smtx.cc@ 2362

Last change on this file since 2362 was 2362, checked in by ansari, 22 years ago

Creation du module JET, Test / evaluation de Expressions Template

Reza 17 Avril 2003

File size: 3.8 KB
RevLine 
[2362]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
17bool 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
29template <class T>
30SimpleMatrix<T>::SimpleMatrix()
31 : MtxSize(), JETExpression<T, JETExpMtx<T> >(), dbv_(&data_, this)
32{
33 Expression().JETExpMtxSet(&data_, this);
34}
35
36template <class T>
37SimpleMatrix<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
43template <class T>
44SimpleMatrix<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
50template <class T>
51SimpleMatrix<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
56template <class T>
57SimpleMatrix<T>::~SimpleMatrix()
58{
59}
60
61
62template <class T>
63void 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
72template <class T>
73SimpleMatrix<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
87template <class T>
88SimpleMatrix<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
96template <class T>
97SimpleMatrix<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
107template <class T>
108void 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
118template <class T>
119SimpleMatrix<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
127template <class T>
128SimpleMatrix<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
136template <class T>
137SimpleMatrix<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
145template <class T>
146SimpleMatrix<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
Note: See TracBrowser for help on using the repository browser.