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

Last change on this file since 4054 was 4054, checked in by ansari, 14 years ago

ajout programme telacc.cc pour test rapidite acces aux elements, Reza 17/03/2012

File size: 3.6 KB
RevLine 
[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
17template <class T>
18SimpleMatrix<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
25template <class T>
26SimpleMatrix<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
33template <class T>
34SimpleMatrix<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
41template <class T>
42SimpleMatrix<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
48template <class T>
49SimpleMatrix<T>::~SimpleMatrix()
50{
51}
52
53
54template <class T>
55void 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
65template <class T>
66SimpleMatrix<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
81template <class T>
82SimpleMatrix<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
90template <class T>
91SimpleMatrix<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
101template <class T>
102void 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
112template <class T>
113SimpleMatrix<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
121template <class T>
122SimpleMatrix<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
130template <class T>
131SimpleMatrix<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
139template <class T>
140SimpleMatrix<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
Note: See TracBrowser for help on using the repository browser.