[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 |
|
---|
[2915] | 79 | //! Extract the first 3D subarray specified by rx, ry, rz. (see SubArray() )
|
---|
[963] | 80 | inline TArray<T> operator () (Range rx, Range ry, Range rz) const
|
---|
[2915] | 81 | { return SubArray(rx, ry, rz, Range::first(), Range::first()); }
|
---|
| 82 | //! Extract the first 4D subarray specified by rx, ry, rz. (see SubArray() )
|
---|
[963] | 83 | inline TArray<T> operator () (Range rx, Range ry, Range rz, Range rt) const
|
---|
[2915] | 84 | { return SubArray(rx, ry, rz, rt, Range::first()); }
|
---|
| 85 | //! Extract the subarray specified by rx, ry, rz. (see SubArray() )
|
---|
[963] | 86 | inline TArray<T> operator () (Range rx, Range ry, Range rz, Range rt, Range ru) const
|
---|
| 87 | { return SubArray(rx, ry, rz, rt, ru); }
|
---|
[772] | 88 |
|
---|
[787] | 89 | // ---- Access to data
|
---|
| 90 | // Definition of virtual element acces method inherited from BaseArray class
|
---|
[1156] | 91 | virtual MuTyV & ValueAtPosition(sa_size_t ip) const;
|
---|
[2888] | 92 | virtual MuTyV & ValueAtPositionDB(sa_size_t ip) const;
|
---|
[785] | 93 |
|
---|
[787] | 94 | // Data Access: operator overloaded inline acces methods
|
---|
[1156] | 95 | inline T const& operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz) const ;
|
---|
| 96 | inline T& operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz);
|
---|
| 97 | 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 ;
|
---|
| 98 | inline T& operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu=0);
|
---|
| 99 | inline T const& operator[](sa_size_t ip) const ;
|
---|
| 100 | inline T& operator[](sa_size_t ip);
|
---|
[772] | 101 |
|
---|
[1156] | 102 | 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 ;
|
---|
| 103 | 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);
|
---|
| 104 | 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 ;
|
---|
| 105 | 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] | 106 |
|
---|
[894] | 107 | //! Return pointer to first element adress
|
---|
[772] | 108 | inline T* Data() {return mNDBlock.Begin()+offset_;}
|
---|
[894] | 109 | //! Return pointer to first element adress
|
---|
[772] | 110 | inline const T* Data() const {return mNDBlock.Begin()+offset_;}
|
---|
[894] | 111 | //! Return reference to datablock NDataBlock
|
---|
[772] | 112 | inline NDataBlock<T>& DataBlock() {return mNDBlock;}
|
---|
[894] | 113 | //! Return reference to datablock NDataBlock
|
---|
[772] | 114 | inline const NDataBlock<T>& DataBlock() const {return mNDBlock;}
|
---|
| 115 |
|
---|
[787] | 116 | // Temporaire?
|
---|
[894] | 117 | //! Are the array temporay ?
|
---|
[787] | 118 | inline bool IsTemp(void) const {return mNDBlock.IsTemp();}
|
---|
[894] | 119 | //! Set the array as temporay
|
---|
[787] | 120 | inline void SetTemp(bool temp=false) const {mNDBlock.SetTemp(temp);}
|
---|
| 121 |
|
---|
[772] | 122 | // Operations diverses = , +=, ...
|
---|
| 123 | // Conversion en type T, if Size() == 1
|
---|
[787] | 124 | inline T toScalar();
|
---|
[772] | 125 | // Met les elements a une suite de valeurs
|
---|
[1103] | 126 | virtual TArray<T>& SetSeq(Sequence const & seq);
|
---|
[894] | 127 | //! Fill TArray with Sequence \b seq
|
---|
[1103] | 128 | inline TArray<T>& operator = (Sequence const & seq) { return SetSeq(seq); }
|
---|
[2575] | 129 |
|
---|
[772] | 130 | // A = x (tous les elements a x)
|
---|
[2575] | 131 | virtual TArray<T>& SetCst(T x);
|
---|
| 132 | //! Fill an array with a constant value \b x ( alias for \b SetCst() method )
|
---|
| 133 | inline TArray<T>& SetT(T x) { return SetCst(x); }
|
---|
[894] | 134 | //! Fill TArray with all elements equal to \b x
|
---|
[813] | 135 | inline TArray<T>& operator = (T x) { return SetT(x); }
|
---|
[2564] | 136 |
|
---|
| 137 | // addition et soustraction de constante
|
---|
| 138 | virtual TArray<T>& AddCst(T x, TArray<T>& res) const ;
|
---|
| 139 | virtual TArray<T>& SubCst(T x, TArray<T>& res, bool fginv=false) const ;
|
---|
| 140 | // Multiplication et division par une constante
|
---|
| 141 | virtual TArray<T>& MulCst(T x, TArray<T>& res) const ;
|
---|
| 142 | virtual TArray<T>& DivCst(T x, TArray<T>& res, bool fginv=false) const ;
|
---|
| 143 |
|
---|
[772] | 144 | // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
|
---|
[2575] | 145 | // Methodes Add/Sub/Mul/Div() sont la pour compatibilite avant V=2 (1.818)
|
---|
| 146 | // Faut-il les garder ? Reza, Juillet 2004
|
---|
[2564] | 147 | inline TArray<T>& Add(T x) { return AddCst(x, *this); }
|
---|
| 148 | inline TArray<T>& Sub(T x, bool fginv=false) { return SubCst(x, *this, fginv); }
|
---|
| 149 | inline TArray<T>& Mul(T x) { return MulCst(x, *this); }
|
---|
| 150 | inline TArray<T>& Div(T x, bool fginv=false) { return DivCst(x, *this, fginv); }
|
---|
| 151 |
|
---|
[894] | 152 | //! Add \b x to all elements
|
---|
[2564] | 153 | inline TArray<T>& operator += (T x) { return AddCst(x, *this); }
|
---|
[894] | 154 | //! Substract \b x to all elements
|
---|
[2564] | 155 | inline TArray<T>& operator -= (T x) { return SubCst(x, *this); }
|
---|
[894] | 156 | //! Multiply all elements by \b x
|
---|
[2564] | 157 | inline TArray<T>& operator *= (T x) { return MulCst(x, *this); }
|
---|
[894] | 158 | //! Divide all elements by \b x
|
---|
[2564] | 159 | inline TArray<T>& operator /= (T x) { return DivCst(x, *this); }
|
---|
[804] | 160 |
|
---|
[1156] | 161 | // applique le signe moins a tous les elements
|
---|
[2564] | 162 | virtual TArray<T>& NegateElt(TArray<T>& res) const ;
|
---|
| 163 | //! Replace array elements values by their opposite ( (*this)(i) -> -(*this)(i) )
|
---|
| 164 | inline TArray<T>& NegateElt() { return NegateElt(*this); }
|
---|
| 165 |
|
---|
[772] | 166 | // A += -= (ajoute, soustrait element par element les deux tableaux )
|
---|
[2575] | 167 | virtual TArray<T>& AddElt(const TArray<T>& a, TArray<T>& res) const ;
|
---|
| 168 | virtual TArray<T>& SubElt(const TArray<T>& a, TArray<T>& res, bool fginv=false) const ;
|
---|
[787] | 169 | // Multiplication, division element par element les deux tableaux
|
---|
[2575] | 170 | virtual TArray<T>& MulElt(const TArray<T>& a, TArray<T>& res) const ;
|
---|
| 171 | virtual TArray<T>& DivElt(const TArray<T>& a, TArray<T>& res, bool fginv=false, bool divzero=false) const ;
|
---|
| 172 |
|
---|
| 173 | //! Operator TArray += TArray (element by element addition in place)
|
---|
| 174 | inline TArray<T>& operator += (const TArray<T>& a) { return AddElt(a, *this); }
|
---|
| 175 | //! Operator TArray -= TArray (element by element subtraction in place)
|
---|
| 176 | inline TArray<T>& operator -= (const TArray<T>& a) { return SubElt(a, *this); }
|
---|
| 177 |
|
---|
[2588] | 178 | // Doit-on definir les operateur *= /= TArray ? Reza, Juillet 2004
|
---|
| 179 | //! Element by element multiplication in place TArray *= TArray (element by element)
|
---|
| 180 | inline TArray<T>& Mul(const TArray<T>& a) { return MulElt(a, *this); }
|
---|
| 181 | //! Element by element division in place TArray *= TArray (element by element)
|
---|
[2589] | 182 | inline TArray<T>& Div(const TArray<T>& a, bool divzero=false)
|
---|
| 183 | { return DivElt(a, *this, false, divzero); }
|
---|
[2588] | 184 |
|
---|
[804] | 185 | // Recopie des valeurs, element par element
|
---|
| 186 | virtual TArray<T>& CopyElt(const TArray<T>& a);
|
---|
[1081] | 187 | // Recopie des valeurs avec conversion prealable, element par element
|
---|
| 188 | virtual TArray<T>& ConvertAndCopyElt(const BaseArray& a);
|
---|
[772] | 189 |
|
---|
[2575] | 190 | // Calcul du produit scalaire ( Somme_i (*this)(i)*a(i) )
|
---|
| 191 | virtual T ScalarProduct(const TArray<T>& a) const ;
|
---|
| 192 | // Norme(^2)
|
---|
| 193 | //! Returns the squarred of the array norm, defined as Sum_k (*this)(k)*(*this)(k)
|
---|
| 194 | inline T Norm2() const { return ScalarProduct(*this); }
|
---|
| 195 |
|
---|
[804] | 196 | // Somme et produit des elements
|
---|
| 197 | virtual T Sum() const ;
|
---|
| 198 | virtual T Product() const ;
|
---|
[1113] | 199 | // Somme du carre des elements
|
---|
| 200 | virtual T SumX2() const;
|
---|
| 201 | // Valeur min et max des elements
|
---|
| 202 | virtual void MinMax(T& min, T& max) const ;
|
---|
[804] | 203 |
|
---|
[772] | 204 | // Impression, I/O, ...
|
---|
[813] | 205 | virtual string InfoString() const;
|
---|
[1550] | 206 | virtual void Print(ostream& os, sa_size_t maxprt=-1,
|
---|
| 207 | bool si=false, bool ascd=false) const ;
|
---|
[772] | 208 |
|
---|
[1517] | 209 | // Lecture,Ecriture sur fichier ASCII
|
---|
[2286] | 210 | virtual sa_size_t ReadASCII(istream& is, sa_size_t & nr, sa_size_t & nc,
|
---|
| 211 | char clm='#', const char* sep=" \t");
|
---|
[1517] | 212 | virtual void WriteASCII(ostream& os) const;
|
---|
| 213 |
|
---|
[772] | 214 | // Pour la gestion de persistance
|
---|
| 215 | friend class FIO_TArray<T>;
|
---|
| 216 |
|
---|
| 217 | protected:
|
---|
| 218 |
|
---|
[894] | 219 | NDataBlock<T> mNDBlock; //!< Block for datas
|
---|
[1081] | 220 | mutable MuTyV my_mtv; //!< for use by ValueAtPosition()
|
---|
[772] | 221 | };
|
---|
| 222 |
|
---|
| 223 | ////////////////////////////////////////////////////////////////
|
---|
| 224 | // Surcharge d'operateur <<
|
---|
[894] | 225 | //! Print TArray \b a on stream \b os
|
---|
[772] | 226 | template <class T>
|
---|
| 227 | inline ostream& operator << (ostream& os, const TArray<T>& a)
|
---|
| 228 | { a.Print(os); return(os); }
|
---|
| 229 |
|
---|
[1517] | 230 | // Surcharge d'operateur >>
|
---|
| 231 | //! Decodes the ASCII input stream \b is , filling TArray \b a elements
|
---|
| 232 | template <class T>
|
---|
| 233 | inline istream& operator >> (istream& is, TArray<T>& a)
|
---|
[1576] | 234 | { sa_size_t nr, nc;
|
---|
| 235 | a.ReadASCII(is, nr, nc); return(is); }
|
---|
[1517] | 236 |
|
---|
| 237 |
|
---|
[772] | 238 | ////////////////////////////////////////////////////////////////
|
---|
| 239 | // Surcharge d'operateurs A (+,-,*,/) (T) x
|
---|
| 240 |
|
---|
[958] | 241 | /*! \ingroup TArray \fn operator+(const TArray<T>&,T)
|
---|
| 242 | \brief Operator TArray = TArray + constant */
|
---|
[772] | 243 | template <class T> inline TArray<T> operator + (const TArray<T>& a, T b)
|
---|
[2564] | 244 | {TArray<T> result; result.SetTemp(true);
|
---|
[2569] | 245 | a.AddCst(b, result); return result;}
|
---|
[772] | 246 |
|
---|
[958] | 247 | /*! \ingroup TArray \fn operator+(T,const TArray<T>&)
|
---|
| 248 | \brief Operator TArray = constant + TArray */
|
---|
[772] | 249 | template <class T> inline TArray<T> operator + (T b,const TArray<T>& a)
|
---|
[2564] | 250 | {TArray<T> result; result.SetTemp(true);
|
---|
[2569] | 251 | a.AddCst(b, result); return result;}
|
---|
[772] | 252 |
|
---|
[958] | 253 | /*! \ingroup TArray \fn operator-(const TArray<T>&,T)
|
---|
| 254 | \brief Operator TArray = TArray - constant */
|
---|
[772] | 255 | template <class T> inline TArray<T> operator - (const TArray<T>& a, T b)
|
---|
[2564] | 256 | {TArray<T> result; result.SetTemp(true);
|
---|
[2569] | 257 | a.SubCst(b,result); return result;}
|
---|
[772] | 258 |
|
---|
[958] | 259 | /*! \ingroup TArray \fn operator-(T,const TArray<T>&)
|
---|
| 260 | \brief Operator TArray = constant - TArray */
|
---|
[772] | 261 | template <class T> inline TArray<T> operator - (T b,const TArray<T>& a)
|
---|
[2564] | 262 | {TArray<T> result; result.SetTemp(true);
|
---|
[2569] | 263 | a.SubCst(b,result,true); return result;}
|
---|
[772] | 264 |
|
---|
[958] | 265 | /*! \ingroup TArray \fn operator*(const TArray<T>&,T)
|
---|
| 266 | \brief Operator TArray = TArray * constant */
|
---|
[772] | 267 | template <class T> inline TArray<T> operator * (const TArray<T>& a, T b)
|
---|
[2564] | 268 | {TArray<T> result; result.SetTemp(true);
|
---|
| 269 | a.MulCst(b, result); return result;}
|
---|
[772] | 270 |
|
---|
[958] | 271 | /*! \ingroup TArray \fn operator*(T,const TArray<T>&)
|
---|
| 272 | \brief Operator TArray = constant * TArray */
|
---|
[772] | 273 | template <class T> inline TArray<T> operator * (T b,const TArray<T>& a)
|
---|
[2564] | 274 | {TArray<T> result; result.SetTemp(true);
|
---|
| 275 | a.MulCst(b,result); return result;}
|
---|
[772] | 276 |
|
---|
[958] | 277 | /*! \ingroup TArray \fn operator/(const TArray<T>&,T)
|
---|
| 278 | \brief Operator TArray = TArray / constant */
|
---|
[772] | 279 | template <class T> inline TArray<T> operator / (const TArray<T>& a, T b)
|
---|
[2564] | 280 | {TArray<T> result; result.SetTemp(true);
|
---|
[2569] | 281 | a.DivCst(b,result); return result;}
|
---|
[772] | 282 |
|
---|
[970] | 283 | /*! \ingroup TArray \fn operator/(T,const TArray<T>&)
|
---|
| 284 | \brief Operator TArray = constant / TArray */
|
---|
| 285 | template <class T> inline TArray<T> operator / (T b, const TArray<T>& a)
|
---|
[2564] | 286 | {TArray<T> result; result.SetTemp(true);
|
---|
[2569] | 287 | a.DivCst(b, result, true); return result;}
|
---|
[970] | 288 |
|
---|
[772] | 289 | ////////////////////////////////////////////////////////////////
|
---|
[1156] | 290 | // Surcharge d'operateurs B = -A
|
---|
| 291 |
|
---|
| 292 | /*! \ingroup TArray \fn operator - (const TArray<T>&)
|
---|
| 293 | \brief Operator - Returns an array with elements equal to the opposite of
|
---|
| 294 | the original array elements. */
|
---|
| 295 | template <class T> inline TArray<T> operator - (const TArray<T>& a)
|
---|
[2569] | 296 | {TArray<T> result; result.SetTemp(true);
|
---|
| 297 | a.NegateElt(result); return result;}
|
---|
[1156] | 298 |
|
---|
| 299 | ////////////////////////////////////////////////////////////////
|
---|
[772] | 300 | // Surcharge d'operateurs C = A (+,-) B
|
---|
| 301 |
|
---|
[958] | 302 | /*! \ingroup TArray \fn operator+(const TArray<T>&,const TArray<T>&)
|
---|
[2588] | 303 | \brief Operator TArray = TArray + TArray (element by element addition) */
|
---|
[772] | 304 | template <class T>
|
---|
| 305 | inline TArray<T> operator + (const TArray<T>& a,const TArray<T>& b)
|
---|
[970] | 306 | { TArray<T> result; result.SetTemp(true);
|
---|
[2575] | 307 | a.AddElt(b, result); return result; }
|
---|
[772] | 308 |
|
---|
[958] | 309 | /*! \ingroup TArray \fn operator-(const TArray<T>&,const TArray<T>&)
|
---|
[2588] | 310 | \brief Operator TArray = TArray - TArray (element by element subtraction) */
|
---|
[772] | 311 | template <class T>
|
---|
| 312 | inline TArray<T> operator - (const TArray<T>& a,const TArray<T>& b)
|
---|
[970] | 313 | { TArray<T> result; result.SetTemp(true);
|
---|
[2575] | 314 | a.SubElt(b, result); return result; }
|
---|
[772] | 315 |
|
---|
[2588] | 316 | /*! \ingroup TArray \fn MultiplyElt((const TArray<T>&,const TArray<T>&)
|
---|
| 317 | \brief Element by element multiplication of two arrays TArray = TArray * TArray */
|
---|
[772] | 318 |
|
---|
[2588] | 319 | template <class T>
|
---|
| 320 | inline TArray<T> MultiplyElt(const TArray<T>& a,const TArray<T>& b)
|
---|
| 321 | { TArray<T> result; result.SetTemp(true);
|
---|
| 322 | a.MulElt(b, result); return result; }
|
---|
| 323 |
|
---|
| 324 | /*! \ingroup TArray \fn DivideElt((const TArray<T>&,const TArray<T>&)
|
---|
| 325 | \brief Element by element division of two arrays TArray = TArray * TArray */
|
---|
| 326 | template <class T>
|
---|
[2589] | 327 | inline TArray<T> DivideElt(const TArray<T>& a,const TArray<T>& b, bool divzero=false)
|
---|
[2588] | 328 | { TArray<T> result; result.SetTemp(true);
|
---|
[2589] | 329 | a.DivElt(b, result, false, divzero); return result; }
|
---|
[2588] | 330 |
|
---|
[772] | 331 | // --------------------------------------------------
|
---|
| 332 | // inline element acces methods
|
---|
| 333 | // --------------------------------------------------
|
---|
[894] | 334 |
|
---|
| 335 | //! Return element (ix,iy,iz,it,iu) value
|
---|
[772] | 336 | template <class T>
|
---|
[1156] | 337 | 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] | 338 | {
|
---|
| 339 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 340 | ix*step_[0] + iy*step_[1] + iz*step_[2] +
|
---|
| 341 | it*step_[3] + iu*step_[4]) );
|
---|
| 342 | }
|
---|
| 343 |
|
---|
[894] | 344 | //! Return element (ix,iy,iz,it,iu) value
|
---|
[772] | 345 | template <class T>
|
---|
[1156] | 346 | 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] | 347 | {
|
---|
| 348 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 349 | ix*step_[0] + iy*step_[1] + iz*step_[2] +
|
---|
| 350 | it*step_[3] + iu*step_[4]) );
|
---|
| 351 | }
|
---|
| 352 |
|
---|
[894] | 353 | //! Return element (ix,iy,iz,it,iu) value with Check of indexes bound first
|
---|
[772] | 354 | template <class T>
|
---|
[1156] | 355 | 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] | 356 | {
|
---|
| 357 | CheckBound(ix, iy, iz, it, iu, 4);
|
---|
[804] | 358 | return(Elem(ix, iy, iz, it, iu));
|
---|
[772] | 359 | }
|
---|
| 360 |
|
---|
[894] | 361 | //! Return element (ix,iy,iz,it,iu) value with Check of indexes bound first
|
---|
[772] | 362 | template <class T>
|
---|
[1156] | 363 | 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] | 364 | {
|
---|
| 365 | CheckBound(ix, iy, iz, it, iu, 4);
|
---|
[804] | 366 | return(Elem(ix, iy, iz, it, iu));
|
---|
[772] | 367 | }
|
---|
| 368 |
|
---|
[894] | 369 | //! Return element (ix,iy,iz) value
|
---|
[772] | 370 | template <class T>
|
---|
[1156] | 371 | inline T const& TArray<T>::operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz) const
|
---|
[772] | 372 | {
|
---|
| 373 | #ifdef SO_BOUNDCHECKING
|
---|
| 374 | CheckBound(ix, iy, iz, 0, 0, 4);
|
---|
| 375 | #endif
|
---|
| 376 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 377 | ix*step_[0] + iy*step_[1] + iz*step_[2]) );
|
---|
| 378 | }
|
---|
| 379 |
|
---|
[894] | 380 | //! Return element (ix,iy,iz) value
|
---|
[772] | 381 | template <class T>
|
---|
[1156] | 382 | inline T & TArray<T>::operator()(sa_size_t ix, sa_size_t iy, sa_size_t iz)
|
---|
[772] | 383 | {
|
---|
| 384 | #ifdef SO_BOUNDCHECKING
|
---|
| 385 | CheckBound(ix, iy, iz, 0, 0, 4);
|
---|
| 386 | #endif
|
---|
| 387 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 388 | ix*step_[0] + iy*step_[1] + iz*step_[2]) );
|
---|
| 389 | }
|
---|
| 390 |
|
---|
[894] | 391 | //! Operator () : return element (ix,iy,iz,it,iu) value
|
---|
[772] | 392 | template <class T>
|
---|
[1156] | 393 | 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] | 394 | {
|
---|
| 395 | #ifdef SO_BOUNDCHECKING
|
---|
| 396 | CheckBound(ix, iy, iz, it, iu, 4);
|
---|
| 397 | #endif
|
---|
| 398 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 399 | ix*step_[0] + iy*step_[1] + iz*step_[2] +
|
---|
| 400 | it*step_[3] + iu*step_[4]) );
|
---|
| 401 | }
|
---|
| 402 |
|
---|
[894] | 403 | //! Operator () : return element (ix,iy,iz,it,iu) value
|
---|
[772] | 404 | template <class T>
|
---|
[1156] | 405 | 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] | 406 | {
|
---|
| 407 | #ifdef SO_BOUNDCHECKING
|
---|
| 408 | CheckBound(ix, iy, iz, it, iu, 4);
|
---|
| 409 | #endif
|
---|
| 410 | return ( *( mNDBlock.Begin()+ offset_+
|
---|
| 411 | ix*step_[0] + iy*step_[1] + iz*step_[2] +
|
---|
| 412 | it*step_[3] + iu*step_[4]) );
|
---|
| 413 | }
|
---|
| 414 |
|
---|
[785] | 415 |
|
---|
[894] | 416 | //! Operator [] : return element at positon ip
|
---|
[772] | 417 | template <class T>
|
---|
[1156] | 418 | inline T const& TArray<T>::operator[](sa_size_t ip) const
|
---|
[772] | 419 | {
|
---|
| 420 | #ifdef SO_BOUNDCHECKING
|
---|
| 421 | if (ip >= totsize_) throw( ParmError("TArray<T>::operator[] Out-of-bound Error") );
|
---|
| 422 | #endif
|
---|
[785] | 423 | return *(mNDBlock.Begin()+Offset(ip));
|
---|
[772] | 424 | }
|
---|
| 425 |
|
---|
[894] | 426 | //! Operator [] : return element at positon ip
|
---|
[772] | 427 | template <class T>
|
---|
[1156] | 428 | inline T & TArray<T>::operator[](sa_size_t ip)
|
---|
[772] | 429 | {
|
---|
| 430 | #ifdef SO_BOUNDCHECKING
|
---|
| 431 | if (ip >= totsize_) throw( ParmError("TArray<T>::operator[] Out-of-bound Error") );
|
---|
| 432 | #endif
|
---|
[785] | 433 | return *(mNDBlock.Begin()+Offset(ip));
|
---|
[772] | 434 | }
|
---|
| 435 |
|
---|
[785] | 436 |
|
---|
[1156] | 437 | //! Converts to a scalar (value of first element) if the array size is equal to 1
|
---|
[772] | 438 | template <class T>
|
---|
[787] | 439 | inline T TArray<T>::toScalar()
|
---|
[772] | 440 | {
|
---|
| 441 | if (Size() != 1) throw(SzMismatchError("TArray<T>::operator T() Size() != 1")) ;
|
---|
| 442 | return ( (*this)[0] );
|
---|
| 443 | }
|
---|
| 444 |
|
---|
[804] | 445 | // Typedef pour simplifier
|
---|
[956] | 446 | /*! \ingroup TArray
|
---|
| 447 | \typedef Array
|
---|
| 448 | \brief To simplified TArray<r_8> writing
|
---|
| 449 | */
|
---|
[804] | 450 | typedef TArray<r_8> Array;
|
---|
| 451 |
|
---|
[772] | 452 | } // Fin du namespace
|
---|
| 453 |
|
---|
| 454 | #endif
|
---|