Changeset 1081 in Sophya
- Timestamp:
- Jul 24, 2000, 2:51:27 PM (25 years ago)
- Location:
- trunk/SophyaLib/TArray
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/basarr.h
r1005 r1081 10 10 #include <iostream.h> 11 11 #include "anydataobj.h" 12 #include "mutyv.h" 12 13 #include "dvlist.h" 13 14 … … 134 135 135 136 // an abstract element acces methode 136 virtual doubleValueAtPosition(uint_8 ip) const = 0;137 virtual MuTyV & ValueAtPosition(uint_8 ip) const = 0; 137 138 138 139 // Impression, I/O, ... -
trunk/SophyaLib/TArray/tarray.cc
r1072 r1081 131 131 } 132 132 133 //! Constructor with size and contents copied (after conversion) from a different type TArray 134 template <class T> 135 TArray<T>::TArray(const BaseArray& a) 136 : BaseArray() , mNDBlock() 137 { 138 string exmsg = "TArray<T>::TArray(const BaseArray&)"; 139 if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) ); 140 mNDBlock.ReSize(totsize_); 141 // if (a.mInfo) mInfo = new DVList(*(a.mInfo)); - pb protected ! 142 ConvertAndCopyElt(a); 143 } 144 133 145 //! Destructor 134 146 template <class T> … … 155 167 } 156 168 169 //! Set array elements equal to the \b a array elements, after conversion 170 template <class T> 171 TArray<T>& TArray<T>::SetBA(const BaseArray& a) 172 { 173 if (this == &a) return(*this); 174 if (a.NbDimensions() < 1) 175 throw RangeCheckError("TArray<T>::SetBA(a ) - Array a not allocated ! "); 176 if (NbDimensions() < 1) { 177 string exmsg = "TArray<T>::SetBA(const BaseArray& a)"; 178 if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) ); 179 mNDBlock.ReSize(totsize_); 180 } 181 ConvertAndCopyElt(a); 182 return(*this); 183 } 184 157 185 //! Clone array \b a 158 186 template <class T> … … 233 261 } 234 262 235 inline double _SqrtRz_(double x) { return sqrt(x); } // Pb avec SGI-CC - $CHECK$ - Reza 04/2000236 237 263 //! Give value (in \b double) for element at position \b ip.. 238 264 template <class T> 239 doubleTArray<T>::ValueAtPosition(uint_8 ip) const265 MuTyV & TArray<T>::ValueAtPosition(uint_8 ip) const 240 266 { 241 267 #ifdef SO_BOUNDCHECKING 242 268 if (ip >= totsize_) throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") ); 243 269 #endif 244 return( (double)(*(mNDBlock.Begin()+Offset(ip))) ); 245 } 246 247 //! Give value (in \b double) for element at position \b ip.. 248 /*! 249 For complex values, we return the module of the complex number 250 */ 251 double TArray< complex<r_4> >::ValueAtPosition(uint_8 ip) const 252 { 253 #ifdef SO_BOUNDCHECKING 254 if (ip >= totsize_) throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") ); 255 #endif 256 complex<r_4> c = *(mNDBlock.Begin()+Offset(ip)); 257 double cr = (double)(c.real()); 258 double ci = (double)(c.imag()); 259 return( _SqrtRz_(cr*cr+ci*ci) ); 260 } 261 262 //! Give value (in \b double) for element at position \b ip.. 263 /*! 264 For complex values, we return the module of the complex number 265 */ 266 double TArray< complex<r_8> >::ValueAtPosition(uint_8 ip) const 267 { 268 #ifdef SO_BOUNDCHECKING 269 if (ip >= totsize_) throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") ); 270 #endif 271 complex<r_8> c = *(mNDBlock.Begin()+Offset(ip)); 272 double cr = (double)(c.real()); 273 double ci = (double)(c.imag()); 274 return( _SqrtRz_(cr*cr+ci*ci) ); 270 my_mtv = *(mNDBlock.Begin()+Offset(ip)); 271 return( my_mtv ); 275 272 } 276 273 … … 754 751 for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka]; 755 752 } 753 } 754 return(*this); 755 } 756 757 //! Converts and Copy elements of \b a 758 template <class T> 759 TArray<T>& TArray<T>::ConvertAndCopyElt(const BaseArray& a) 760 { 761 if (NbDimensions() < 1) 762 throw RangeCheckError("TArray<T>::ConvertAndCopyElt(const TArray<T>& ) - Not Allocated Array ! "); 763 if (!CompareSizes(a)) 764 throw(SzMismatchError("TArray<T>::ConvertAndCopyElt(const TArray<T>&) SizeMismatch")) ; 765 766 T * pe; 767 uint_8 j,k,ka; 768 uint_8 offa; 769 // Non regular data spacing ... 770 uint_4 ax = MaxSizeKA(); 771 uint_8 step = Step(ax); 772 uint_8 stepa = a.Step(ax); 773 uint_8 gpas = Size(ax)*step; 774 uint_8 naxa = Size()/Size(ax); 775 for(j=0; j<naxa; j++) { 776 pe = mNDBlock.Begin()+Offset(ax,j); 777 offa = a.Offset(ax,j); 778 for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = a.ValueAtPosition(offa+ka); 756 779 } 757 780 return(*this); -
trunk/SophyaLib/TArray/tarray.h
r1072 r1081 35 35 TArray(const TArray<T>& a); 36 36 TArray(const TArray<T>& a, bool share); 37 TArray(const BaseArray& a); 37 38 38 39 virtual ~TArray(); … … 44 45 inline TArray<T>& operator = (const TArray<T>& a) { return Set(a); } 45 46 virtual TArray<T>& Set(const TArray<T>& a); 47 48 //! = operator between TArray 's with different types - Elements are converted. 49 inline TArray<T>& operator = (const BaseArray& a) { return SetBA(a); } 50 virtual TArray<T>& SetBA(const BaseArray& a); 46 51 47 52 // Gestion taille/Remplissage … … 83 88 // ---- Access to data 84 89 // Definition of virtual element acces method inherited from BaseArray class 85 virtual doubleValueAtPosition(uint_8 ip) const;90 virtual MuTyV & ValueAtPosition(uint_8 ip) const; 86 91 87 92 // Data Access: operator overloaded inline acces methods … … 150 155 // Recopie des valeurs, element par element 151 156 virtual TArray<T>& CopyElt(const TArray<T>& a); 157 // Recopie des valeurs avec conversion prealable, element par element 158 virtual TArray<T>& ConvertAndCopyElt(const BaseArray& a); 152 159 153 160 // Somme et produit des elements … … 165 172 166 173 NDataBlock<T> mNDBlock; //!< Block for datas 174 mutable MuTyV my_mtv; //!< for use by ValueAtPosition() 167 175 }; 168 176 -
trunk/SophyaLib/TArray/tmatrix.cc
r996 r1081 1 // $Id: tmatrix.cc,v 1.1 2 2000-05-02 15:49:29ansari Exp $1 // $Id: tmatrix.cc,v 1.13 2000-07-24 12:51:27 ansari Exp $ 2 2 // C.Magneville 04/99 3 3 #include "machdefs.h" … … 99 99 UpdateMemoryMapping(a, mm); 100 100 } 101 102 template <class T> 103 TMatrix<T>::TMatrix(const BaseArray& a) 104 : TArray<T>() 105 { 106 SetBA(a); 107 } 108 109 101 110 102 111 //! Destructor … … 125 134 return(*this); 126 135 } 136 137 template <class T> 138 TArray<T>& TMatrix<T>::SetBA(const BaseArray& a) 139 { 140 if (a.NbDimensions() > 2) 141 throw SzMismatchError("TMatrix<T>::SetBA(const BaseArray& a) a.NbDimensions() > 2"); 142 TArray<T>::SetBA(a); 143 if (NbDimensions() == 1) { 144 size_[1] = 1; 145 step_[1] = size_[0]*step_[0]; 146 ndim_ = 2; 147 } 148 UpdateMemoryMapping(*this, SameMemoryMapping); 149 return(*this); 150 } 151 152 127 153 128 154 //! Resize the matrix -
trunk/SophyaLib/TArray/tmatrix.h
r1013 r1081 20 20 TMatrix(const TArray<T>& a); 21 21 TMatrix(const TArray<T>& a, bool share, short mm=BaseArray::AutoMemoryMapping); 22 TMatrix(const BaseArray& a); 22 23 23 24 virtual ~TMatrix(); … … 30 31 inline TMatrix<T>& operator = (const TMatrix<T>& a) 31 32 { Set(a); return(*this); } 33 34 virtual TArray<T>& SetBA(const BaseArray& a); 35 inline TMatrix<T>& operator = (const BaseArray& a) 36 { SetBA(a); return(*this); } 32 37 33 38 // Size - Changing the Size
Note:
See TracChangeset
for help on using the changeset viewer.