Changeset 1103 in Sophya for trunk/SophyaLib/TArray
- Timestamp:
- Jul 27, 2000, 2:00:10 AM (25 years ago)
- Location:
- trunk/SophyaLib/TArray
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/basarr.cc
r1099 r1103 301 301 else { 302 302 smo = false; 303 if ( (size_[marowi_] != a.size_[marowi_]) || 304 (size_[macoli_] != a.size_[macoli_]) ) return(false); 303 if ( (size_[marowi_] != a.size_[a.marowi_]) || 304 (size_[macoli_] != a.size_[a.macoli_]) ) return(false); 305 if (ndim_ > 2) 306 for(uint_4 k=2; k<ndim_; k++) 307 if (size_[k] != a.size_[k]) return(false); 305 308 if ( (macoli_ == a.macoli_) && (marowi_ == a.marowi_) || 306 309 (veceli_ == a.veceli_) ) smo = true; … … 353 356 int BaseArray::MinStepKA() const 354 357 { 355 for( intka=0; ka<ndim_; ka++)356 if (step_[ka] == minstep_) return( ka);358 for(uint_4 ka=0; ka<ndim_; ka++) 359 if (step_[ka] == minstep_) return((int)ka); 357 360 return(0); 358 361 } … … 363 366 int ka = 0; 364 367 uint_4 mx = size_[0]; 365 for( int k=0; k<ndim_; k++)368 for(uint_4 k=1; k<ndim_; k++) 366 369 if (size_[k] > mx) { ka = k; mx = size_[k]; } 367 370 return(ka); … … 475 478 os << " MemoryMapping=" << GetMemoryMapping() << " VecType= " << GetVectorType() 476 479 << " RowsKA= " << RowsKA() << " ColsKA= " << ColsKA() 477 << " VectKA=" << VectKA() << endl;480 << " VectKA=" << VectKA() << " ArrayType=" << arrtype_ << endl; 478 481 } 479 482 if (!si && (prt_lev_ < 2)) return; -
trunk/SophyaLib/TArray/tarray.cc
r1099 r1103 200 200 { 201 201 string exmsg = "TArray<T>::CloneOrShare()"; 202 if (!UpdateSizes(a .ndim_, a.size_, a.step_, a.offset_, exmsg)) throw( ParmError(exmsg) );202 if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) ); 203 203 mNDBlock.CloneOrShare(a.mNDBlock); 204 if (mInfo) {delete mInfo; mInfo = NULL;} 205 if (a.mInfo) mInfo = new DVList(*(a.mInfo)); 204 206 } 205 207 … … 209 211 { 210 212 string exmsg = "TArray<T>::Share()"; 211 if (!UpdateSizes(a .ndim_, a.size_, a.step_, a.offset_, exmsg)) throw( ParmError(exmsg) );213 if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) ); 212 214 mNDBlock.Share(a.mNDBlock); 215 if (mInfo) {delete mInfo; mInfo = NULL;} 216 if (a.mInfo) mInfo = new DVList(*(a.mInfo)); 213 217 } 214 218 … … 363 367 */ 364 368 template <class T> 365 TArray<T>& TArray<T>::SetSeq(Sequence seq)369 TArray<T>& TArray<T>::SetSeq(Sequence const & seq) 366 370 { 367 371 if (NbDimensions() < 1) 368 372 throw RangeCheckError("TArray<T>::SetSeq(Sequence ) - Not Allocated Array ! "); 373 369 374 T * pe; 370 375 uint_8 j,k; 371 if (AvgStep() > 0) { // regularly spaced elements 372 uint_8 step = AvgStep(); 373 pe = Data(); 374 for(k=0; k<totsize_; k++ ) pe[k*step] = (T) seq(k); 375 } 376 else { // Non regular data spacing ... 377 // uint_4 ka = MaxSizeKA(); 378 uint_4 ka = 0; 379 uint_8 step = Step(ka); 380 uint_8 gpas = Size(ka); 381 uint_8 naxa = Size()/Size(ka); 382 for(j=0; j<naxa; j++) { 383 pe = mNDBlock.Begin()+Offset(ka,j); 384 for(k=0; k<gpas; k++) pe[k*step] = (T) seq(j*gpas+k); 385 } 376 int ka; 377 if (arrtype_ == 0) ka = 0; 378 else ka = macoli_; 379 uint_8 step = Step(ka); 380 uint_8 gpas = Size(ka); 381 uint_8 naxa = Size()/Size(ka); 382 for(j=0; j<naxa; j++) { 383 pe = mNDBlock.Begin()+Offset(ka,j); 384 #if !defined(__GNUG__) 385 for(k=0; k<gpas; k++) pe[k*step] = (T) seq(j*gpas+k); 386 #else 387 // g++ (up to 2.95.1) se melange les pinceaux s'il y a le cast (T) pour l'instanciation des complexes 388 for(k=0; k<gpas; k++) pe[k*step] = seq(j*gpas+k); 389 #endif 386 390 } 387 391 return(*this); -
trunk/SophyaLib/TArray/tarray.h
r1081 r1103 122 122 inline T toScalar(); 123 123 // Met les elements a une suite de valeurs 124 virtual TArray<T>& SetSeq(Sequence seq);124 virtual TArray<T>& SetSeq(Sequence const & seq); 125 125 //! Fill TArray with Sequence \b seq 126 inline TArray<T>& operator = (Sequence seq) { return SetSeq(seq); }126 inline TArray<T>& operator = (Sequence const & seq) { return SetSeq(seq); } 127 127 // A = x (tous les elements a x) 128 128 virtual TArray<T>& SetT(T x); -
trunk/SophyaLib/TArray/tmatrix.cc
r1099 r1103 1 // $Id: tmatrix.cc,v 1.1 4 2000-07-26 16:29:45ansari Exp $1 // $Id: tmatrix.cc,v 1.15 2000-07-27 00:00:09 ansari Exp $ 2 2 // C.Magneville 04/99 3 3 #include "machdefs.h" … … 54 54 { 55 55 arrtype_ = 1; // Type = Matrix 56 UpdateMemoryMapping(a, SameMemoryMapping); 56 57 } 57 58 … … 66 67 { 67 68 arrtype_ = 1; // Type = Matrix 69 UpdateMemoryMapping(a, SameMemoryMapping); 68 70 } 69 71 … … 111 113 { 112 114 arrtype_ = 1; // Type = Matrix 115 UpdateMemoryMapping(a, SameMemoryMapping); 113 116 SetBA(a); 114 117 } -
trunk/SophyaLib/TArray/tmatrix.h
r1099 r1103 82 82 83 83 // = : fill matrix with a Sequence \b seq 84 inline TMatrix<T>& operator = (Sequence seq) { SetSeq(seq); return(*this); }84 inline TMatrix<T>& operator = (Sequence const & seq) { SetSeq(seq); return(*this); } 85 85 86 86 // Operations diverses avec une constante … … 137 137 r*step_[marowi_] + c*step_[macoli_] ) ); 138 138 } 139 //////////////////////////////////////////////////////////////// 140 // Surcharge d'operateurs A (+,-,*,/) (T) x 141 142 /*! \ingroup TMatrix \fn operator+(const TMatrix<T>&,T) 143 \brief Operator TMatrix = TMatrix + constant */ 144 template <class T> inline TMatrix<T> operator + (const TMatrix<T>& a, T b) 145 {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true); 146 result.Add(b); return result;} 147 148 /*! \ingroup TMatrix \fn operator+(T,const TMatrix<T>&) 149 \brief Operator TMatrix = constant + TMatrix */ 150 template <class T> inline TMatrix<T> operator + (T b,const TMatrix<T>& a) 151 {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true); 152 result.Add(b); return result;} 153 154 /*! \ingroup TMatrix \fn operator-(const TMatrix<T>&,T) 155 \brief Operator TMatrix = TMatrix - constant */ 156 template <class T> inline TMatrix<T> operator - (const TMatrix<T>& a, T b) 157 {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true); 158 result.Sub(b); return result;} 159 160 /*! \ingroup TMatrix \fn operator-(T,const TMatrix<T>&) 161 \brief Operator TMatrix = constant - TMatrix */ 162 template <class T> inline TMatrix<T> operator - (T b,const TMatrix<T>& a) 163 {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true); 164 result.Sub(b,true); return result;} 165 166 /*! \ingroup TMatrix \fn operator*(const TMatrix<T>&,T) 167 \brief Operator TMatrix = TMatrix * constant */ 168 template <class T> inline TMatrix<T> operator * (const TMatrix<T>& a, T b) 169 {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true); 170 result.Mul(b); return result;} 171 172 /*! \ingroup TMatrix \fn operator*(T,const TMatrix<T>&) 173 \brief Operator TMatrix = constant * TMatrix */ 174 template <class T> inline TMatrix<T> operator * (T b,const TMatrix<T>& a) 175 {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true); 176 result.Mul(b); return result;} 177 178 /*! \ingroup TMatrix \fn operator/(const TMatrix<T>&,T) 179 \brief Operator TMatrix = TMatrix / constant */ 180 template <class T> inline TMatrix<T> operator / (const TMatrix<T>& a, T b) 181 {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true); 182 result.Div(b); return result;} 183 184 /*! \ingroup TMatrix \fn operator/(T,const TMatrix<T>&) 185 \brief Operator TMatrix = constant / TMatrix */ 186 template <class T> inline TMatrix<T> operator / (T b, const TMatrix<T>& a) 187 {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true); 188 result.Div(b, true); return result;} 189 139 190 140 191 // Surcharge d'operateurs C = A (+,-) B -
trunk/SophyaLib/TArray/tvector.cc
r1099 r1103 1 // $Id: tvector.cc,v 1. 9 2000-07-26 16:29:46ansari Exp $1 // $Id: tvector.cc,v 1.10 2000-07-27 00:00:10 ansari Exp $ 2 2 // C.Magneville 04/99 3 3 #include "machdefs.h" … … 101 101 template <class T> 102 102 TVector<T>::TVector(const BaseArray& a) 103 : TMatrix<T>() 104 { 105 arrtype_ = 2; // Type = Vector 106 SetBA(a); 103 : TMatrix<T>(a) 104 { 105 if ( (size_[0] != 1) && (size_[1] != 1) ) 106 throw SzMismatchError("TVector<T>::TVector(const BaseArray& a) NRows()!=1 && NCols()!=1 "); 107 arrtype_ = 2; // Type = Vector 107 108 } 108 109 -
trunk/SophyaLib/TArray/tvector.h
r1099 r1103 58 58 // Operateur d'affectation 59 59 //! Fill the vector with Sequence \b seq 60 inline TVector<T>& operator = (Sequence seq) { SetSeq(seq); return(*this); }60 inline TVector<T>& operator = (Sequence const & seq) { SetSeq(seq); return(*this); } 61 61 62 62 // Operations diverses avec une constante -
trunk/SophyaLib/TArray/utilarr.cc
r935 r1103 7 7 8 8 // Classe utilitaires 9 10 Sequence::~Sequence() 11 { 12 } 9 13 10 14 ////////////////////////////////////////////////////////// … … 27 31 sig_ = s; 28 32 } 33 RandomSequence::~RandomSequence() 34 { 35 } 29 36 30 37 //! Return random sequence values. … … 41 48 } 42 49 50 MuTyV & RandomSequence::Value(uint_8 k) const 51 { 52 if (typ_ == Flat) retv_ = drandpm1()*sig_ + mean_; 53 else retv_ = GauRnd(mean_, sig_); 54 return retv_; 55 } 56 43 57 44 58 ////////////////////////////////////////////////////////// 45 59 /*! 46 \class SOPHYA:: Sequence60 \class SOPHYA::RegularSequence 47 61 \ingroup TArray 48 62 Class to generate a sequence of values … … 55 69 \param f : pointer to the sequence function 56 70 57 See \ref SequenceOperat "operator()"71 See \ref RegularSequenceOperat "operator()" 58 72 */ 59 Sequence::Sequence(double start, double step, Arr_DoubleFunctionOfX f) 60 : rseq_(RandomSequence::Gaussian) 73 RegularSequence::RegularSequence(double start, double step, Arr_DoubleFunctionOfX f) 61 74 { 62 75 start_ = start; 63 76 step_ = step; 64 77 myf_ = f; 65 fgrseq_ = false;66 78 } 67 79 68 //! Constructor 69 /*! 70 \param rseq : RandomSequence 71 72 See \ref SequenceOperat "operator()" 73 */ 74 Sequence::Sequence(RandomSequence rseq) 80 RegularSequence::~RegularSequence() 75 81 { 76 start_ = 0.;77 step_ = 1.;78 myf_ = NULL;79 rseq_ = rseq;80 fgrseq_ = true;81 82 } 82 83 … … 84 85 /*! 85 86 \param k : index of the value 86 \anchor SequenceOperat87 \anchor RegularSequenceOperat 87 88 88 89 If the constructor was done with RandomSequence, return a RandomSequence … … 94 95 \return the \b k th value 95 96 */ 96 double Sequence::operator () (uint_4 k) 97 98 MuTyV & RegularSequence::Value (uint_8 k) const 97 99 { 98 if (fgrseq_) return(rseq_.Rand()); 99 else { 100 double x = start_+(double)k*step_; 101 if (myf_) return(myf_(x)); 102 else return x; 103 } 100 double x = start_+(double)k*step_; 101 if (myf_) x = myf_(x); 102 retv_ = x; 103 return(retv_); 104 } 105 106 EnumeratedSequence::~EnumeratedSequence() 107 { 108 } 109 110 MuTyV & EnumeratedSequence::Value (uint_8 k) const 111 { 112 if (k >= vecv_.size()) retv_ = 0; 113 else retv_ = vecv_[k]; 114 return(retv_); 115 } 116 117 EnumeratedSequence & EnumeratedSequence::operator , (MuTyV const & v) 118 { 119 vecv_.push_back(v); 120 return(*this); 104 121 } 105 122 -
trunk/SophyaLib/TArray/utilarr.h
r956 r1103 7 7 8 8 #include "machdefs.h" 9 #include "mutyv.h" 10 9 11 #include <stdlib.h> 12 #include <vector> 10 13 11 14 namespace SOPHYA { … … 26 29 ////////////////////////////////////////////////////////// 27 30 //! Class to generate a random sequence of values 28 class RandomSequence { 31 class Sequence { 32 public: 33 virtual ~Sequence(); 34 virtual MuTyV & Value(uint_8 k) const = 0; 35 inline MuTyV & operator () (uint_8 k) const { return(Value(k)) ; } 36 }; 37 38 class RandomSequence : public Sequence { 29 39 public: 30 40 //! to define the generator type … … 34 44 }; 35 45 36 RandomSequence(int typ = RandomSequence::Gaussian, double m=0., double s=1.); 37 double Rand(); 46 explicit RandomSequence(int typ = RandomSequence::Gaussian, double m=0., double s=1.); 47 virtual ~RandomSequence(); 48 virtual MuTyV & Value(uint_8 k) const ; 49 double Rand(); 50 38 51 protected: 39 52 int typ_; //!< random generation type 40 53 double mean_, sig_; //!< generation parameters mean and sigma (if needed) 54 mutable MuTyV retv_; 41 55 }; 42 56 … … 44 58 ////////////////////////////////////////////////////////// 45 59 //! Class to generate a sequence of values 46 class Sequence {60 class RegularSequence : public Sequence { 47 61 public: 48 explicit Sequence (double start=0., double step=1., Arr_DoubleFunctionOfX f=NULL);49 explicit Sequence (RandomSequence rseq);62 explicit RegularSequence (double start=0., double step=1., Arr_DoubleFunctionOfX f=NULL); 63 virtual ~RegularSequence(); 50 64 51 65 //! return start value of the sequence … … 53 67 //! return step value of the sequence 54 68 inline double & Step() { return step_; } 55 double operator () (uint_4 k); 69 70 virtual MuTyV & Value(uint_8 k) const ; 71 56 72 protected: 57 73 double start_; //!< start value of the sequence 58 74 double step_; //!< step value of the sequence 59 75 Arr_DoubleFunctionOfX myf_; //!< pointer to the sequence function 60 bool fgrseq_; //!< true if RandomSequence is used 61 RandomSequence rseq_; //!< RandomSequence 76 mutable MuTyV retv_; 62 77 }; 78 79 class EnumeratedSequence : public Sequence { 80 public: 81 virtual ~EnumeratedSequence(); 82 virtual MuTyV & Value(uint_8 k) const ; 83 EnumeratedSequence & operator , (MuTyV const & v); 84 private: 85 vector<MuTyV> vecv_; 86 mutable MuTyV retv_; 87 }; 88 89 inline EnumeratedSequence operator , (MuTyV const & a, MuTyV const & b) 90 { EnumeratedSequence seq; return ((seq,a),b) ; } 63 91 64 92 //////////////////////////////////////////////////////////
Note:
See TracChangeset
for help on using the changeset viewer.