#ifndef SMTX_H_SEEN #define SMTX_H_SEEN #include "machdefs.h" #include #include "ndatablock.h" #include "sopnamsp.h" #include "ctimer.h" #include "timing.h" #include "jet.h" //======================================================== // Test d'expression template sur tableaux // Reza - Avril 2003 //======================================================== // --------------------------------------------------- //------- Expression/iterateur sur matrice ----------- // --------------------------------------------------- template class JETExpMtx { public: JETExpMtx() : db_(NULL), msz_(NULL), pd_(NULL) { } //cout << " DBG-AA" << hex << db_ << " - " << msz_ << dec << endl;} JETExpMtx(NDataBlock * db, MtxSize const * msz) : db_(db), msz_(msz), pd_(NULL) { } // cout << " DBG-BBB" << hex << db_ << " - " << msz_ << dec << endl; } JETExpMtx(JETExpMtx const & a) : db_(a.db_), msz_(a.msz_), pd_(a.pd_) { } // cout << " DBG-CCC" << hex << db_ << " - " << msz_ << dec << endl;} inline T EvaluateAndStep() const { return (*pd_++); } inline void Reset() const { pd_ = db_->Begin(); } //{ if (db_ == NULL) cout << " AAA-BUG db_" << endl; //pd_ = db_->Begin(); if (pd_ == NULL) cout << " BBB-BUG db_" << endl;} inline MtxSize const & RefSize() const { return *msz_; } // if (msz_ == NULL) cout << " BUG msz_ " << endl; return *msz_; } void JETExpMtxSet(NDataBlock * db, MtxSize const * msz) { db_ = db; msz_ = msz; pd_ = NULL; } protected: NDataBlock * db_; MtxSize const * msz_; mutable T * pd_; }; // --------------------------------------------------- // ------------- Classe de matrice ------------------- // --------------------------------------------------- template class SimpleMatrix : public AnyDataObj, public MtxSize, public JETExpression > { public: SimpleMatrix(); SimpleMatrix(sa_size_t nr, sa_size_t nc); SimpleMatrix(const SimpleMatrix & m); SimpleMatrix(const SimpleMatrix & m, bool share); virtual ~SimpleMatrix(); virtual void ReSize(const MtxSize & a); virtual SimpleMatrix& Set(const SimpleMatrix & a); inline SimpleMatrix& Set(JETEvaluator const & exp) { exp.EvaluateAll(*this); return(*this); } virtual SimpleMatrix& Init(T c); virtual SimpleMatrix& Init(T c, T step); inline SimpleMatrix& operator = (const SimpleMatrix & a) { return Set(a); } inline SimpleMatrix& operator = (JETEvaluator const & a) { return Set(a); } inline SimpleMatrix& operator = (T c) { return Init(c); } inline T operator()(int r, int c) const { return data_p_[r*ncol_+c]; } inline T& operator()(int r, int c) { return data_p_[r*ncol_+c]; } inline sa_size_t NRows() const {return nrow_; } inline sa_size_t NCols() const {return ncol_; } inline sa_size_t Size() const {return nrow_*ncol_; } virtual void Print(ostream& os) const; inline NDataBlock const & DataBlock() const { return data_; } inline NDataBlock& DataBlock() { return data_; } SimpleMatrix& AddCst(T c); SimpleMatrix& MulCst(T c); SimpleMatrix& AddElt(const SimpleMatrix & b); SimpleMatrix& MulElt(const SimpleMatrix & b); inline SimpleMatrix& operator += (T c) { return AddCst(c); } inline SimpleMatrix& operator *= (T c) { return MulCst(c); } inline SimpleMatrix& operator += (const SimpleMatrix & b) { return AddElt(b); } inline SimpleMatrix& operator *= (const SimpleMatrix & b) { return MulElt(b); } protected: NDataBlock data_; T* data_p_; JETExpMtx dbv_; }; template inline ostream& operator << (ostream& os, const SimpleMatrix & m) { m.Print(os); return(os); } // ------------------------------------------------------------- template void JETExpression::EvaluateAll(AnyDataObj& dest) const { // cout << " JETExpression::EvaluateAll(AnyDataObj& dest) " << endl; SimpleMatrix* dmx = dynamic_cast *>(&dest); if (dmx == NULL) throw ParmError("SMExprMult::EvaluateAll() - dest not a SimpleMatrix"); // cout << " --- Doing Reset() " << endl; e_.Reset(); // cout << " --- Reset() OK " << endl; dmx->ReSize(e_.RefSize()); // cout << " --- Resize OK " << endl; for(sa_size_t k=0; kSize(); k++) dmx->DataBlock()(k) = e_.EvaluateAndStep(); } #endif