[772] | 1 | // template array class for numerical types
|
---|
| 2 | // R. Ansari, C.Magneville 03/2000
|
---|
| 3 |
|
---|
| 4 | #include "machdefs.h"
|
---|
| 5 | #include <stdio.h>
|
---|
| 6 | #include <stdlib.h>
|
---|
[922] | 7 | #include <math.h>
|
---|
[772] | 8 | #include "pexceptions.h"
|
---|
| 9 | #include "tarray.h"
|
---|
| 10 |
|
---|
[926] | 11 | /*!
|
---|
| 12 | \class SOPHYA::TArray
|
---|
| 13 | \ingroup TArray
|
---|
| 14 | Class for template arrays
|
---|
[772] | 15 |
|
---|
[926] | 16 | This class implements arrays of dimensions up to
|
---|
| 17 | \ref BASEARRAY_MAXNDIMS "BASEARRAY_MAXNDIMS"
|
---|
| 18 | */
|
---|
[772] | 19 |
|
---|
| 20 | // -------------------------------------------------------
|
---|
| 21 | // Methodes de la classe
|
---|
| 22 | // -------------------------------------------------------
|
---|
| 23 |
|
---|
[894] | 24 | ////////////////////////// Les constructeurs / destructeurs
|
---|
| 25 |
|
---|
| 26 | //! Default constructor
|
---|
[772] | 27 | template <class T>
|
---|
| 28 | TArray<T>::TArray()
|
---|
[804] | 29 | : BaseArray() , mNDBlock()
|
---|
[772] | 30 | {
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[894] | 33 | //! Constructor
|
---|
| 34 | /*!
|
---|
| 35 | \param ndim : number of dimensions (less or equal to
|
---|
| 36 | \ref BASEARRAY_MAXNDIMS "BASEARRAY_MAXNDIMS")
|
---|
| 37 | \param siz[ndim] : size along each dimension
|
---|
| 38 | \param step : step (same for all dimensions)
|
---|
| 39 | */
|
---|
[772] | 40 | template <class T>
|
---|
[804] | 41 | TArray<T>::TArray(uint_4 ndim, const uint_4 * siz, uint_4 step)
|
---|
| 42 | : BaseArray() , mNDBlock(ComputeTotalSize(ndim, siz, step, 1))
|
---|
[772] | 43 | {
|
---|
| 44 | string exmsg = "TArray<T>::TArray(uint_4, uint_4 *, uint_4)";
|
---|
| 45 | if (!UpdateSizes(ndim, siz, step, 0, exmsg)) throw( ParmError(exmsg) );
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[894] | 48 | //! Constructor
|
---|
| 49 | /*!
|
---|
| 50 | \param nx,ny,nz,nt,nu : sizes along first, second, third, fourth and fifth dimension
|
---|
| 51 | */
|
---|
[772] | 52 | template <class T>
|
---|
[804] | 53 | TArray<T>::TArray(uint_4 nx, uint_4 ny, uint_4 nz, uint_4 nt, uint_4 nu)
|
---|
| 54 | : BaseArray() , mNDBlock(nx*((ny>0)?ny:1)*((nz>0)?nz:1)*((nt>0)?nt:1)*((nu>0)?nu:1))
|
---|
[772] | 55 | {
|
---|
[787] | 56 | uint_4 size[BASEARRAY_MAXNDIMS];
|
---|
[772] | 57 | size[0] = nx; size[1] = ny; size[2] = nz;
|
---|
[804] | 58 | size[3] = nt; size[4] = nu;
|
---|
[772] | 59 | int ndim = 1;
|
---|
[804] | 60 | if ((size[1] > 0) && (size[2] > 0) && (size[3] > 0) && (size[4] > 0) ) ndim = 5;
|
---|
| 61 | else if ((size[1] > 0) && (size[2] > 0) && (size[3] > 0) ) ndim = 4;
|
---|
| 62 | else if ((size[1] > 0) && (size[2] > 0)) ndim = 3;
|
---|
[772] | 63 | else if (size[1] > 0) ndim = 2;
|
---|
| 64 | else ndim = 1;
|
---|
| 65 | string exmsg = "TArray<T>::TArray(uint_4, uint_4, uint_4)";
|
---|
| 66 | if (!UpdateSizes(ndim, size, 1, 0, exmsg)) throw( ParmError(exmsg) );
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[894] | 69 | //! Constructor
|
---|
| 70 | /*!
|
---|
| 71 | \param ndim : number of dimensions
|
---|
| 72 | \param siz[ndim] : size along each dimension
|
---|
| 73 | \param db : datas are given by this NDataBlock
|
---|
| 74 | \param share : if true, data are shared, if false they are copied
|
---|
| 75 | \param step : step (same for all dimensions) in data block
|
---|
| 76 | \param offset : offset for first element in data block
|
---|
| 77 | */
|
---|
[772] | 78 | template <class T>
|
---|
[804] | 79 | TArray<T>::TArray(uint_4 ndim, const uint_4 * siz, NDataBlock<T> & db, bool share, uint_4 step, uint_8 offset)
|
---|
| 80 | : BaseArray() , mNDBlock(db, share)
|
---|
[772] | 81 | {
|
---|
| 82 | string exmsg = "TArray<T>::TArray(uint_4, uint_4 *, NDataBlock<T> & ... )";
|
---|
| 83 | if (!UpdateSizes(ndim, siz, step, offset, exmsg)) throw( ParmError(exmsg) );
|
---|
| 84 |
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[894] | 87 | //! Constructor
|
---|
| 88 | /*!
|
---|
| 89 | \param ndim : number of dimensions
|
---|
| 90 | \param siz[ndim] : size along each dimension
|
---|
| 91 | \param values : datas are given by this pointer
|
---|
| 92 | \param share : if true, data are shared, if false they are copied
|
---|
| 93 | \param step : step (same for all dimensions) in data block
|
---|
| 94 | \param offset : offset for first element in data block
|
---|
| 95 | \param br : if not NULL, dats are bridge with other datas
|
---|
| 96 | \sa NDataBlock
|
---|
| 97 | */
|
---|
[772] | 98 | template <class T>
|
---|
[804] | 99 | TArray<T>::TArray(uint_4 ndim, const uint_4 * siz, T* values, uint_4 step, uint_8 offset, Bridge* br)
|
---|
| 100 | : BaseArray() , mNDBlock(ComputeTotalSize(ndim, siz, step, 1), values, br)
|
---|
[772] | 101 | {
|
---|
| 102 | string exmsg = "TArray<T>::TArray(uint_4, uint_4 *, T* ... )";
|
---|
| 103 | if (!UpdateSizes(ndim, siz, step, offset, exmsg)) throw( ParmError(exmsg) );
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[894] | 106 | //! Constructor by copy
|
---|
[976] | 107 | /*!
|
---|
| 108 | \warning datas are \b SHARED with \b a.
|
---|
| 109 | \sa NDataBlock::NDataBlock(const NDataBlock<T>&)
|
---|
| 110 | */
|
---|
[772] | 111 | template <class T>
|
---|
| 112 | TArray<T>::TArray(const TArray<T>& a)
|
---|
[804] | 113 | : BaseArray() , mNDBlock(a.mNDBlock)
|
---|
[772] | 114 | {
|
---|
| 115 | string exmsg = "TArray<T>::TArray(const TArray<T>&)";
|
---|
| 116 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
| 117 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[894] | 120 | //! Constructor by copy
|
---|
| 121 | /*!
|
---|
| 122 | \param share : if true, data are shared, if false they are copied
|
---|
| 123 | */
|
---|
[772] | 124 | template <class T>
|
---|
| 125 | TArray<T>::TArray(const TArray<T>& a, bool share)
|
---|
[804] | 126 | : BaseArray() , mNDBlock(a.mNDBlock, share)
|
---|
[772] | 127 | {
|
---|
| 128 | string exmsg = "TArray<T>::TArray(const TArray<T>&, bool)";
|
---|
| 129 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
| 130 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[1081] | 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 |
|
---|
[894] | 145 | //! Destructor
|
---|
[772] | 146 | template <class T>
|
---|
| 147 | TArray<T>::~TArray()
|
---|
| 148 | {
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[894] | 151 | ////////////////////////// Les methodes de copie/share
|
---|
| 152 |
|
---|
| 153 | //! Set array equal to \b a and return *this
|
---|
[976] | 154 | /*!
|
---|
| 155 | \warning Datas are copied (cloned) from \b a.
|
---|
| 156 | \sa NDataBlock::operator=(const NDataBlock<T>&)
|
---|
| 157 | */
|
---|
[772] | 158 | template <class T>
|
---|
[804] | 159 | TArray<T>& TArray<T>::Set(const TArray<T>& a)
|
---|
[772] | 160 | {
|
---|
[970] | 161 | if (this == &a) return(*this);
|
---|
| 162 | if (a.NbDimensions() < 1)
|
---|
| 163 | throw RangeCheckError("TArray<T>::Set(a ) - Array a not allocated ! ");
|
---|
| 164 | if (NbDimensions() < 1) CloneOrShare(a);
|
---|
| 165 | else CopyElt(a);
|
---|
[772] | 166 | return(*this);
|
---|
| 167 | }
|
---|
| 168 |
|
---|
[1081] | 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 |
|
---|
[894] | 185 | //! Clone array \b a
|
---|
[772] | 186 | template <class T>
|
---|
| 187 | void TArray<T>::Clone(const TArray<T>& a)
|
---|
| 188 | {
|
---|
| 189 | string exmsg = "TArray<T>::Clone()";
|
---|
| 190 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
| 191 | mNDBlock.Clone(a.mNDBlock);
|
---|
[894] | 192 | if (mInfo) {delete mInfo; mInfo = NULL;}
|
---|
[772] | 193 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
| 194 | }
|
---|
| 195 |
|
---|
[970] | 196 | //! Clone if \b a is not temporary, share if temporary
|
---|
[976] | 197 | /*! \sa NDataBlock::CloneOrShare(const NDataBlock<T>&) */
|
---|
[970] | 198 | template <class T>
|
---|
| 199 | void TArray<T>::CloneOrShare(const TArray<T>& a)
|
---|
| 200 | {
|
---|
| 201 | string exmsg = "TArray<T>::CloneOrShare()";
|
---|
[1103] | 202 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
[970] | 203 | mNDBlock.CloneOrShare(a.mNDBlock);
|
---|
[1103] | 204 | if (mInfo) {delete mInfo; mInfo = NULL;}
|
---|
| 205 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
[970] | 206 | }
|
---|
| 207 |
|
---|
| 208 | //! Share data with a
|
---|
| 209 | template <class T>
|
---|
| 210 | void TArray<T>::Share(const TArray<T>& a)
|
---|
| 211 | {
|
---|
| 212 | string exmsg = "TArray<T>::Share()";
|
---|
[1103] | 213 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
[970] | 214 | mNDBlock.Share(a.mNDBlock);
|
---|
[1103] | 215 | if (mInfo) {delete mInfo; mInfo = NULL;}
|
---|
| 216 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
[970] | 217 | }
|
---|
| 218 |
|
---|
| 219 |
|
---|
[894] | 220 | //! Resize array
|
---|
| 221 | /*!
|
---|
| 222 | \param ndim : number of dimensions
|
---|
| 223 | \param siz[ndim] : size along each dimension
|
---|
| 224 | \param step : step (same for all dimensions)
|
---|
| 225 | */
|
---|
[772] | 226 | template <class T>
|
---|
| 227 | void TArray<T>::ReSize(uint_4 ndim, uint_4 * siz, uint_4 step)
|
---|
| 228 | {
|
---|
[1099] | 229 | if (arrtype_ != 0) {
|
---|
| 230 | if (ndim != 2)
|
---|
| 231 | throw( ParmError("TArray<T>::ReSize(ndim!=2,...) for Matrix" ) );
|
---|
| 232 | if ((arrtype_ == 2) && (siz[0] > 1) && (siz[1] > 1))
|
---|
| 233 | throw( ParmError("TArray<T>::ReSize(,siz[0]>1 && size[1]>1) for Vector" ) );
|
---|
| 234 | }
|
---|
[772] | 235 | string exmsg = "TArray<T>::ReSize()";
|
---|
| 236 | if (!UpdateSizes(ndim, siz, step, 0, exmsg)) throw( ParmError(exmsg) );
|
---|
| 237 | mNDBlock.ReSize(totsize_);
|
---|
| 238 | }
|
---|
| 239 |
|
---|
[894] | 240 | //! Re-allocate space for array
|
---|
| 241 | /*!
|
---|
| 242 | \param ndim : number of dimensions
|
---|
| 243 | \param siz[ndim] : size along each dimension
|
---|
| 244 | \param step : step (same for all dimensions)
|
---|
| 245 | \param force : if true re-allocation is forced, if not it occurs
|
---|
| 246 | only if the required space is greater than the old one.
|
---|
| 247 | */
|
---|
[772] | 248 | template <class T>
|
---|
| 249 | void TArray<T>::Realloc(uint_4 ndim, uint_4 * siz, uint_4 step, bool force)
|
---|
| 250 | {
|
---|
[1099] | 251 | if (arrtype_ != 0) {
|
---|
| 252 | if (ndim != 2)
|
---|
| 253 | throw( ParmError("TArray<T>::Realloc(ndim!=2,...) for Matrix" ) );
|
---|
| 254 | if ((arrtype_ == 2) && (siz[0] > 1) && (siz[1] > 1))
|
---|
| 255 | throw( ParmError("TArray<T>::Realloc(,siz[0]>1 && size[1]>1) for Vector" ) );
|
---|
| 256 | }
|
---|
[772] | 257 | string exmsg = "TArray<T>::Realloc()";
|
---|
| 258 | if (!UpdateSizes(ndim, siz, step, 0, exmsg)) throw( ParmError(exmsg) );
|
---|
| 259 | mNDBlock.ReSize(totsize_);
|
---|
| 260 | }
|
---|
| 261 |
|
---|
[787] | 262 |
|
---|
[894] | 263 | //! Compact dimensions in one or more is equal to 1.
|
---|
[772] | 264 | template <class T>
|
---|
[787] | 265 | TArray<T>& TArray<T>::CompactAllDimensions()
|
---|
[772] | 266 | {
|
---|
[787] | 267 | CompactAllDim();
|
---|
| 268 | return(*this);
|
---|
[772] | 269 | }
|
---|
| 270 |
|
---|
[894] | 271 | //! Compact dimensions if the last one is equal to 1.
|
---|
[785] | 272 | template <class T>
|
---|
[787] | 273 | TArray<T>& TArray<T>::CompactTrailingDimensions()
|
---|
[785] | 274 | {
|
---|
[787] | 275 | CompactTrailingDim();
|
---|
[785] | 276 | return(*this);
|
---|
| 277 | }
|
---|
| 278 |
|
---|
[894] | 279 | //! Give value (in \b double) for element at position \b ip..
|
---|
[785] | 280 | template <class T>
|
---|
[1081] | 281 | MuTyV & TArray<T>::ValueAtPosition(uint_8 ip) const
|
---|
[785] | 282 | {
|
---|
[787] | 283 | #ifdef SO_BOUNDCHECKING
|
---|
| 284 | if (ip >= totsize_) throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") );
|
---|
| 285 | #endif
|
---|
[1081] | 286 | my_mtv = *(mNDBlock.Begin()+Offset(ip));
|
---|
| 287 | return( my_mtv );
|
---|
[785] | 288 | }
|
---|
| 289 |
|
---|
[894] | 290 | //! Return array with elements packed
|
---|
| 291 | /*!
|
---|
| 292 | \param force : if true, pack elements in a new array.
|
---|
| 293 | If false and array is already packed, return
|
---|
| 294 | an array that share data with the current one.
|
---|
| 295 | \return packed array
|
---|
| 296 | */
|
---|
[804] | 297 | template <class T>
|
---|
| 298 | TArray<T> TArray<T>::PackElements(bool force) const
|
---|
| 299 | {
|
---|
| 300 | if (NbDimensions() < 1)
|
---|
| 301 | throw RangeCheckError("TArray<T>::PackElements() - Not Allocated Array ! ");
|
---|
| 302 | if ( !force && (AvgStep() == 1) ) {
|
---|
[970] | 303 | TArray<T> ra;
|
---|
| 304 | ra.Share(*this);
|
---|
[804] | 305 | ra.SetTemp(true);
|
---|
| 306 | return(ra);
|
---|
| 307 | }
|
---|
| 308 | else {
|
---|
| 309 | TArray<T> ra(ndim_, size_, 1);
|
---|
| 310 | ra.CopyElt(*this);
|
---|
| 311 | ra.SetTemp(true);
|
---|
| 312 | return(ra);
|
---|
| 313 | }
|
---|
| 314 | }
|
---|
| 315 |
|
---|
[785] | 316 | // SubArrays
|
---|
[804] | 317 | // $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
|
---|
[894] | 318 | //! Extract a sub-array
|
---|
| 319 | /*!
|
---|
| 320 | \param rx,ry,rz,rt,ru : range of extraction along dimensions
|
---|
| 321 | \sa Range
|
---|
| 322 | */
|
---|
[785] | 323 | template <class T>
|
---|
[804] | 324 | TArray<T> TArray<T>::SubArray(Range rx, Range ry, Range rz, Range rt, Range ru) const
|
---|
[785] | 325 | {
|
---|
[804] | 326 | if (NbDimensions() < 1)
|
---|
| 327 | throw RangeCheckError("TArray<T>::operator () (Range, ...) - Not Allocated Array ! ");
|
---|
[785] | 328 | uint_4 ndim = 0;
|
---|
[787] | 329 | uint_4 size[BASEARRAY_MAXNDIMS];
|
---|
| 330 | uint_4 step[BASEARRAY_MAXNDIMS];
|
---|
| 331 | uint_4 pos[BASEARRAY_MAXNDIMS];
|
---|
[785] | 332 | size[0] = rx.Size();
|
---|
| 333 | size[1] = ry.Size();
|
---|
| 334 | size[2] = rz.Size();
|
---|
| 335 | size[3] = rt.Size();
|
---|
| 336 | size[4] = ru.Size();
|
---|
| 337 |
|
---|
| 338 | step[0] = rx.Step();
|
---|
| 339 | step[1] = ry.Step();
|
---|
| 340 | step[2] = rz.Step();
|
---|
| 341 | step[3] = rt.Step();
|
---|
| 342 | step[4] = ru.Step();
|
---|
| 343 |
|
---|
| 344 | pos[0] = rx.Start();
|
---|
| 345 | pos[1] = ry.Start();
|
---|
| 346 | pos[2] = rz.Start();
|
---|
| 347 | pos[3] = rt.Start();
|
---|
| 348 | pos[4] = ru.Start();
|
---|
| 349 |
|
---|
| 350 | ndim = ndim_;
|
---|
| 351 | TArray<T> ra;
|
---|
[804] | 352 | UpdateSubArraySizes(ra, ndim, size, pos, step);
|
---|
[787] | 353 | ra.DataBlock().Share(this->DataBlock());
|
---|
[785] | 354 | ra.SetTemp(true);
|
---|
| 355 | return(ra);
|
---|
| 356 | }
|
---|
| 357 |
|
---|
[772] | 358 | // ...... Operation de calcul sur les tableaux ......
|
---|
| 359 | // ------- Attention --------
|
---|
| 360 | // Boucles normales prenant en compte les steps ....
|
---|
[894] | 361 | // Possibilite de // , vectorisation
|
---|
| 362 |
|
---|
| 363 | //! Fill TArray with Sequence \b seq
|
---|
| 364 | /*!
|
---|
| 365 | \param seq : sequence to fill the array
|
---|
| 366 | \sa Sequence
|
---|
| 367 | */
|
---|
[772] | 368 | template <class T>
|
---|
[1103] | 369 | TArray<T>& TArray<T>::SetSeq(Sequence const & seq)
|
---|
[772] | 370 | {
|
---|
[804] | 371 | if (NbDimensions() < 1)
|
---|
[813] | 372 | throw RangeCheckError("TArray<T>::SetSeq(Sequence ) - Not Allocated Array ! ");
|
---|
[1103] | 373 |
|
---|
[785] | 374 | T * pe;
|
---|
| 375 | uint_8 j,k;
|
---|
[1103] | 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
|
---|
[785] | 390 | }
|
---|
[772] | 391 | return(*this);
|
---|
| 392 | }
|
---|
| 393 |
|
---|
| 394 | // >>>> Operations avec 2nd membre de type scalaire
|
---|
| 395 |
|
---|
[894] | 396 | //! Fill an array with a constant value \b x
|
---|
[772] | 397 | template <class T>
|
---|
[813] | 398 | TArray<T>& TArray<T>::SetT(T x)
|
---|
[772] | 399 | {
|
---|
[804] | 400 | if (NbDimensions() < 1)
|
---|
[813] | 401 | throw RangeCheckError("TArray<T>::SetT(T ) - Not Allocated Array ! ");
|
---|
[785] | 402 | T * pe;
|
---|
| 403 | uint_8 j,k;
|
---|
| 404 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
| 405 | uint_8 step = AvgStep();
|
---|
| 406 | uint_8 maxx = totsize_*step;
|
---|
| 407 | pe = Data();
|
---|
| 408 | for(k=0; k<maxx; k+=step ) pe[k] = x;
|
---|
| 409 | }
|
---|
| 410 | else { // Non regular data spacing ...
|
---|
| 411 | uint_4 ka = MaxSizeKA();
|
---|
| 412 | uint_8 step = Step(ka);
|
---|
| 413 | uint_8 gpas = Size(ka)*step;
|
---|
[813] | 414 | uint_8 naxa = Size()/Size(ka);
|
---|
| 415 | for(j=0; j<naxa; j++) {
|
---|
| 416 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[785] | 417 | for(k=0; k<gpas; k+=step) pe[k] = x;
|
---|
| 418 | }
|
---|
| 419 | }
|
---|
[772] | 420 | return(*this);
|
---|
| 421 | }
|
---|
| 422 |
|
---|
[894] | 423 | //! Add a constant value \b x to an array
|
---|
[772] | 424 | template <class T>
|
---|
[804] | 425 | TArray<T>& TArray<T>::Add(T x)
|
---|
[772] | 426 | {
|
---|
[804] | 427 | if (NbDimensions() < 1)
|
---|
| 428 | throw RangeCheckError("TArray<T>::Add(T ) - Not Allocated Array ! ");
|
---|
[785] | 429 | T * pe;
|
---|
| 430 | uint_8 j,k;
|
---|
| 431 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
| 432 | uint_8 step = AvgStep();
|
---|
| 433 | uint_8 maxx = totsize_*step;
|
---|
| 434 | pe = Data();
|
---|
| 435 | for(k=0; k<maxx; k+=step ) pe[k] += x;
|
---|
| 436 | }
|
---|
| 437 | else { // Non regular data spacing ...
|
---|
| 438 | uint_4 ka = MaxSizeKA();
|
---|
| 439 | uint_8 step = Step(ka);
|
---|
| 440 | uint_8 gpas = Size(ka)*step;
|
---|
[813] | 441 | uint_8 naxa = Size()/Size(ka);
|
---|
| 442 | for(j=0; j<naxa; j++) {
|
---|
| 443 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[785] | 444 | for(k=0; k<gpas; k+=step) pe[k] += x;
|
---|
| 445 | }
|
---|
| 446 | }
|
---|
[772] | 447 | return(*this);
|
---|
| 448 | }
|
---|
| 449 |
|
---|
[894] | 450 | //! Substract a constant value \b x to an array
|
---|
[970] | 451 | /*!
|
---|
| 452 | Substract a constant from the *this = *this-x
|
---|
| 453 | \param fginv == true : Perfoms the inverse subtraction (*this = x-(*this))
|
---|
| 454 | */
|
---|
[772] | 455 | template <class T>
|
---|
[970] | 456 | TArray<T>& TArray<T>::Sub(T x, bool fginv)
|
---|
[772] | 457 | {
|
---|
[804] | 458 | if (NbDimensions() < 1)
|
---|
| 459 | throw RangeCheckError("TArray<T>::Sub(T ) - Not Allocated Array ! ");
|
---|
[785] | 460 | T * pe;
|
---|
| 461 | uint_8 j,k;
|
---|
| 462 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
| 463 | uint_8 step = AvgStep();
|
---|
| 464 | uint_8 maxx = totsize_*step;
|
---|
| 465 | pe = Data();
|
---|
[970] | 466 | if (fginv)
|
---|
| 467 | for(k=0; k<maxx; k+=step ) pe[k] = x-pe[k];
|
---|
| 468 | else
|
---|
| 469 | for(k=0; k<maxx; k+=step ) pe[k] -= x;
|
---|
[785] | 470 | }
|
---|
| 471 | else { // Non regular data spacing ...
|
---|
| 472 | uint_4 ka = MaxSizeKA();
|
---|
| 473 | uint_8 step = Step(ka);
|
---|
| 474 | uint_8 gpas = Size(ka)*step;
|
---|
[813] | 475 | uint_8 naxa = Size()/Size(ka);
|
---|
| 476 | for(j=0; j<naxa; j++) {
|
---|
| 477 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[970] | 478 | if (fginv)
|
---|
| 479 | for(k=0; k<gpas; k+=step) pe[k] = x-pe[k];
|
---|
| 480 | else
|
---|
| 481 | for(k=0; k<gpas; k+=step) pe[k] -= x;
|
---|
[785] | 482 | }
|
---|
| 483 | }
|
---|
[772] | 484 | return(*this);
|
---|
| 485 | }
|
---|
| 486 |
|
---|
[894] | 487 | //! Multiply an array by a constant value \b x
|
---|
[772] | 488 | template <class T>
|
---|
[804] | 489 | TArray<T>& TArray<T>::Mul(T x)
|
---|
[772] | 490 | {
|
---|
[804] | 491 | if (NbDimensions() < 1)
|
---|
| 492 | throw RangeCheckError("TArray<T>::Mul(T ) - Not Allocated Array ! ");
|
---|
[785] | 493 | T * pe;
|
---|
| 494 | uint_8 j,k;
|
---|
| 495 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
| 496 | uint_8 step = AvgStep();
|
---|
| 497 | uint_8 maxx = totsize_*step;
|
---|
| 498 | pe = Data();
|
---|
| 499 | for(k=0; k<maxx; k+=step ) pe[k] *= x;
|
---|
| 500 | }
|
---|
| 501 | else { // Non regular data spacing ...
|
---|
| 502 | uint_4 ka = MaxSizeKA();
|
---|
| 503 | uint_8 step = Step(ka);
|
---|
| 504 | uint_8 gpas = Size(ka)*step;
|
---|
[813] | 505 | uint_8 naxa = Size()/Size(ka);
|
---|
| 506 | for(j=0; j<naxa; j++) {
|
---|
| 507 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[785] | 508 | for(k=0; k<gpas; k+=step) pe[k] *= x;
|
---|
| 509 | }
|
---|
| 510 | }
|
---|
[772] | 511 | return(*this);
|
---|
| 512 | }
|
---|
| 513 |
|
---|
[894] | 514 | //! Divide an array by a constant value \b x
|
---|
[970] | 515 | /*!
|
---|
| 516 | Divide the array by a constant *this = *this/x
|
---|
| 517 | \param fginv == true : Perfoms the inverse division (*this = x/(*this))
|
---|
| 518 | */
|
---|
[772] | 519 | template <class T>
|
---|
[970] | 520 | TArray<T>& TArray<T>::Div(T x, bool fginv)
|
---|
[772] | 521 | {
|
---|
[804] | 522 | if (NbDimensions() < 1)
|
---|
| 523 | throw RangeCheckError("TArray<T>::Div(T ) - Not Allocated Array ! ");
|
---|
[970] | 524 | if (!fginv && (x == (T) 0) )
|
---|
[894] | 525 | throw MathExc("TArray<T>::Div(T ) - Divide by zero ! ");
|
---|
[785] | 526 | T * pe;
|
---|
| 527 | uint_8 j,k;
|
---|
| 528 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
| 529 | uint_8 step = AvgStep();
|
---|
| 530 | uint_8 maxx = totsize_*step;
|
---|
| 531 | pe = Data();
|
---|
[970] | 532 | if (fginv)
|
---|
| 533 | for(k=0; k<maxx; k+=step ) pe[k] = x/pe[k];
|
---|
| 534 | else
|
---|
| 535 | for(k=0; k<maxx; k+=step ) pe[k] /= x;
|
---|
[785] | 536 | }
|
---|
| 537 | else { // Non regular data spacing ...
|
---|
| 538 | uint_4 ka = MaxSizeKA();
|
---|
| 539 | uint_8 step = Step(ka);
|
---|
| 540 | uint_8 gpas = Size(ka)*step;
|
---|
[813] | 541 | uint_8 naxa = Size()/Size(ka);
|
---|
| 542 | for(j=0; j<naxa; j++) {
|
---|
| 543 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[970] | 544 | if (fginv)
|
---|
| 545 | for(k=0; k<gpas; k+=step) pe[k] = x/pe[k];
|
---|
| 546 | else
|
---|
| 547 | for(k=0; k<gpas; k+=step) pe[k] /= x;
|
---|
[785] | 548 | }
|
---|
| 549 | }
|
---|
[772] | 550 | return(*this);
|
---|
| 551 | }
|
---|
| 552 |
|
---|
| 553 |
|
---|
[804] | 554 |
|
---|
| 555 |
|
---|
[772] | 556 | // >>>> Operations avec 2nd membre de type tableau
|
---|
[894] | 557 | //! Add two TArrays
|
---|
[772] | 558 | template <class T>
|
---|
[804] | 559 | TArray<T>& TArray<T>::AddElt(const TArray<T>& a)
|
---|
[772] | 560 | {
|
---|
[804] | 561 | if (NbDimensions() < 1)
|
---|
| 562 | throw RangeCheckError("TArray<T>::AddElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 563 | bool smo;
|
---|
| 564 | if (!CompareSizes(a, smo))
|
---|
[813] | 565 | throw(SzMismatchError("TArray<T>::AddElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[785] | 566 |
|
---|
| 567 | T * pe;
|
---|
| 568 | const T * pea;
|
---|
| 569 | uint_8 j,k,ka;
|
---|
[1099] | 570 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0)) { // regularly spaced elements
|
---|
[785] | 571 | uint_8 step = AvgStep();
|
---|
| 572 | uint_8 stepa = a.AvgStep();
|
---|
| 573 | uint_8 maxx = totsize_*step;
|
---|
| 574 | pe = Data();
|
---|
| 575 | pea = a.Data();
|
---|
| 576 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] += pea[ka] ;
|
---|
[772] | 577 | }
|
---|
[785] | 578 | else { // Non regular data spacing ...
|
---|
[1099] | 579 | int ax,axa;
|
---|
| 580 | uint_8 step, stepa;
|
---|
| 581 | uint_8 gpas, naxa;
|
---|
| 582 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 583 | for(j=0; j<naxa; j++) {
|
---|
| 584 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 585 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[785] | 586 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] += pea[ka];
|
---|
| 587 | }
|
---|
| 588 | }
|
---|
[772] | 589 | return(*this);
|
---|
| 590 | }
|
---|
| 591 |
|
---|
[894] | 592 | //! Substract two TArrays
|
---|
[970] | 593 | /*!
|
---|
| 594 | Substract two TArrays *this = *this-a
|
---|
| 595 | \param fginv == true : Perfoms the inverse subtraction (*this = a-(*this))
|
---|
| 596 | */
|
---|
[772] | 597 | template <class T>
|
---|
[970] | 598 | TArray<T>& TArray<T>::SubElt(const TArray<T>& a, bool fginv)
|
---|
[772] | 599 | {
|
---|
[804] | 600 | if (NbDimensions() < 1)
|
---|
| 601 | throw RangeCheckError("TArray<T>::SubElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 602 | bool smo;
|
---|
| 603 | if (!CompareSizes(a, smo))
|
---|
[813] | 604 | throw(SzMismatchError("TArray<T>::SubElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[785] | 605 |
|
---|
| 606 | T * pe;
|
---|
| 607 | const T * pea;
|
---|
| 608 | uint_8 j,k,ka;
|
---|
[1099] | 609 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0) ) { // regularly spaced elements
|
---|
[785] | 610 | uint_8 step = AvgStep();
|
---|
| 611 | uint_8 stepa = a.AvgStep();
|
---|
| 612 | uint_8 maxx = totsize_*step;
|
---|
| 613 | pe = Data();
|
---|
| 614 | pea = a.Data();
|
---|
[970] | 615 | if (fginv)
|
---|
| 616 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] = pea[ka]-pe[k] ;
|
---|
| 617 | else
|
---|
| 618 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] -= pea[ka] ;
|
---|
[772] | 619 | }
|
---|
[785] | 620 | else { // Non regular data spacing ...
|
---|
[1099] | 621 | int ax,axa;
|
---|
| 622 | uint_8 step, stepa;
|
---|
| 623 | uint_8 gpas, naxa;
|
---|
| 624 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 625 | for(j=0; j<naxa; j++) {
|
---|
| 626 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 627 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[970] | 628 | if (fginv)
|
---|
| 629 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka]-pe[k] ;
|
---|
| 630 | else
|
---|
| 631 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] -= pea[ka];
|
---|
[785] | 632 | }
|
---|
| 633 | }
|
---|
[772] | 634 | return(*this);
|
---|
| 635 | }
|
---|
| 636 |
|
---|
[970] | 637 |
|
---|
[894] | 638 | //! Multiply two TArrays (elements by elements)
|
---|
[772] | 639 | template <class T>
|
---|
[804] | 640 | TArray<T>& TArray<T>::MulElt(const TArray<T>& a)
|
---|
[772] | 641 | {
|
---|
[804] | 642 | if (NbDimensions() < 1)
|
---|
| 643 | throw RangeCheckError("TArray<T>::MulElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 644 | bool smo;
|
---|
| 645 | if (!CompareSizes(a, smo))
|
---|
[813] | 646 | throw(SzMismatchError("TArray<T>::MulElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[785] | 647 |
|
---|
| 648 | T * pe;
|
---|
| 649 | const T * pea;
|
---|
| 650 | uint_8 j,k,ka;
|
---|
[1099] | 651 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0) ) { // regularly spaced elements
|
---|
[785] | 652 | uint_8 step = AvgStep();
|
---|
| 653 | uint_8 stepa = a.AvgStep();
|
---|
| 654 | uint_8 maxx = totsize_*step;
|
---|
| 655 | pe = Data();
|
---|
| 656 | pea = a.Data();
|
---|
| 657 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] *= pea[ka] ;
|
---|
[772] | 658 | }
|
---|
[785] | 659 | else { // Non regular data spacing ...
|
---|
[1099] | 660 | int ax,axa;
|
---|
| 661 | uint_8 step, stepa;
|
---|
| 662 | uint_8 gpas, naxa;
|
---|
| 663 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 664 | for(j=0; j<naxa; j++) {
|
---|
[1099] | 665 | pe = mNDBlock.Begin()+Offset(axa,j);
|
---|
| 666 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[785] | 667 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] *= pea[ka];
|
---|
| 668 | }
|
---|
| 669 | }
|
---|
[772] | 670 | return(*this);
|
---|
| 671 | }
|
---|
| 672 |
|
---|
[804] | 673 |
|
---|
[894] | 674 | //! Divide two TArrays (elements by elements)
|
---|
[970] | 675 | /*!
|
---|
| 676 | Divide two TArrays *this = (*this)/a
|
---|
| 677 | \param fginv == true : Perfoms the inverse division (*this = a/(*this))
|
---|
[1072] | 678 | \param divzero == true : if a(i)==0. result is set to zero: (*this)(i)==0.
|
---|
[970] | 679 | */
|
---|
[772] | 680 | template <class T>
|
---|
[1072] | 681 | TArray<T>& TArray<T>::DivElt(const TArray<T>& a, bool fginv, bool divzero)
|
---|
[772] | 682 | {
|
---|
[804] | 683 | if (NbDimensions() < 1)
|
---|
| 684 | throw RangeCheckError("TArray<T>::DivElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 685 | bool smo;
|
---|
| 686 | if (!CompareSizes(a, smo))
|
---|
[813] | 687 | throw(SzMismatchError("TArray<T>::DivElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[785] | 688 |
|
---|
| 689 | T * pe;
|
---|
| 690 | const T * pea;
|
---|
| 691 | uint_8 j,k,ka;
|
---|
[1099] | 692 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0) ) { // regularly spaced elements
|
---|
[785] | 693 | uint_8 step = AvgStep();
|
---|
| 694 | uint_8 stepa = a.AvgStep();
|
---|
| 695 | uint_8 maxx = totsize_*step;
|
---|
| 696 | pe = Data();
|
---|
| 697 | pea = a.Data();
|
---|
[1072] | 698 | if(divzero) {
|
---|
| 699 | if (fginv)
|
---|
| 700 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa )
|
---|
| 701 | {if(pe[k]==(T)0) pe[k] = (T)0; else pe[k] = pea[ka]/pe[k];}
|
---|
| 702 | else
|
---|
| 703 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa )
|
---|
| 704 | {if(pea[k]==(T)0) pe[k] = (T)0; else pe[k] /= pea[ka] ;}
|
---|
| 705 | } else {
|
---|
| 706 | if (fginv)
|
---|
| 707 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] = pea[ka]/pe[k];
|
---|
| 708 | else
|
---|
| 709 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] /= pea[ka] ;
|
---|
| 710 | }
|
---|
[772] | 711 | }
|
---|
[785] | 712 | else { // Non regular data spacing ...
|
---|
[1099] | 713 | int ax,axa;
|
---|
| 714 | uint_8 step, stepa;
|
---|
| 715 | uint_8 gpas, naxa;
|
---|
| 716 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 717 | for(j=0; j<naxa; j++) {
|
---|
| 718 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 719 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[1072] | 720 | if(divzero) {
|
---|
| 721 | if (fginv)
|
---|
| 722 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa)
|
---|
| 723 | {if(pe[k]==(T)0) pe[k] = (T)0; else pe[k] = pea[ka]/pe[k];}
|
---|
| 724 | else
|
---|
| 725 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa)
|
---|
| 726 | {if(pea[k]==(T)0) pe[k] = (T)0; else pe[k] /= pea[ka];}
|
---|
| 727 | } else {
|
---|
| 728 | if (fginv)
|
---|
| 729 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka]/pe[k];
|
---|
| 730 | else
|
---|
| 731 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] /= pea[ka];
|
---|
| 732 | }
|
---|
[785] | 733 | }
|
---|
| 734 | }
|
---|
[772] | 735 | return(*this);
|
---|
| 736 | }
|
---|
| 737 |
|
---|
[894] | 738 | //! Copy elements of \b a
|
---|
[804] | 739 | template <class T>
|
---|
| 740 | TArray<T>& TArray<T>::CopyElt(const TArray<T>& a)
|
---|
| 741 | {
|
---|
| 742 | if (NbDimensions() < 1)
|
---|
| 743 | throw RangeCheckError("TArray<T>::CopyElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 744 | bool smo;
|
---|
| 745 | if (!CompareSizes(a, smo))
|
---|
[1050] | 746 | throw(SzMismatchError("TArray<T>::CopyElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[772] | 747 |
|
---|
[804] | 748 | T * pe;
|
---|
| 749 | const T * pea;
|
---|
| 750 | uint_8 j,k,ka;
|
---|
[1099] | 751 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0) ) { // regularly spaced elements
|
---|
[804] | 752 | uint_8 step = AvgStep();
|
---|
| 753 | uint_8 stepa = a.AvgStep();
|
---|
| 754 | uint_8 maxx = totsize_*step;
|
---|
| 755 | pe = Data();
|
---|
| 756 | pea = a.Data();
|
---|
| 757 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] = pea[ka] ;
|
---|
| 758 | }
|
---|
| 759 | else { // Non regular data spacing ...
|
---|
[1099] | 760 | int ax,axa;
|
---|
| 761 | uint_8 step, stepa;
|
---|
| 762 | uint_8 gpas, naxa;
|
---|
| 763 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 764 | for(j=0; j<naxa; j++) {
|
---|
| 765 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 766 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[804] | 767 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka];
|
---|
| 768 | }
|
---|
| 769 | }
|
---|
| 770 | return(*this);
|
---|
| 771 | }
|
---|
| 772 |
|
---|
[1081] | 773 | //! Converts and Copy elements of \b a
|
---|
| 774 | template <class T>
|
---|
| 775 | TArray<T>& TArray<T>::ConvertAndCopyElt(const BaseArray& a)
|
---|
| 776 | {
|
---|
| 777 | if (NbDimensions() < 1)
|
---|
| 778 | throw RangeCheckError("TArray<T>::ConvertAndCopyElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 779 | bool smo;
|
---|
| 780 | if (!CompareSizes(a, smo))
|
---|
[1081] | 781 | throw(SzMismatchError("TArray<T>::ConvertAndCopyElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[804] | 782 |
|
---|
[1081] | 783 | T * pe;
|
---|
| 784 | uint_8 j,k,ka;
|
---|
| 785 | uint_8 offa;
|
---|
| 786 | // Non regular data spacing ...
|
---|
[1099] | 787 | int ax,axa;
|
---|
| 788 | uint_8 step, stepa;
|
---|
| 789 | uint_8 gpas, naxa;
|
---|
| 790 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[1081] | 791 | for(j=0; j<naxa; j++) {
|
---|
| 792 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 793 | offa = a.Offset(axa,j);
|
---|
[1085] | 794 | #if !defined(__GNUG__)
|
---|
| 795 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = (T)a.ValueAtPosition(offa+ka);
|
---|
| 796 | #else
|
---|
| 797 | // g++ (up to 2.95.1) se melange les pinceaux s'il y a le cast (T) pour l'instanciation des complexes
|
---|
[1081] | 798 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = a.ValueAtPosition(offa+ka);
|
---|
[1085] | 799 | #endif
|
---|
[1081] | 800 | }
|
---|
| 801 | return(*this);
|
---|
| 802 | }
|
---|
| 803 |
|
---|
| 804 |
|
---|
[804] | 805 | // Somme et produit des elements
|
---|
[894] | 806 | //! Sum all elements
|
---|
[804] | 807 | template <class T>
|
---|
| 808 | T TArray<T>::Sum() const
|
---|
| 809 | {
|
---|
| 810 | if (NbDimensions() < 1)
|
---|
| 811 | throw RangeCheckError("TArray<T>::Sum() - Not Allocated Array ! ");
|
---|
| 812 | T ret=0;
|
---|
| 813 | const T * pe;
|
---|
| 814 | uint_8 j,k;
|
---|
| 815 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
| 816 | uint_8 step = AvgStep();
|
---|
| 817 | uint_8 maxx = totsize_*step;
|
---|
| 818 | pe = Data();
|
---|
| 819 | for(k=0; k<maxx; k+=step ) ret += pe[k];
|
---|
| 820 | }
|
---|
| 821 | else { // Non regular data spacing ...
|
---|
| 822 | uint_4 ka = MaxSizeKA();
|
---|
| 823 | uint_8 step = Step(ka);
|
---|
| 824 | uint_8 gpas = Size(ka)*step;
|
---|
[813] | 825 | uint_8 naxa = Size()/Size(ka);
|
---|
| 826 | for(j=0; j<naxa; j++) {
|
---|
| 827 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[804] | 828 | for(k=0; k<gpas; k+=step) ret += pe[k] ;
|
---|
| 829 | }
|
---|
| 830 | }
|
---|
| 831 | return ret;
|
---|
| 832 | }
|
---|
| 833 |
|
---|
[894] | 834 | //! Multiply all elements
|
---|
[804] | 835 | template <class T>
|
---|
| 836 | T TArray<T>::Product() const
|
---|
| 837 | {
|
---|
| 838 | if (NbDimensions() < 1)
|
---|
| 839 | throw RangeCheckError("TArray<T>::Product() - Not Allocated Array ! ");
|
---|
| 840 | T ret=0;
|
---|
| 841 | const T * pe;
|
---|
| 842 | uint_8 j,k;
|
---|
| 843 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
| 844 | uint_8 step = AvgStep();
|
---|
| 845 | uint_8 maxx = totsize_*step;
|
---|
| 846 | pe = Data();
|
---|
| 847 | for(k=0; k<maxx; k+=step ) ret *= pe[k];
|
---|
| 848 | }
|
---|
| 849 | else { // Non regular data spacing ...
|
---|
| 850 | uint_4 ka = MaxSizeKA();
|
---|
| 851 | uint_8 step = Step(ka);
|
---|
| 852 | uint_8 gpas = Size(ka)*step;
|
---|
[813] | 853 | uint_8 naxa = Size()/Size(ka);
|
---|
| 854 | for(j=0; j<naxa; j++) {
|
---|
| 855 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[804] | 856 | for(k=0; k<gpas; k+=step) ret *= pe[k] ;
|
---|
| 857 | }
|
---|
| 858 | }
|
---|
| 859 | return ret;
|
---|
| 860 | }
|
---|
| 861 |
|
---|
| 862 |
|
---|
| 863 |
|
---|
[772] | 864 | // ----------------------------------------------------
|
---|
| 865 | // Impression, etc ...
|
---|
| 866 | // ----------------------------------------------------
|
---|
| 867 |
|
---|
[894] | 868 | //! Return a string that contain the type \b T of the array
|
---|
[772] | 869 | template <class T>
|
---|
[813] | 870 | string TArray<T>::InfoString() const
|
---|
[772] | 871 | {
|
---|
[813] | 872 | string rs = "TArray<" ;
|
---|
| 873 | rs += typeid(T).name();
|
---|
| 874 | rs += "> ";
|
---|
[787] | 875 | return(rs);
|
---|
[772] | 876 | }
|
---|
| 877 |
|
---|
[894] | 878 | //! Print array
|
---|
| 879 | /*!
|
---|
| 880 | \param os : output stream
|
---|
| 881 | \param maxprt : maximum numer of print
|
---|
| 882 | \param si : if true, display attached DvList
|
---|
| 883 | \sa SetMaxPrint
|
---|
| 884 | */
|
---|
[772] | 885 | template <class T>
|
---|
| 886 | void TArray<T>::Print(ostream& os, int_4 maxprt, bool si) const
|
---|
| 887 | {
|
---|
| 888 | if (maxprt < 0) maxprt = max_nprt_;
|
---|
[958] | 889 | uint_4 npr = 0;
|
---|
[772] | 890 | Show(os, si);
|
---|
[850] | 891 | if (ndim_ < 1) return;
|
---|
[804] | 892 | uint_4 k0,k1,k2,k3,k4;
|
---|
[772] | 893 | for(k4=0; k4<size_[4]; k4++) {
|
---|
[785] | 894 | if (size_[4] > 1) cout << "\n ----- Dimension 5 (U) K4= " << k4 << endl;
|
---|
[772] | 895 | for(k3=0; k3<size_[3]; k3++) {
|
---|
[785] | 896 | if (size_[3] > 1) cout << "\n ----- Dimension 4 (T) K3= " << k3 << endl;
|
---|
[772] | 897 | for(k2=0; k2<size_[2]; k2++) {
|
---|
[785] | 898 | if (size_[2] > 1) cout << "\n ----- Dimension 3 (Z) K2= " << k2 << endl;
|
---|
[772] | 899 | for(k1=0; k1<size_[1]; k1++) {
|
---|
[785] | 900 | if ( (size_[1] > 1) && (size_[0] > 10) ) cout << "----- Dimension 2 (Y) K1= " << k1 << endl;
|
---|
[772] | 901 | for(k0=0; k0<size_[0]; k0++) {
|
---|
[785] | 902 | if(k0 > 0) os << ", ";
|
---|
| 903 | os << Elem(k0, k1, k2, k3, k4); npr++;
|
---|
[958] | 904 | if (npr >= (uint_4) maxprt) {
|
---|
[772] | 905 | if (npr < totsize_) os << "\n .... " << endl; return;
|
---|
| 906 | }
|
---|
| 907 | }
|
---|
| 908 | os << endl;
|
---|
| 909 | }
|
---|
| 910 | }
|
---|
| 911 | }
|
---|
| 912 | }
|
---|
[813] | 913 | os << endl;
|
---|
[772] | 914 | }
|
---|
| 915 |
|
---|
| 916 |
|
---|
| 917 |
|
---|
| 918 | ///////////////////////////////////////////////////////////////
|
---|
| 919 | ///////////////////////////////////////////////////////////////
|
---|
| 920 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
[804] | 921 | /*
|
---|
[772] | 922 | #pragma define_template TArray<uint_1>
|
---|
[804] | 923 | #pragma define_template TArray<int_2>
|
---|
| 924 | #pragma define_template TArray<uint_4>
|
---|
| 925 | #pragma define_template TArray<uint_8>
|
---|
| 926 | */
|
---|
[772] | 927 | #pragma define_template TArray<uint_2>
|
---|
| 928 | #pragma define_template TArray<int_4>
|
---|
| 929 | #pragma define_template TArray<int_8>
|
---|
| 930 | #pragma define_template TArray<r_4>
|
---|
| 931 | #pragma define_template TArray<r_8>
|
---|
| 932 | #pragma define_template TArray< complex<r_4> >
|
---|
| 933 | #pragma define_template TArray< complex<r_8> >
|
---|
| 934 | #endif
|
---|
| 935 |
|
---|
| 936 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
[804] | 937 | /*
|
---|
| 938 | template class TArray<uint_1>;
|
---|
| 939 | template class TArray<int_2>;
|
---|
| 940 | template class TArray<uint_4>;
|
---|
| 941 | template class TArray<uint_8>;
|
---|
| 942 | */
|
---|
[772] | 943 | template class TArray<uint_2>;
|
---|
| 944 | template class TArray<int_4>;
|
---|
| 945 | template class TArray<int_8>;
|
---|
| 946 | template class TArray<r_4>;
|
---|
| 947 | template class TArray<r_8>;
|
---|
| 948 | template class TArray< complex<r_4> >;
|
---|
| 949 | template class TArray< complex<r_8> >;
|
---|
| 950 | #endif
|
---|
| 951 |
|
---|
| 952 |
|
---|