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