source: Sophya/trunk/Eval/JET/smtx.cc@ 4017

Last change on this file since 4017 was 3257, checked in by ansari, 18 years ago

Petite modif (liee a l'identification des templates) pour compil avec gcc 4 , Reza 27/05/2007

File size: 3.5 KB
Line 
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
17template <class T>
18SimpleMatrix<T>::SimpleMatrix()
19 : MtxSize(), JETExpression<T, JETExpMtx<T> >(), dbv_(&data_, this)
20{
21 this->Expression().JETExpMtxSet(&data_, this);
22}
23
24template <class T>
25SimpleMatrix<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 this->Expression().JETExpMtxSet(&data_, this);
29}
30
31template <class T>
32SimpleMatrix<T>::SimpleMatrix(const SimpleMatrix & m)
33 : MtxSize(m), JETExpression<T, JETExpMtx<T> >(), data_(m.data_), dbv_(&data_, this)
34{
35 this->Expression().JETExpMtxSet(&data_, this);
36}
37
38template <class T>
39SimpleMatrix<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
44template <class T>
45SimpleMatrix<T>::~SimpleMatrix()
46{
47}
48
49
50template <class T>
51void 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
60template <class T>
61SimpleMatrix<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
75template <class T>
76SimpleMatrix<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
84template <class T>
85SimpleMatrix<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
95template <class T>
96void 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
106template <class T>
107SimpleMatrix<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
115template <class T>
116SimpleMatrix<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
124template <class T>
125SimpleMatrix<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
133template <class T>
134SimpleMatrix<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
Note: See TracBrowser for help on using the repository browser.