source: Sophya/trunk/Eval/JET/smtx.h@ 2537

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

This commit was generated by cvs2svn to compensate for changes in r2362,
which included commits to RCS files with non-trunk default branches.

File size: 4.3 KB
Line 
1#ifndef SMTX_H_SEEN
2#define SMTX_H_SEEN
3
4#include "machdefs.h"
5#include <iostream>
6
7#include "ndatablock.h"
8#include "ctimer.h"
9#include "timing.h"
10
11#include "jet.h"
12
13
14//========================================================
15// Test d'expression template sur tableaux
16// Reza - Avril 2003
17//========================================================
18
19
20// ---------------------------------------------------
21//------- Expression/iterateur sur matrice -----------
22// ---------------------------------------------------
23template <class T>
24class JETExpMtx {
25public:
26 JETExpMtx() : db_(NULL), msz_(NULL), pd_(NULL) { }
27 //cout << " DBG-AA" << hex << db_ << " - " << msz_ << dec << endl;}
28 JETExpMtx(NDataBlock<T> * db, MtxSize const * msz) :
29 db_(db), msz_(msz), pd_(NULL) { }
30 // cout << " DBG-BBB" << hex << db_ << " - " << msz_ << dec << endl; }
31 JETExpMtx(JETExpMtx const & a) : db_(a.db_), msz_(a.msz_), pd_(a.pd_) { }
32 // cout << " DBG-CCC" << hex << db_ << " - " << msz_ << dec << endl;}
33 inline T EvaluateAndStep() const { return (*pd_++); }
34 inline void Reset() const { pd_ = db_->Begin(); }
35 //{ if (db_ == NULL) cout << " AAA-BUG db_" << endl;
36 //pd_ = db_->Begin(); if (pd_ == NULL) cout << " BBB-BUG db_" << endl;}
37 inline MtxSize const & RefSize() const { return *msz_; }
38 // if (msz_ == NULL) cout << " BUG msz_ " << endl; return *msz_; }
39 void JETExpMtxSet(NDataBlock<T> * db, MtxSize const * msz)
40 { db_ = db; msz_ = msz; pd_ = NULL; }
41protected:
42 NDataBlock<T> * db_;
43 MtxSize const * msz_;
44 mutable T * pd_;
45};
46
47
48// ---------------------------------------------------
49// ------------- Classe de matrice -------------------
50// ---------------------------------------------------
51
52template <class T>
53class SimpleMatrix : public AnyDataObj, public MtxSize,
54 public JETExpression<T, JETExpMtx<T> > {
55public:
56 SimpleMatrix();
57 SimpleMatrix(sa_size_t nr, sa_size_t nc);
58 SimpleMatrix(const SimpleMatrix<T> & m);
59 SimpleMatrix(const SimpleMatrix<T> & m, bool share);
60 virtual ~SimpleMatrix();
61
62 virtual void ReSize(const MtxSize & a);
63
64 virtual SimpleMatrix<T>& Set(const SimpleMatrix<T> & a);
65
66 inline SimpleMatrix<T>& Set(JETEvaluator const & exp)
67 { exp.EvaluateAll(*this); return(*this); }
68
69 virtual SimpleMatrix<T>& Init(T c);
70 virtual SimpleMatrix<T>& Init(T c, T step);
71
72 inline SimpleMatrix<T>& operator = (const SimpleMatrix<T> & a)
73 { return Set(a); }
74 inline SimpleMatrix<T>& operator = (JETEvaluator const & a)
75 { return Set(a); }
76 inline SimpleMatrix<T>& operator = (T c)
77 { return Init(c); }
78
79 inline T operator()(int r, int c) const
80 { return data_(r*ncol_+c); }
81 inline T& operator()(int r, int c)
82 { return data_(r*ncol_+c); }
83
84 inline sa_size_t NRows() const {return nrow_; }
85 inline sa_size_t NCols() const {return ncol_; }
86 inline sa_size_t Size() const {return nrow_*ncol_; }
87
88 virtual void Print(ostream& os) const;
89
90 inline NDataBlock<T> const & DataBlock() const { return data_; }
91 inline NDataBlock<T>& DataBlock() { return data_; }
92
93 SimpleMatrix<T>& AddCst(T c);
94 SimpleMatrix<T>& MulCst(T c);
95
96 SimpleMatrix<T>& AddElt(const SimpleMatrix<T> & b);
97 SimpleMatrix<T>& MulElt(const SimpleMatrix<T> & b);
98
99 inline SimpleMatrix<T>& operator += (T c)
100 { return AddCst(c); }
101 inline SimpleMatrix<T>& operator *= (T c)
102 { return MulCst(c); }
103 inline SimpleMatrix<T>& operator += (const SimpleMatrix<T> & b)
104 { return AddElt(b); }
105 inline SimpleMatrix<T>& operator *= (const SimpleMatrix<T> & b)
106 { return MulElt(b); }
107
108protected:
109 NDataBlock<T> data_;
110 JETExpMtx<T> dbv_;
111};
112
113
114template <class T>
115inline ostream& operator << (ostream& os, const SimpleMatrix<T> & m)
116{ m.Print(os); return(os); }
117
118// -------------------------------------------------------------
119template <class T, class E>
120void JETExpression<T,E>::EvaluateAll(AnyDataObj& dest) const
121 {
122 // cout << " JETExpression<T,E>::EvaluateAll(AnyDataObj& dest) " << endl;
123 SimpleMatrix<T>* dmx = dynamic_cast<SimpleMatrix<T> *>(&dest);
124 if (dmx == NULL) throw ParmError("SMExprMult<T>::EvaluateAll() - dest not a SimpleMatrix");
125 // cout << " --- Doing Reset() " << endl;
126 e_.Reset();
127 // cout << " --- Reset() OK " << endl;
128 dmx->ReSize(e_.RefSize());
129 // cout << " --- Resize OK " << endl;
130 for(sa_size_t k=0; k<dmx->Size(); k++) dmx->DataBlock()(k) = e_.EvaluateAndStep();
131 }
132
133
134#endif
Note: See TracBrowser for help on using the repository browser.