[772] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | // template array class for numerical types
|
---|
| 3 | // R. Ansari, C.Magneville 03/2000
|
---|
| 4 |
|
---|
| 5 | #ifndef TArray_SEEN
|
---|
| 6 | #define TArray_SEEN
|
---|
| 7 |
|
---|
| 8 | #include "machdefs.h"
|
---|
| 9 | #include <math.h>
|
---|
[2322] | 10 | #include <iostream>
|
---|
[787] | 11 | #include "basarr.h"
|
---|
[772] | 12 | #include "ndatablock.h"
|
---|
| 13 | #include <complex>
|
---|
[785] | 14 | #include "utilarr.h"
|
---|
[772] | 15 |
|
---|
| 16 |
|
---|
| 17 | namespace SOPHYA {
|
---|
| 18 |
|
---|
| 19 | // Forward declaration
|
---|
| 20 | template <class T> class FIO_TArray;
|
---|
| 21 |
|
---|
[787] | 22 | // --------------------------- classe template Array -----------------------
|
---|
| 23 | // ( See BaseArray class for data organisation in memory and related methods )
|
---|
| 24 |
|
---|
[894] | 25 | //! Class for template arrays
|
---|
[772] | 26 | template <class T>
|
---|
[787] | 27 | class TArray : public BaseArray {
|
---|
[772] | 28 | public:
|
---|
| 29 | // Creation / destruction
|
---|
| 30 | TArray();
|
---|
[2564] | 31 | TArray(int_4 ndim, const sa_size_t * siz, sa_size_t step =1, bool fzero=true);
|
---|
| 32 | TArray(sa_size_t nx, sa_size_t ny=0, sa_size_t nz=0, sa_size_t nt=0, sa_size_t nu=0, bool fzero=true);
|
---|
[1156] | 33 | TArray(int_4 ndim, const sa_size_t * siz, NDataBlock<T> & db, bool share=false, sa_size_t step=1, sa_size_t offset=0);
|
---|
| 34 | TArray(int_4 ndim, const sa_size_t * siz, T* values, sa_size_t step=1, sa_size_t offset=0, Bridge* br=NULL);
|
---|
[772] | 35 | TArray(const TArray<T>& a);
|
---|
| 36 | TArray(const TArray<T>& a, bool share);
|
---|
[1081] | 37 | TArray(const BaseArray& a);
|
---|
[772] | 38 |
|
---|
| 39 | virtual ~TArray();
|
---|
| 40 |
|
---|
[967] | 41 | // A = B
|
---|
[894] | 42 | //! = operator between TArray
|
---|
[976] | 43 | /*! \warning Datas are copied (cloned) from \b a.
|
---|
| 44 | \sa Set \sa NDataBlock::operator=(const NDataBlock<T>&) */
|
---|
[804] | 45 | inline TArray<T>& operator = (const TArray<T>& a) { return Set(a); }
|
---|
| 46 | virtual TArray<T>& Set(const TArray<T>& a);
|
---|
[772] | 47 |
|
---|
[1081] | 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);
|
---|
| 51 |
|
---|
[772] | 52 | // Gestion taille/Remplissage
|
---|
| 53 | virtual void Clone(const TArray<T>& a);
|
---|
[970] | 54 | // partage les donnees si "a" temporaire, clone sinon.
|
---|
| 55 | void CloneOrShare(const TArray<T>& a);
|
---|
| 56 | // Share: partage les donnees de "a"
|
---|
[1393] | 57 | void Share(const TArray<T>& a);
|
---|
[970] | 58 |
|
---|
[2564] | 59 | void ReSize(int_4 ndim, sa_size_t * siz, sa_size_t step=1, bool fzero=true);
|
---|
[2569] | 60 | void ReSize(const BaseArray& a, bool pack=false, bool fzero=true);
|
---|
[1393] | 61 | //! a synonym (alias) for method ReSize(int_4, ...)
|
---|
[2564] | 62 | inline void SetSize(int_4 ndim, sa_size_t * siz, sa_size_t step=1, bool fzero=true)
|
---|
| 63 | { ReSize(ndim, siz, step, fzero); }
|
---|
[1517] | 64 | //! a synonym (alias) for method ReSize(const BaseArray&)
|
---|
[2569] | 65 | inline void SetSize(const BaseArray& a, bool pack=false, bool fzero=true)
|
---|
[2564] | 66 | { ReSize(a, pack, fzero); }
|
---|
[1156] | 67 | void Realloc(int_4 ndim, sa_size_t * siz, sa_size_t step=1, bool force=false);
|
---|
[787] | 68 |
|
---|
[785] | 69 | // Compacts size=1 array dimensions
|
---|
[787] | 70 | virtual TArray<T>& CompactAllDimensions();
|
---|
| 71 | virtual TArray<T>& CompactTrailingDimensions();
|
---|
[785] | 72 |
|
---|
[804] | 73 | // Packing array elements in memory
|
---|
| 74 | virtual TArray<T> PackElements(bool force=false) const ;
|
---|
[772] | 75 |
|
---|
[804] | 76 | // SubArrays - $CHECK$ Reza 03/2000 je ne sais pas s'il faut declarer ca const ??
|
---|
[894] | 77 | TArray<T> SubArray(Range rx, Range ry, Range rz, Range rt, Range ru) const ;
|
---|
[1891] | 78 |
|
---|
[894] | 79 | //! () operator for Sub arrays extraction
|
---|
| 80 | /*! \sa SubArray */
|
---|
[963] | 81 | inline TArray<T> operator () (Range rx, Range ry, Range rz) const
|
---|
| 82 | { return SubArray(rx, ry, rz, Range(0), Range(0)); }
|
---|
| 83 | inline TArray<T> operator () (Range rx, Range ry, Range rz, Range rt) const
|
---|
| 84 | { return SubArray(rx, ry, rz, rt, Range(0)); }
|
---|
| 85 | inline TArray<T> operator () (Range rx, Range ry, Range rz, Range rt, Range ru) const
|
---|
| 86 | { return SubArray(rx, ry, rz, rt, ru); }
|
---|
[772] | 87 |
|
---|
[787] | 88 | // ---- Access to data
|
---|
| 89 | // Definition of virtual element acces method inherited from BaseArray class
|
---|
[1156] | 90 | virtual MuTyV & ValueAtPosition(sa_size_t ip) const;
|
---|
[785] | 91 |
|
---|
[787] | 92 | // Data Access: operator overloaded inline acces methods
|
---|
[1156] | 93 | inline T const& operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz) const ;
|
---|
| 94 | inline T& operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz);
|
---|
| 95 | inline T const& operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu=0) const ;
|
---|
| 96 | inline T& operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu=0);
|
---|
| 97 | inline T const& operator[](sa_size_t ip) const ;
|
---|
| 98 | inline T& operator[](sa_size_t ip);
|
---|
[772] | 99 |
|
---|
[1156] | 100 | inline T const& Elem(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it=0, sa_size_t iu=0) const ;
|
---|
| 101 | inline T& Elem(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it=0, sa_size_t iu=0);
|
---|
| 102 | inline T const& ElemCheckBound(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it=0, sa_size_t iu=0) const ;
|
---|
| 103 | inline T& ElemCheckBound(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it=0, sa_size_t iu=0);
|
---|
[772] | 104 |
|
---|
[894] | 105 | //! Return pointer to first element adress
|
---|
[772] | 106 | inline T* Data() {return mNDBlock.Begin()+offset_;}
|
---|
[894] | 107 | //! Return pointer to first element adress
|
---|
[772] | 108 | inline const T* Data() const {return mNDBlock.Begin()+offset_;}
|
---|
[894] | 109 | //! Return reference to datablock NDataBlock
|
---|
[772] | 110 | inline NDataBlock<T>& DataBlock() {return mNDBlock;}
|
---|
[894] | 111 | //! Return reference to datablock NDataBlock
|
---|
[772] | 112 | inline const NDataBlock<T>& DataBlock() const {return mNDBlock;}
|
---|
| 113 |
|
---|
[787] | 114 | // Temporaire?
|
---|
[894] | 115 | //! Are the array temporay ?
|
---|
[787] | 116 | inline bool IsTemp(void) const {return mNDBlock.IsTemp();}
|
---|
[894] | 117 | //! Set the array as temporay
|
---|
[787] | 118 | inline void SetTemp(bool temp=false) const {mNDBlock.SetTemp(temp);}
|
---|
| 119 |
|
---|
[772] | 120 | // Operations diverses = , +=, ...
|
---|
| 121 | // Conversion en type T, if Size() == 1
|
---|
[787] | 122 | inline T toScalar();
|
---|
[772] | 123 | // Met les elements a une suite de valeurs
|
---|
[1103] | 124 | virtual TArray<T>& SetSeq(Sequence const & seq);
|
---|
[894] | 125 | //! Fill TArray with Sequence \b seq
|
---|
[1103] | 126 | inline TArray<T>& operator = (Sequence const & seq) { return SetSeq(seq); }
|
---|
[2575] | 127 |
|
---|
[772] | 128 | // A = x (tous les elements a x)
|
---|
[2575] | 129 | virtual TArray<T>& SetCst(T x);
|
---|
| 130 | //! Fill an array with a constant value \b x ( alias for \b SetCst() method )
|
---|
| 131 | inline TArray<T>& SetT(T x) { return SetCst(x); }
|
---|
[894] | 132 | //! Fill TArray with all elements equal to \b x
|
---|
[813] | 133 | inline TArray<T>& operator = (T x) { return SetT(x); }
|
---|
[2564] | 134 |
|
---|
| 135 | // addition et soustraction de constante
|
---|
| 136 | virtual TArray<T>& AddCst(T x, TArray<T>& res) const ;
|
---|
| 137 | virtual TArray<T>& SubCst(T x, TArray<T>& res, bool fginv=false) const ;
|
---|
| 138 | // Multiplication et division par une constante
|
---|
| 139 | virtual TArray<T>& MulCst(T x, TArray<T>& res) const ;
|
---|
| 140 | virtual TArray<T>& DivCst(T x, TArray<T>& res, bool fginv=false) const ;
|
---|
| 141 |
|
---|
[772] | 142 | // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
|
---|
[2575] | 143 | // Methodes Add/Sub/Mul/Div() sont la pour compatibilite avant V=2 (1.818)
|
---|
| 144 | // Faut-il les garder ? Reza, Juillet 2004
|
---|
[2564] | 145 | inline TArray<T>& Add(T x) { return AddCst(x, *this); }
|
---|
| 146 | inline TArray<T>& Sub(T x, bool fginv=false) { return SubCst(x, *this, fginv); }
|
---|
| 147 | inline TArray<T>& Mul(T x) { return MulCst(x, *this); }
|
---|
| 148 | inline TArray<T>& Div(T x, bool fginv=false) { return DivCst(x, *this, fginv); }
|
---|
| 149 |
|
---|
[894] | 150 | //! Add \b x to all elements
|
---|
[2564] | 151 | inline TArray<T>& operator += (T x) { return AddCst(x, *this); }
|
---|
[894] | 152 | //! Substract \b x to all elements
|
---|
[2564] | 153 | inline TArray<T>& operator -= (T x) { return SubCst(x, *this); }
|
---|
[894] | 154 | //! Multiply all elements by \b x
|
---|
[2564] | 155 | inline TArray<T>& operator *= (T x) { return MulCst(x, *this); }
|
---|
[894] | 156 | //! Divide all elements by \b x
|
---|
[2564] | 157 | inline TArray<T>& operator /= (T x) { return DivCst(x, *this); }
|
---|
[804] | 158 |
|
---|
[1156] | 159 | // applique le signe moins a tous les elements
|
---|
[2564] | 160 | virtual TArray<T>& NegateElt(TArray<T>& res) const ;
|
---|
| 161 | //! Replace array elements values by their opposite ( (*this)(i) -> -(*this)(i) )
|
---|
| 162 | inline TArray<T>& NegateElt() { return NegateElt(*this); }
|
---|
| 163 |
|
---|
[772] | 164 | // A += -= (ajoute, soustrait element par element les deux tableaux )
|
---|
[2575] | 165 | virtual TArray<T>& AddElt(const TArray<T>& a, TArray<T>& res) const ;
|
---|
| 166 | virtual TArray<T>& SubElt(const TArray<T>& a, TArray<T>& res, bool fginv=false) const ;
|
---|
[787] | 167 | // Multiplication, division element par element les deux tableaux
|
---|
[2575] | 168 | virtual TArray<T>& MulElt(const TArray<T>& a, TArray<T>& res) const ;
|
---|
| 169 | virtual TArray<T>& DivElt(const TArray<T>& a, TArray<T>& res, bool fginv=false, bool divzero=false) const ;
|
---|
| 170 |
|
---|
| 171 | //! Operator TArray += TArray (element by element addition in place)
|
---|
| 172 | inline TArray<T>& operator += (const TArray<T>& a) { return AddElt(a, *this); }
|
---|
| 173 | //! Operator TArray -= TArray (element by element subtraction in place)
|
---|
| 174 | inline TArray<T>& operator -= (const TArray<T>& a) { return SubElt(a, *this); }
|
---|
| 175 |
|
---|
[2588] | 176 | // Doit-on definir les operateur *= /= TArray ? Reza, Juillet 2004
|
---|
| 177 | //! Element by element multiplication in place TArray *= TArray (element by element)
|
---|
| 178 | inline TArray<T>& Mul(const TArray<T>& a) { return MulElt(a, *this); }
|
---|
| 179 | //! Element by element division in place TArray *= TArray (element by element)
|
---|
[2589] | 180 | inline TArray<T>& Div(const TArray<T>& a, bool divzero=false)
|
---|
| 181 | { return DivElt(a, *this, false, divzero); }
|
---|
[2588] | 182 |
|
---|
[804] | 183 | // Recopie des valeurs, element par element
|
---|
| 184 | virtual TArray<T>& CopyElt(const TArray<T>& a);
|
---|
[1081] | 185 | // Recopie des valeurs avec conversion prealable, element par element
|
---|
| 186 | virtual TArray<T>& ConvertAndCopyElt(const BaseArray& a);
|
---|
[772] | 187 |
|
---|
[2575] | 188 | // Calcul du produit scalaire ( Somme_i (*this)(i)*a(i) )
|
---|
| 189 | virtual T ScalarProduct(const TArray<T>& a) const ;
|
---|
| 190 | // Norme(^2)
|
---|
| 191 | //! Returns the squarred of the array norm, defined as Sum_k (*this)(k)*(*this)(k)
|
---|
| 192 | inline T Norm2() const { return ScalarProduct(*this); }
|
---|
| 193 |
|
---|
[804] | 194 | // Somme et produit des elements
|
---|
| 195 | virtual T Sum() const ;
|
---|
| 196 | virtual T Product() const ;
|
---|
[1113] | 197 | // Somme du carre des elements
|
---|
| 198 | virtual T SumX2() const;
|
---|
| 199 | // Valeur min et max des elements
|
---|
| 200 | virtual void MinMax(T& min, T& max) const ;
|
---|
[804] | 201 |
|
---|
[772] | 202 | // Impression, I/O, ...
|
---|
[813] | 203 | virtual string InfoString() const;
|
---|
[1550] | 204 | virtual void Print(ostream& os, sa_size_t maxprt=-1,
|
---|
| 205 | bool si=false, bool ascd=false) const ;
|
---|
[772] | 206 |
|
---|
[1517] | 207 | // Lecture,Ecriture sur fichier ASCII
|
---|
[2286] | 208 | virtual sa_size_t ReadASCII(istream& is, sa_size_t & nr, sa_size_t & nc,
|
---|
| 209 | char clm='#', const char* sep=" \t");
|
---|
[1517] | 210 | virtual void WriteASCII(ostream& os) const;
|
---|
| 211 |
|
---|
[772] | 212 | // Pour la gestion de persistance
|
---|
| 213 | friend class FIO_TArray<T>;
|
---|
| 214 |
|
---|
| 215 | protected:
|
---|
| 216 |
|
---|
[894] | 217 | NDataBlock<T> mNDBlock; //!< Block for datas
|
---|
[1081] | 218 | mutable MuTyV my_mtv; //!< for use by ValueAtPosition()
|
---|
[772] | 219 | };
|
---|
| 220 |
|
---|
| 221 | ////////////////////////////////////////////////////////////////
|
---|
| 222 | // Surcharge d'operateur <<
|
---|
[894] | 223 | //! Print TArray \b a on stream \b os
|
---|
[772] | 224 | template <class T>
|
---|
| 225 | inline ostream& operator << (ostream& os, const TArray<T>& a)
|
---|
| 226 | { a.Print(os); return(os); }
|
---|
| 227 |
|
---|
[1517] | 228 | // Surcharge d'operateur >>
|
---|
| 229 | //! Decodes the ASCII input stream \b is , filling TArray \b a elements
|
---|
| 230 | template <class T>
|
---|
| 231 | inline istream& operator >> (istream& is, TArray<T>& a)
|
---|
[1576] | 232 | { sa_size_t nr, nc;
|
---|
| 233 | a.ReadASCII(is, nr, nc); return(is); }
|
---|
[1517] | 234 |
|
---|
| 235 |
|
---|
[772] | 236 | ////////////////////////////////////////////////////////////////
|
---|
| 237 | // Surcharge d'operateurs A (+,-,*,/) (T) x
|
---|
| 238 |
|
---|
[958] | 239 | /*! \ingroup TArray \fn operator+(const TArray<T>&,T)
|
---|
| 240 | \brief Operator TArray = TArray + constant */
|
---|
[772] | 241 | template <class T> inline TArray<T> operator + (const TArray<T>& a, T b)
|
---|
[2564] | 242 | {TArray<T> result; result.SetTemp(true);
|
---|
[2569] | 243 | a.AddCst(b, result); return result;}
|
---|
[772] | 244 |
|
---|
[958] | 245 | /*! \ingroup TArray \fn operator+(T,const TArray<T>&)
|
---|
| 246 | \brief Operator TArray = constant + TArray */
|
---|
[772] | 247 | template <class T> inline TArray<T> operator + (T b,const TArray<T>& a)
|
---|
[2564] | 248 | {TArray<T> result; result.SetTemp(true);
|
---|
[2569] | 249 | a.AddCst(b, result); return result;}
|
---|
[772] | 250 |
|
---|
[958] | 251 | /*! \ingroup TArray \fn operator-(const TArray<T>&,T)
|
---|
| 252 | \brief Operator TArray = TArray - constant */
|
---|
[772] | 253 | template <class T> inline TArray<T> operator - (const TArray<T>& a, T b)
|
---|
[2564] | 254 | {TArray<T> result; result.SetTemp(true);
|
---|
[2569] | 255 | a.SubCst(b,result); return result;}
|
---|
[772] | 256 |
|
---|
[958] | 257 | /*! \ingroup TArray \fn operator-(T,const TArray<T>&)
|
---|
| 258 | \brief Operator TArray = constant - TArray */
|
---|
[772] | 259 | template <class T> inline TArray<T> operator - (T b,const TArray<T>& a)
|
---|
[2564] | 260 | {TArray<T> result; result.SetTemp(true);
|
---|
[2569] | 261 | a.SubCst(b,result,true); return result;}
|
---|
[772] | 262 |
|
---|
[958] | 263 | /*! \ingroup TArray \fn operator*(const TArray<T>&,T)
|
---|
| 264 | \brief Operator TArray = TArray * constant */
|
---|
[772] | 265 | template <class T> inline TArray<T> operator * (const TArray<T>& a, T b)
|
---|
[2564] | 266 | {TArray<T> result; result.SetTemp(true);
|
---|
| 267 | a.MulCst(b, result); return result;}
|
---|
[772] | 268 |
|
---|
[958] | 269 | /*! \ingroup TArray \fn operator*(T,const TArray<T>&)
|
---|
| 270 | \brief Operator TArray = constant * TArray */
|
---|
[772] | 271 | template <class T> inline TArray<T> operator * (T b,const TArray<T>& a)
|
---|
[2564] | 272 | {TArray<T> result; result.SetTemp(true);
|
---|
| 273 | a.MulCst(b,result); return result;}
|
---|
[772] | 274 |
|
---|
[958] | 275 | /*! \ingroup TArray \fn operator/(const TArray<T>&,T)
|
---|
| 276 | \brief Operator TArray = TArray / constant */
|
---|
[772] | 277 | template <class T> inline TArray<T> operator / (const TArray<T>& a, T b)
|
---|
[2564] | 278 | {TArray<T> result; result.SetTemp(true);
|
---|
[2569] | 279 | a.DivCst(b,result); return result;}
|
---|
[772] | 280 |
|
---|
[970] | 281 | /*! \ingroup TArray \fn operator/(T,const TArray<T>&)
|
---|
| 282 | \brief Operator TArray = constant / TArray */
|
---|
| 283 | template <class T> inline TArray<T> operator / (T b, const TArray<T>& a)
|
---|
[2564] | 284 | {TArray<T> result; result.SetTemp(true);
|
---|
[2569] | 285 | a.DivCst(b, result, true); return result;}
|
---|
[970] | 286 |
|
---|
[772] | 287 | ////////////////////////////////////////////////////////////////
|
---|
[1156] | 288 | // Surcharge d'operateurs B = -A
|
---|
| 289 |
|
---|
| 290 | /*! \ingroup TArray \fn operator - (const TArray<T>&)
|
---|
| 291 | \brief Operator - Returns an array with elements equal to the opposite of
|
---|
| 292 | the original array elements. */
|
---|
| 293 | template <class T> inline TArray<T> operator - (const TArray<T>& a)
|
---|
[2569] | 294 | {TArray<T> result; result.SetTemp(true);
|
---|
| 295 | a.NegateElt(result); return result;}
|
---|
[1156] | 296 |
|
---|
| 297 | ////////////////////////////////////////////////////////////////
|
---|
[772] | 298 | // Surcharge d'operateurs C = A (+,-) B
|
---|
| 299 |
|
---|
[958] | 300 | /*! \ingroup TArray \fn operator+(const TArray<T>&,const TArray<T>&)
|
---|
[2588] | 301 | \brief Operator TArray = TArray + TArray (element by element addition) */
|
---|
[772] | 302 | template <class T>
|
---|
| 303 | inline TArray<T> operator + (const TArray<T>& a,const TArray<T>& b)
|
---|
[970] | 304 | { TArray<T> result; result.SetTemp(true);
|
---|
[2575] | 305 | a.AddElt(b, result); return result; }
|
---|
[772] | 306 |
|
---|
[958] | 307 | /*! \ingroup TArray \fn operator-(const TArray<T>&,const TArray<T>&)
|
---|
[2588] | 308 | \brief Operator TArray = TArray - TArray (element by element subtraction) */
|
---|
[772] | 309 | template <class T>
|
---|
| 310 | inline TArray<T> operator - (const TArray<T>& a,const TArray<T>& b)
|
---|
[970] | 311 | { TArray<T> result; result.SetTemp(true);
|
---|
[2575] | 312 | a.SubElt(b, result); return result; }
|
---|
[772] | 313 |
|
---|
[2588] | 314 | /*! \ingroup TArray \fn MultiplyElt((const TArray<T>&,const TArray<T>&)
|
---|
| 315 | \brief Element by element multiplication of two arrays TArray = TArray * TArray */
|
---|
[772] | 316 |
|
---|
[2588] | 317 | template <class T>
|
---|
| 318 | inline TArray<T> MultiplyElt(const TArray<T>& a,const TArray<T>& b)
|
---|
| 319 | { TArray<T> result; result.SetTemp(true);
|
---|
| 320 | a.MulElt(b, result); return result; }
|
---|
| 321 |
|
---|
| 322 | /*! \ingroup TArray \fn DivideElt((const TArray<T>&,const TArray<T>&)
|
---|
| 323 | \brief Element by element division of two arrays TArray = TArray * TArray */
|
---|
| 324 | template <class T>
|
---|
[2589] | 325 | inline TArray<T> DivideElt(const TArray<T>& a,const TArray<T>& b, bool divzero=false)
|
---|
[2588] | 326 | { TArray<T> result; result.SetTemp(true);
|
---|
[2589] | 327 | a.DivElt(b, result, false, divzero); return result; }
|
---|
[2588] | 328 |
|
---|
[772] | 329 | // --------------------------------------------------
|
---|
| 330 | // inline element acces methods
|
---|
| 331 | // --------------------------------------------------
|
---|
[894] | 332 |
|
---|
| 333 | //! Return element (ix,iy,iz,it,iu) value
|
---|
[772] | 334 | template <class T>
|
---|
[1156] | 335 | inline T const& TArray<T>::Elem(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu) const
|
---|
[772] | 336 | {
|
---|
| 337 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 338 | ix*step_[0] + iy*step_[1] + iz*step_[2] +
|
---|
| 339 | it*step_[3] + iu*step_[4]) );
|
---|
| 340 | }
|
---|
| 341 |
|
---|
[894] | 342 | //! Return element (ix,iy,iz,it,iu) value
|
---|
[772] | 343 | template <class T>
|
---|
[1156] | 344 | inline T & TArray<T>::Elem(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu)
|
---|
[772] | 345 | {
|
---|
| 346 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 347 | ix*step_[0] + iy*step_[1] + iz*step_[2] +
|
---|
| 348 | it*step_[3] + iu*step_[4]) );
|
---|
| 349 | }
|
---|
| 350 |
|
---|
[894] | 351 | //! Return element (ix,iy,iz,it,iu) value with Check of indexes bound first
|
---|
[772] | 352 | template <class T>
|
---|
[1156] | 353 | inline T const& TArray<T>::ElemCheckBound(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu) const
|
---|
[772] | 354 | {
|
---|
| 355 | CheckBound(ix, iy, iz, it, iu, 4);
|
---|
[804] | 356 | return(Elem(ix, iy, iz, it, iu));
|
---|
[772] | 357 | }
|
---|
| 358 |
|
---|
[894] | 359 | //! Return element (ix,iy,iz,it,iu) value with Check of indexes bound first
|
---|
[772] | 360 | template <class T>
|
---|
[1156] | 361 | inline T & TArray<T>::ElemCheckBound(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu)
|
---|
[772] | 362 | {
|
---|
| 363 | CheckBound(ix, iy, iz, it, iu, 4);
|
---|
[804] | 364 | return(Elem(ix, iy, iz, it, iu));
|
---|
[772] | 365 | }
|
---|
| 366 |
|
---|
[894] | 367 | //! Return element (ix,iy,iz) value
|
---|
[772] | 368 | template <class T>
|
---|
[1156] | 369 | inline T const& TArray<T>::operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz) const
|
---|
[772] | 370 | {
|
---|
| 371 | #ifdef SO_BOUNDCHECKING
|
---|
| 372 | CheckBound(ix, iy, iz, 0, 0, 4);
|
---|
| 373 | #endif
|
---|
| 374 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 375 | ix*step_[0] + iy*step_[1] + iz*step_[2]) );
|
---|
| 376 | }
|
---|
| 377 |
|
---|
[894] | 378 | //! Return element (ix,iy,iz) value
|
---|
[772] | 379 | template <class T>
|
---|
[1156] | 380 | inline T & TArray<T>::operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz)
|
---|
[772] | 381 | {
|
---|
| 382 | #ifdef SO_BOUNDCHECKING
|
---|
| 383 | CheckBound(ix, iy, iz, 0, 0, 4);
|
---|
| 384 | #endif
|
---|
| 385 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 386 | ix*step_[0] + iy*step_[1] + iz*step_[2]) );
|
---|
| 387 | }
|
---|
| 388 |
|
---|
[894] | 389 | //! Operator () : return element (ix,iy,iz,it,iu) value
|
---|
[772] | 390 | template <class T>
|
---|
[1156] | 391 | inline T const& TArray<T>::operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu) const
|
---|
[772] | 392 | {
|
---|
| 393 | #ifdef SO_BOUNDCHECKING
|
---|
| 394 | CheckBound(ix, iy, iz, it, iu, 4);
|
---|
| 395 | #endif
|
---|
| 396 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 397 | ix*step_[0] + iy*step_[1] + iz*step_[2] +
|
---|
| 398 | it*step_[3] + iu*step_[4]) );
|
---|
| 399 | }
|
---|
| 400 |
|
---|
[894] | 401 | //! Operator () : return element (ix,iy,iz,it,iu) value
|
---|
[772] | 402 | template <class T>
|
---|
[1156] | 403 | inline T & TArray<T>::operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu)
|
---|
[772] | 404 | {
|
---|
| 405 | #ifdef SO_BOUNDCHECKING
|
---|
| 406 | CheckBound(ix, iy, iz, it, iu, 4);
|
---|
| 407 | #endif
|
---|
| 408 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 409 | ix*step_[0] + iy*step_[1] + iz*step_[2] +
|
---|
| 410 | it*step_[3] + iu*step_[4]) );
|
---|
| 411 | }
|
---|
| 412 |
|
---|
[785] | 413 |
|
---|
[894] | 414 | //! Operator [] : return element at positon ip
|
---|
[772] | 415 | template <class T>
|
---|
[1156] | 416 | inline T const& TArray<T>::operator[](sa_size_t ip) const
|
---|
[772] | 417 | {
|
---|
| 418 | #ifdef SO_BOUNDCHECKING
|
---|
| 419 | if (ip >= totsize_) throw( ParmError("TArray<T>::operator[] Out-of-bound Error") );
|
---|
| 420 | #endif
|
---|
[785] | 421 | return *(mNDBlock.Begin()+Offset(ip));
|
---|
[772] | 422 | }
|
---|
| 423 |
|
---|
[894] | 424 | //! Operator [] : return element at positon ip
|
---|
[772] | 425 | template <class T>
|
---|
[1156] | 426 | inline T & TArray<T>::operator[](sa_size_t ip)
|
---|
[772] | 427 | {
|
---|
| 428 | #ifdef SO_BOUNDCHECKING
|
---|
| 429 | if (ip >= totsize_) throw( ParmError("TArray<T>::operator[] Out-of-bound Error") );
|
---|
| 430 | #endif
|
---|
[785] | 431 | return *(mNDBlock.Begin()+Offset(ip));
|
---|
[772] | 432 | }
|
---|
| 433 |
|
---|
[785] | 434 |
|
---|
[1156] | 435 | //! Converts to a scalar (value of first element) if the array size is equal to 1
|
---|
[772] | 436 | template <class T>
|
---|
[787] | 437 | inline T TArray<T>::toScalar()
|
---|
[772] | 438 | {
|
---|
| 439 | if (Size() != 1) throw(SzMismatchError("TArray<T>::operator T() Size() != 1")) ;
|
---|
| 440 | return ( (*this)[0] );
|
---|
| 441 | }
|
---|
| 442 |
|
---|
[804] | 443 | // Typedef pour simplifier
|
---|
[956] | 444 | /*! \ingroup TArray
|
---|
| 445 | \typedef Array
|
---|
| 446 | \brief To simplified TArray<r_8> writing
|
---|
| 447 | */
|
---|
[804] | 448 | typedef TArray<r_8> Array;
|
---|
| 449 |
|
---|
[772] | 450 | } // Fin du namespace
|
---|
| 451 |
|
---|
| 452 | #endif
|
---|