[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>
|
---|
[1156] | 41 | TArray<T>::TArray(int_4 ndim, const sa_size_t * siz, sa_size_t step)
|
---|
[804] | 42 | : BaseArray() , mNDBlock(ComputeTotalSize(ndim, siz, step, 1))
|
---|
[772] | 43 | {
|
---|
[1156] | 44 | string exmsg = "TArray<T>::TArray(int_4, sa_size_t *, sa_size_t)";
|
---|
[772] | 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>
|
---|
[1156] | 53 | TArray<T>::TArray(sa_size_t nx, sa_size_t ny, sa_size_t nz, sa_size_t nt, sa_size_t nu)
|
---|
[804] | 54 | : BaseArray() , mNDBlock(nx*((ny>0)?ny:1)*((nz>0)?nz:1)*((nt>0)?nt:1)*((nu>0)?nu:1))
|
---|
[772] | 55 | {
|
---|
[1156] | 56 | sa_size_t size[BASEARRAY_MAXNDIMS];
|
---|
[772] | 57 | size[0] = nx; size[1] = ny; size[2] = nz;
|
---|
[804] | 58 | size[3] = nt; size[4] = nu;
|
---|
[1156] | 59 | int_4 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;
|
---|
[1156] | 65 | string exmsg = "TArray<T>::TArray(sa_size_t, sa_size_t, sa_size_t, sa_size_t, sa_size_t)";
|
---|
[772] | 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>
|
---|
[1156] | 79 | TArray<T>::TArray(int_4 ndim, const sa_size_t * siz, NDataBlock<T> & db, bool share, sa_size_t step, sa_size_t offset)
|
---|
[804] | 80 | : BaseArray() , mNDBlock(db, share)
|
---|
[772] | 81 | {
|
---|
[1156] | 82 | string exmsg = "TArray<T>::TArray(int_4, sa_size_t *, NDataBlock<T> & ... )";
|
---|
[772] | 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>
|
---|
[1156] | 99 | TArray<T>::TArray(int_4 ndim, const sa_size_t * siz, T* values, sa_size_t step, sa_size_t offset, Bridge* br)
|
---|
[804] | 100 | : BaseArray() , mNDBlock(ComputeTotalSize(ndim, siz, step, 1), values, br)
|
---|
[772] | 101 | {
|
---|
[1156] | 102 | string exmsg = "TArray<T>::TArray(int_4, sa_size_t *, T* ... )";
|
---|
[772] | 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 | /*!
|
---|
[1364] | 155 | If the array is already allocated, CopyElt() is called
|
---|
| 156 | for checking that the two arrays have the same size and
|
---|
| 157 | for copying the array element values. For non allocated
|
---|
| 158 | arrays, CloneOrShare() is called. The array memory
|
---|
| 159 | organization is also copied from \b a.
|
---|
[976] | 160 | \warning Datas are copied (cloned) from \b a.
|
---|
[1364] | 161 | \sa CopyElt
|
---|
| 162 | \sa CloneOrShare
|
---|
[976] | 163 | \sa NDataBlock::operator=(const NDataBlock<T>&)
|
---|
| 164 | */
|
---|
[772] | 165 | template <class T>
|
---|
[804] | 166 | TArray<T>& TArray<T>::Set(const TArray<T>& a)
|
---|
[772] | 167 | {
|
---|
[970] | 168 | if (this == &a) return(*this);
|
---|
| 169 | if (a.NbDimensions() < 1)
|
---|
| 170 | throw RangeCheckError("TArray<T>::Set(a ) - Array a not allocated ! ");
|
---|
| 171 | if (NbDimensions() < 1) CloneOrShare(a);
|
---|
| 172 | else CopyElt(a);
|
---|
[772] | 173 | return(*this);
|
---|
| 174 | }
|
---|
| 175 |
|
---|
[1081] | 176 | //! Set array elements equal to the \b a array elements, after conversion
|
---|
| 177 | template <class T>
|
---|
| 178 | TArray<T>& TArray<T>::SetBA(const BaseArray& a)
|
---|
| 179 | {
|
---|
| 180 | if (this == &a) return(*this);
|
---|
| 181 | if (a.NbDimensions() < 1)
|
---|
| 182 | throw RangeCheckError("TArray<T>::SetBA(a ) - Array a not allocated ! ");
|
---|
| 183 | if (NbDimensions() < 1) {
|
---|
| 184 | string exmsg = "TArray<T>::SetBA(const BaseArray& a)";
|
---|
| 185 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
| 186 | mNDBlock.ReSize(totsize_);
|
---|
| 187 | }
|
---|
| 188 | ConvertAndCopyElt(a);
|
---|
| 189 | return(*this);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
[894] | 192 | //! Clone array \b a
|
---|
[772] | 193 | template <class T>
|
---|
| 194 | void TArray<T>::Clone(const TArray<T>& a)
|
---|
| 195 | {
|
---|
| 196 | string exmsg = "TArray<T>::Clone()";
|
---|
| 197 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
| 198 | mNDBlock.Clone(a.mNDBlock);
|
---|
[894] | 199 | if (mInfo) {delete mInfo; mInfo = NULL;}
|
---|
[772] | 200 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[970] | 203 | //! Clone if \b a is not temporary, share if temporary
|
---|
[976] | 204 | /*! \sa NDataBlock::CloneOrShare(const NDataBlock<T>&) */
|
---|
[970] | 205 | template <class T>
|
---|
| 206 | void TArray<T>::CloneOrShare(const TArray<T>& a)
|
---|
| 207 | {
|
---|
| 208 | string exmsg = "TArray<T>::CloneOrShare()";
|
---|
[1103] | 209 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
[970] | 210 | mNDBlock.CloneOrShare(a.mNDBlock);
|
---|
[1103] | 211 | if (mInfo) {delete mInfo; mInfo = NULL;}
|
---|
| 212 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
[970] | 213 | }
|
---|
| 214 |
|
---|
| 215 | //! Share data with a
|
---|
| 216 | template <class T>
|
---|
| 217 | void TArray<T>::Share(const TArray<T>& a)
|
---|
| 218 | {
|
---|
| 219 | string exmsg = "TArray<T>::Share()";
|
---|
[1103] | 220 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
[970] | 221 | mNDBlock.Share(a.mNDBlock);
|
---|
[1103] | 222 | if (mInfo) {delete mInfo; mInfo = NULL;}
|
---|
| 223 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
[970] | 224 | }
|
---|
| 225 |
|
---|
| 226 |
|
---|
[894] | 227 | //! Resize array
|
---|
| 228 | /*!
|
---|
| 229 | \param ndim : number of dimensions
|
---|
| 230 | \param siz[ndim] : size along each dimension
|
---|
| 231 | \param step : step (same for all dimensions)
|
---|
| 232 | */
|
---|
[772] | 233 | template <class T>
|
---|
[1156] | 234 | void TArray<T>::ReSize(int_4 ndim, sa_size_t * siz, sa_size_t step)
|
---|
[772] | 235 | {
|
---|
[1099] | 236 | if (arrtype_ != 0) {
|
---|
| 237 | if (ndim != 2)
|
---|
| 238 | throw( ParmError("TArray<T>::ReSize(ndim!=2,...) for Matrix" ) );
|
---|
| 239 | if ((arrtype_ == 2) && (siz[0] > 1) && (siz[1] > 1))
|
---|
| 240 | throw( ParmError("TArray<T>::ReSize(,siz[0]>1 && size[1]>1) for Vector" ) );
|
---|
| 241 | }
|
---|
[772] | 242 | string exmsg = "TArray<T>::ReSize()";
|
---|
| 243 | if (!UpdateSizes(ndim, siz, step, 0, exmsg)) throw( ParmError(exmsg) );
|
---|
| 244 | mNDBlock.ReSize(totsize_);
|
---|
| 245 | }
|
---|
| 246 |
|
---|
[894] | 247 | //! Re-allocate space for array
|
---|
| 248 | /*!
|
---|
| 249 | \param ndim : number of dimensions
|
---|
| 250 | \param siz[ndim] : size along each dimension
|
---|
| 251 | \param step : step (same for all dimensions)
|
---|
| 252 | \param force : if true re-allocation is forced, if not it occurs
|
---|
| 253 | only if the required space is greater than the old one.
|
---|
| 254 | */
|
---|
[772] | 255 | template <class T>
|
---|
[1156] | 256 | void TArray<T>::Realloc(int_4 ndim, sa_size_t * siz, sa_size_t step, bool force)
|
---|
[772] | 257 | {
|
---|
[1099] | 258 | if (arrtype_ != 0) {
|
---|
| 259 | if (ndim != 2)
|
---|
| 260 | throw( ParmError("TArray<T>::Realloc(ndim!=2,...) for Matrix" ) );
|
---|
| 261 | if ((arrtype_ == 2) && (siz[0] > 1) && (siz[1] > 1))
|
---|
| 262 | throw( ParmError("TArray<T>::Realloc(,siz[0]>1 && size[1]>1) for Vector" ) );
|
---|
| 263 | }
|
---|
[772] | 264 | string exmsg = "TArray<T>::Realloc()";
|
---|
| 265 | if (!UpdateSizes(ndim, siz, step, 0, exmsg)) throw( ParmError(exmsg) );
|
---|
| 266 | mNDBlock.ReSize(totsize_);
|
---|
| 267 | }
|
---|
| 268 |
|
---|
[787] | 269 |
|
---|
[894] | 270 | //! Compact dimensions in one or more is equal to 1.
|
---|
[772] | 271 | template <class T>
|
---|
[787] | 272 | TArray<T>& TArray<T>::CompactAllDimensions()
|
---|
[772] | 273 | {
|
---|
[787] | 274 | CompactAllDim();
|
---|
| 275 | return(*this);
|
---|
[772] | 276 | }
|
---|
| 277 |
|
---|
[894] | 278 | //! Compact dimensions if the last one is equal to 1.
|
---|
[785] | 279 | template <class T>
|
---|
[787] | 280 | TArray<T>& TArray<T>::CompactTrailingDimensions()
|
---|
[785] | 281 | {
|
---|
[787] | 282 | CompactTrailingDim();
|
---|
[785] | 283 | return(*this);
|
---|
| 284 | }
|
---|
| 285 |
|
---|
[894] | 286 | //! Give value (in \b double) for element at position \b ip..
|
---|
[785] | 287 | template <class T>
|
---|
[1156] | 288 | MuTyV & TArray<T>::ValueAtPosition(sa_size_t ip) const
|
---|
[785] | 289 | {
|
---|
[787] | 290 | #ifdef SO_BOUNDCHECKING
|
---|
[1156] | 291 | if (ip >= totsize_) throw( ParmError("TArray<T>::ValueAtPosition(sa_size_t ip) Out-of-bound Error") );
|
---|
[787] | 292 | #endif
|
---|
[1081] | 293 | my_mtv = *(mNDBlock.Begin()+Offset(ip));
|
---|
| 294 | return( my_mtv );
|
---|
[785] | 295 | }
|
---|
| 296 |
|
---|
[894] | 297 | //! Return array with elements packed
|
---|
| 298 | /*!
|
---|
| 299 | \param force : if true, pack elements in a new array.
|
---|
| 300 | If false and array is already packed, return
|
---|
| 301 | an array that share data with the current one.
|
---|
| 302 | \return packed array
|
---|
| 303 | */
|
---|
[804] | 304 | template <class T>
|
---|
| 305 | TArray<T> TArray<T>::PackElements(bool force) const
|
---|
| 306 | {
|
---|
| 307 | if (NbDimensions() < 1)
|
---|
| 308 | throw RangeCheckError("TArray<T>::PackElements() - Not Allocated Array ! ");
|
---|
| 309 | if ( !force && (AvgStep() == 1) ) {
|
---|
[970] | 310 | TArray<T> ra;
|
---|
| 311 | ra.Share(*this);
|
---|
[804] | 312 | ra.SetTemp(true);
|
---|
| 313 | return(ra);
|
---|
| 314 | }
|
---|
| 315 | else {
|
---|
| 316 | TArray<T> ra(ndim_, size_, 1);
|
---|
| 317 | ra.CopyElt(*this);
|
---|
| 318 | ra.SetTemp(true);
|
---|
| 319 | return(ra);
|
---|
| 320 | }
|
---|
| 321 | }
|
---|
| 322 |
|
---|
[785] | 323 | // SubArrays
|
---|
[804] | 324 | // $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
|
---|
[894] | 325 | //! Extract a sub-array
|
---|
| 326 | /*!
|
---|
| 327 | \param rx,ry,rz,rt,ru : range of extraction along dimensions
|
---|
| 328 | \sa Range
|
---|
| 329 | */
|
---|
[785] | 330 | template <class T>
|
---|
[804] | 331 | TArray<T> TArray<T>::SubArray(Range rx, Range ry, Range rz, Range rt, Range ru) const
|
---|
[785] | 332 | {
|
---|
[804] | 333 | if (NbDimensions() < 1)
|
---|
| 334 | throw RangeCheckError("TArray<T>::operator () (Range, ...) - Not Allocated Array ! ");
|
---|
[1156] | 335 | int_4 ndim = 0;
|
---|
| 336 | sa_size_t size[BASEARRAY_MAXNDIMS];
|
---|
| 337 | sa_size_t step[BASEARRAY_MAXNDIMS];
|
---|
| 338 | sa_size_t pos[BASEARRAY_MAXNDIMS];
|
---|
[785] | 339 | size[0] = rx.Size();
|
---|
| 340 | size[1] = ry.Size();
|
---|
| 341 | size[2] = rz.Size();
|
---|
| 342 | size[3] = rt.Size();
|
---|
| 343 | size[4] = ru.Size();
|
---|
| 344 |
|
---|
| 345 | step[0] = rx.Step();
|
---|
| 346 | step[1] = ry.Step();
|
---|
| 347 | step[2] = rz.Step();
|
---|
| 348 | step[3] = rt.Step();
|
---|
| 349 | step[4] = ru.Step();
|
---|
| 350 |
|
---|
| 351 | pos[0] = rx.Start();
|
---|
| 352 | pos[1] = ry.Start();
|
---|
| 353 | pos[2] = rz.Start();
|
---|
| 354 | pos[3] = rt.Start();
|
---|
| 355 | pos[4] = ru.Start();
|
---|
| 356 |
|
---|
| 357 | ndim = ndim_;
|
---|
| 358 | TArray<T> ra;
|
---|
[804] | 359 | UpdateSubArraySizes(ra, ndim, size, pos, step);
|
---|
[787] | 360 | ra.DataBlock().Share(this->DataBlock());
|
---|
[785] | 361 | ra.SetTemp(true);
|
---|
| 362 | return(ra);
|
---|
| 363 | }
|
---|
| 364 |
|
---|
[772] | 365 | // ...... Operation de calcul sur les tableaux ......
|
---|
| 366 | // ------- Attention --------
|
---|
| 367 | // Boucles normales prenant en compte les steps ....
|
---|
[894] | 368 | // Possibilite de // , vectorisation
|
---|
| 369 |
|
---|
| 370 | //! Fill TArray with Sequence \b seq
|
---|
| 371 | /*!
|
---|
| 372 | \param seq : sequence to fill the array
|
---|
| 373 | \sa Sequence
|
---|
| 374 | */
|
---|
[772] | 375 | template <class T>
|
---|
[1103] | 376 | TArray<T>& TArray<T>::SetSeq(Sequence const & seq)
|
---|
[772] | 377 | {
|
---|
[804] | 378 | if (NbDimensions() < 1)
|
---|
[813] | 379 | throw RangeCheckError("TArray<T>::SetSeq(Sequence ) - Not Allocated Array ! ");
|
---|
[1103] | 380 |
|
---|
[785] | 381 | T * pe;
|
---|
[1156] | 382 | sa_size_t j,k;
|
---|
| 383 | int_4 ka;
|
---|
[1103] | 384 | if (arrtype_ == 0) ka = 0;
|
---|
| 385 | else ka = macoli_;
|
---|
[1156] | 386 | sa_size_t step = Step(ka);
|
---|
| 387 | sa_size_t gpas = Size(ka);
|
---|
| 388 | sa_size_t naxa = Size()/Size(ka);
|
---|
[1103] | 389 | for(j=0; j<naxa; j++) {
|
---|
| 390 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
| 391 | #if !defined(__GNUG__)
|
---|
| 392 | for(k=0; k<gpas; k++) pe[k*step] = (T) seq(j*gpas+k);
|
---|
| 393 | #else
|
---|
| 394 | // g++ (up to 2.95.1) se melange les pinceaux s'il y a le cast (T) pour l'instanciation des complexes
|
---|
| 395 | for(k=0; k<gpas; k++) pe[k*step] = seq(j*gpas+k);
|
---|
| 396 | #endif
|
---|
[785] | 397 | }
|
---|
[772] | 398 | return(*this);
|
---|
| 399 | }
|
---|
| 400 |
|
---|
| 401 | // >>>> Operations avec 2nd membre de type scalaire
|
---|
| 402 |
|
---|
[894] | 403 | //! Fill an array with a constant value \b x
|
---|
[772] | 404 | template <class T>
|
---|
[813] | 405 | TArray<T>& TArray<T>::SetT(T x)
|
---|
[772] | 406 | {
|
---|
[804] | 407 | if (NbDimensions() < 1)
|
---|
[813] | 408 | throw RangeCheckError("TArray<T>::SetT(T ) - Not Allocated Array ! ");
|
---|
[785] | 409 | T * pe;
|
---|
[1156] | 410 | sa_size_t j,k;
|
---|
[785] | 411 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
[1156] | 412 | sa_size_t step = AvgStep();
|
---|
| 413 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 414 | pe = Data();
|
---|
| 415 | for(k=0; k<maxx; k+=step ) pe[k] = x;
|
---|
| 416 | }
|
---|
| 417 | else { // Non regular data spacing ...
|
---|
[1156] | 418 | int_4 ka = MaxSizeKA();
|
---|
| 419 | sa_size_t step = Step(ka);
|
---|
| 420 | sa_size_t gpas = Size(ka)*step;
|
---|
| 421 | sa_size_t naxa = Size()/Size(ka);
|
---|
[813] | 422 | for(j=0; j<naxa; j++) {
|
---|
| 423 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[785] | 424 | for(k=0; k<gpas; k+=step) pe[k] = x;
|
---|
| 425 | }
|
---|
| 426 | }
|
---|
[772] | 427 | return(*this);
|
---|
| 428 | }
|
---|
| 429 |
|
---|
[894] | 430 | //! Add a constant value \b x to an array
|
---|
[772] | 431 | template <class T>
|
---|
[804] | 432 | TArray<T>& TArray<T>::Add(T x)
|
---|
[772] | 433 | {
|
---|
[804] | 434 | if (NbDimensions() < 1)
|
---|
| 435 | throw RangeCheckError("TArray<T>::Add(T ) - Not Allocated Array ! ");
|
---|
[785] | 436 | T * pe;
|
---|
[1156] | 437 | sa_size_t j,k;
|
---|
[785] | 438 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
[1156] | 439 | sa_size_t step = AvgStep();
|
---|
| 440 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 441 | pe = Data();
|
---|
| 442 | for(k=0; k<maxx; k+=step ) pe[k] += x;
|
---|
| 443 | }
|
---|
| 444 | else { // Non regular data spacing ...
|
---|
[1156] | 445 | int_4 ka = MaxSizeKA();
|
---|
| 446 | sa_size_t step = Step(ka);
|
---|
| 447 | sa_size_t gpas = Size(ka)*step;
|
---|
| 448 | sa_size_t naxa = Size()/Size(ka);
|
---|
[813] | 449 | for(j=0; j<naxa; j++) {
|
---|
| 450 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[785] | 451 | for(k=0; k<gpas; k+=step) pe[k] += x;
|
---|
| 452 | }
|
---|
| 453 | }
|
---|
[772] | 454 | return(*this);
|
---|
| 455 | }
|
---|
| 456 |
|
---|
[894] | 457 | //! Substract a constant value \b x to an array
|
---|
[970] | 458 | /*!
|
---|
| 459 | Substract a constant from the *this = *this-x
|
---|
| 460 | \param fginv == true : Perfoms the inverse subtraction (*this = x-(*this))
|
---|
| 461 | */
|
---|
[772] | 462 | template <class T>
|
---|
[970] | 463 | TArray<T>& TArray<T>::Sub(T x, bool fginv)
|
---|
[772] | 464 | {
|
---|
[804] | 465 | if (NbDimensions() < 1)
|
---|
| 466 | throw RangeCheckError("TArray<T>::Sub(T ) - Not Allocated Array ! ");
|
---|
[785] | 467 | T * pe;
|
---|
[1156] | 468 | sa_size_t j,k;
|
---|
[785] | 469 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
[1156] | 470 | sa_size_t step = AvgStep();
|
---|
| 471 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 472 | pe = Data();
|
---|
[970] | 473 | if (fginv)
|
---|
| 474 | for(k=0; k<maxx; k+=step ) pe[k] = x-pe[k];
|
---|
| 475 | else
|
---|
| 476 | for(k=0; k<maxx; k+=step ) pe[k] -= x;
|
---|
[785] | 477 | }
|
---|
| 478 | else { // Non regular data spacing ...
|
---|
[1156] | 479 | int_4 ka = MaxSizeKA();
|
---|
| 480 | sa_size_t step = Step(ka);
|
---|
| 481 | sa_size_t gpas = Size(ka)*step;
|
---|
| 482 | sa_size_t naxa = Size()/Size(ka);
|
---|
[813] | 483 | for(j=0; j<naxa; j++) {
|
---|
| 484 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[970] | 485 | if (fginv)
|
---|
| 486 | for(k=0; k<gpas; k+=step) pe[k] = x-pe[k];
|
---|
| 487 | else
|
---|
| 488 | for(k=0; k<gpas; k+=step) pe[k] -= x;
|
---|
[785] | 489 | }
|
---|
| 490 | }
|
---|
[772] | 491 | return(*this);
|
---|
| 492 | }
|
---|
| 493 |
|
---|
[894] | 494 | //! Multiply an array by a constant value \b x
|
---|
[772] | 495 | template <class T>
|
---|
[804] | 496 | TArray<T>& TArray<T>::Mul(T x)
|
---|
[772] | 497 | {
|
---|
[804] | 498 | if (NbDimensions() < 1)
|
---|
| 499 | throw RangeCheckError("TArray<T>::Mul(T ) - Not Allocated Array ! ");
|
---|
[785] | 500 | T * pe;
|
---|
[1156] | 501 | sa_size_t j,k;
|
---|
[785] | 502 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
[1156] | 503 | sa_size_t step = AvgStep();
|
---|
| 504 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 505 | pe = Data();
|
---|
| 506 | for(k=0; k<maxx; k+=step ) pe[k] *= x;
|
---|
| 507 | }
|
---|
| 508 | else { // Non regular data spacing ...
|
---|
[1156] | 509 | int_4 ka = MaxSizeKA();
|
---|
| 510 | sa_size_t step = Step(ka);
|
---|
| 511 | sa_size_t gpas = Size(ka)*step;
|
---|
| 512 | sa_size_t naxa = Size()/Size(ka);
|
---|
[813] | 513 | for(j=0; j<naxa; j++) {
|
---|
| 514 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[785] | 515 | for(k=0; k<gpas; k+=step) pe[k] *= x;
|
---|
| 516 | }
|
---|
| 517 | }
|
---|
[772] | 518 | return(*this);
|
---|
| 519 | }
|
---|
| 520 |
|
---|
[894] | 521 | //! Divide an array by a constant value \b x
|
---|
[970] | 522 | /*!
|
---|
| 523 | Divide the array by a constant *this = *this/x
|
---|
| 524 | \param fginv == true : Perfoms the inverse division (*this = x/(*this))
|
---|
| 525 | */
|
---|
[772] | 526 | template <class T>
|
---|
[970] | 527 | TArray<T>& TArray<T>::Div(T x, bool fginv)
|
---|
[772] | 528 | {
|
---|
[804] | 529 | if (NbDimensions() < 1)
|
---|
| 530 | throw RangeCheckError("TArray<T>::Div(T ) - Not Allocated Array ! ");
|
---|
[970] | 531 | if (!fginv && (x == (T) 0) )
|
---|
[894] | 532 | throw MathExc("TArray<T>::Div(T ) - Divide by zero ! ");
|
---|
[785] | 533 | T * pe;
|
---|
[1156] | 534 | sa_size_t j,k;
|
---|
[785] | 535 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
[1156] | 536 | sa_size_t step = AvgStep();
|
---|
| 537 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 538 | pe = Data();
|
---|
[970] | 539 | if (fginv)
|
---|
| 540 | for(k=0; k<maxx; k+=step ) pe[k] = x/pe[k];
|
---|
| 541 | else
|
---|
| 542 | for(k=0; k<maxx; k+=step ) pe[k] /= x;
|
---|
[785] | 543 | }
|
---|
| 544 | else { // Non regular data spacing ...
|
---|
[1156] | 545 | int_4 ka = MaxSizeKA();
|
---|
| 546 | sa_size_t step = Step(ka);
|
---|
| 547 | sa_size_t gpas = Size(ka)*step;
|
---|
| 548 | sa_size_t naxa = Size()/Size(ka);
|
---|
[813] | 549 | for(j=0; j<naxa; j++) {
|
---|
| 550 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[970] | 551 | if (fginv)
|
---|
| 552 | for(k=0; k<gpas; k+=step) pe[k] = x/pe[k];
|
---|
| 553 | else
|
---|
| 554 | for(k=0; k<gpas; k+=step) pe[k] /= x;
|
---|
[785] | 555 | }
|
---|
| 556 | }
|
---|
[772] | 557 | return(*this);
|
---|
| 558 | }
|
---|
| 559 |
|
---|
| 560 |
|
---|
[1156] | 561 | //! Replace array elements values by their opposite ( a(i) -> -a(i) )
|
---|
| 562 | template <class T>
|
---|
| 563 | TArray<T>& TArray<T>::NegateElt()
|
---|
| 564 | {
|
---|
| 565 | if (NbDimensions() < 1)
|
---|
| 566 | throw RangeCheckError("TArray<T>::NegateElt() - Not Allocated Array ! ");
|
---|
| 567 | T * pe;
|
---|
| 568 | sa_size_t j,k;
|
---|
| 569 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
| 570 | sa_size_t step = AvgStep();
|
---|
| 571 | sa_size_t maxx = totsize_*step;
|
---|
| 572 | pe = Data();
|
---|
| 573 | for(k=0; k<maxx; k+=step ) pe[k] = -pe[k];
|
---|
| 574 | }
|
---|
| 575 | else { // Non regular data spacing ...
|
---|
| 576 | int_4 ka = MaxSizeKA();
|
---|
| 577 | sa_size_t step = Step(ka);
|
---|
| 578 | sa_size_t gpas = Size(ka)*step;
|
---|
| 579 | sa_size_t naxa = Size()/Size(ka);
|
---|
| 580 | for(j=0; j<naxa; j++) {
|
---|
| 581 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
| 582 | for(k=0; k<gpas; k+=step) pe[k] = -pe[k];
|
---|
| 583 | }
|
---|
| 584 | }
|
---|
| 585 | return(*this);
|
---|
| 586 | }
|
---|
[804] | 587 |
|
---|
[772] | 588 | // >>>> Operations avec 2nd membre de type tableau
|
---|
[894] | 589 | //! Add two TArrays
|
---|
[772] | 590 | template <class T>
|
---|
[804] | 591 | TArray<T>& TArray<T>::AddElt(const TArray<T>& a)
|
---|
[772] | 592 | {
|
---|
[804] | 593 | if (NbDimensions() < 1)
|
---|
| 594 | throw RangeCheckError("TArray<T>::AddElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 595 | bool smo;
|
---|
| 596 | if (!CompareSizes(a, smo))
|
---|
[813] | 597 | throw(SzMismatchError("TArray<T>::AddElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[785] | 598 |
|
---|
| 599 | T * pe;
|
---|
| 600 | const T * pea;
|
---|
[1156] | 601 | sa_size_t j,k,ka;
|
---|
[1099] | 602 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0)) { // regularly spaced elements
|
---|
[1156] | 603 | sa_size_t step = AvgStep();
|
---|
| 604 | sa_size_t stepa = a.AvgStep();
|
---|
| 605 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 606 | pe = Data();
|
---|
| 607 | pea = a.Data();
|
---|
| 608 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] += pea[ka] ;
|
---|
[772] | 609 | }
|
---|
[785] | 610 | else { // Non regular data spacing ...
|
---|
[1156] | 611 | int_4 ax,axa;
|
---|
| 612 | sa_size_t step, stepa;
|
---|
| 613 | sa_size_t gpas, naxa;
|
---|
[1099] | 614 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 615 | for(j=0; j<naxa; j++) {
|
---|
| 616 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 617 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[785] | 618 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] += pea[ka];
|
---|
| 619 | }
|
---|
| 620 | }
|
---|
[772] | 621 | return(*this);
|
---|
| 622 | }
|
---|
| 623 |
|
---|
[894] | 624 | //! Substract two TArrays
|
---|
[970] | 625 | /*!
|
---|
| 626 | Substract two TArrays *this = *this-a
|
---|
| 627 | \param fginv == true : Perfoms the inverse subtraction (*this = a-(*this))
|
---|
| 628 | */
|
---|
[772] | 629 | template <class T>
|
---|
[970] | 630 | TArray<T>& TArray<T>::SubElt(const TArray<T>& a, bool fginv)
|
---|
[772] | 631 | {
|
---|
[804] | 632 | if (NbDimensions() < 1)
|
---|
| 633 | throw RangeCheckError("TArray<T>::SubElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 634 | bool smo;
|
---|
| 635 | if (!CompareSizes(a, smo))
|
---|
[813] | 636 | throw(SzMismatchError("TArray<T>::SubElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[785] | 637 |
|
---|
| 638 | T * pe;
|
---|
| 639 | const T * pea;
|
---|
[1156] | 640 | sa_size_t j,k,ka;
|
---|
[1099] | 641 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0) ) { // regularly spaced elements
|
---|
[1156] | 642 | sa_size_t step = AvgStep();
|
---|
| 643 | sa_size_t stepa = a.AvgStep();
|
---|
| 644 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 645 | pe = Data();
|
---|
| 646 | pea = a.Data();
|
---|
[970] | 647 | if (fginv)
|
---|
| 648 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] = pea[ka]-pe[k] ;
|
---|
| 649 | else
|
---|
| 650 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] -= pea[ka] ;
|
---|
[772] | 651 | }
|
---|
[785] | 652 | else { // Non regular data spacing ...
|
---|
[1156] | 653 | int_4 ax,axa;
|
---|
| 654 | sa_size_t step, stepa;
|
---|
| 655 | sa_size_t gpas, naxa;
|
---|
[1099] | 656 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 657 | for(j=0; j<naxa; j++) {
|
---|
| 658 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 659 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[970] | 660 | if (fginv)
|
---|
| 661 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka]-pe[k] ;
|
---|
| 662 | else
|
---|
| 663 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] -= pea[ka];
|
---|
[785] | 664 | }
|
---|
| 665 | }
|
---|
[772] | 666 | return(*this);
|
---|
| 667 | }
|
---|
| 668 |
|
---|
[970] | 669 |
|
---|
[894] | 670 | //! Multiply two TArrays (elements by elements)
|
---|
[772] | 671 | template <class T>
|
---|
[804] | 672 | TArray<T>& TArray<T>::MulElt(const TArray<T>& a)
|
---|
[772] | 673 | {
|
---|
[804] | 674 | if (NbDimensions() < 1)
|
---|
| 675 | throw RangeCheckError("TArray<T>::MulElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 676 | bool smo;
|
---|
| 677 | if (!CompareSizes(a, smo))
|
---|
[813] | 678 | throw(SzMismatchError("TArray<T>::MulElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[785] | 679 |
|
---|
| 680 | T * pe;
|
---|
| 681 | const T * pea;
|
---|
[1156] | 682 | sa_size_t j,k,ka;
|
---|
[1099] | 683 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0) ) { // regularly spaced elements
|
---|
[1156] | 684 | sa_size_t step = AvgStep();
|
---|
| 685 | sa_size_t stepa = a.AvgStep();
|
---|
| 686 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 687 | pe = Data();
|
---|
| 688 | pea = a.Data();
|
---|
| 689 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] *= pea[ka] ;
|
---|
[772] | 690 | }
|
---|
[785] | 691 | else { // Non regular data spacing ...
|
---|
[1156] | 692 | int_4 ax,axa;
|
---|
| 693 | sa_size_t step, stepa;
|
---|
| 694 | sa_size_t gpas, naxa;
|
---|
[1099] | 695 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 696 | for(j=0; j<naxa; j++) {
|
---|
[1099] | 697 | pe = mNDBlock.Begin()+Offset(axa,j);
|
---|
| 698 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[785] | 699 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] *= pea[ka];
|
---|
| 700 | }
|
---|
| 701 | }
|
---|
[772] | 702 | return(*this);
|
---|
| 703 | }
|
---|
| 704 |
|
---|
[804] | 705 |
|
---|
[894] | 706 | //! Divide two TArrays (elements by elements)
|
---|
[970] | 707 | /*!
|
---|
| 708 | Divide two TArrays *this = (*this)/a
|
---|
| 709 | \param fginv == true : Perfoms the inverse division (*this = a/(*this))
|
---|
[1072] | 710 | \param divzero == true : if a(i)==0. result is set to zero: (*this)(i)==0.
|
---|
[970] | 711 | */
|
---|
[772] | 712 | template <class T>
|
---|
[1072] | 713 | TArray<T>& TArray<T>::DivElt(const TArray<T>& a, bool fginv, bool divzero)
|
---|
[772] | 714 | {
|
---|
[804] | 715 | if (NbDimensions() < 1)
|
---|
| 716 | throw RangeCheckError("TArray<T>::DivElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 717 | bool smo;
|
---|
| 718 | if (!CompareSizes(a, smo))
|
---|
[813] | 719 | throw(SzMismatchError("TArray<T>::DivElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[785] | 720 |
|
---|
| 721 | T * pe;
|
---|
| 722 | const T * pea;
|
---|
[1156] | 723 | sa_size_t j,k,ka;
|
---|
[1099] | 724 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0) ) { // regularly spaced elements
|
---|
[1156] | 725 | sa_size_t step = AvgStep();
|
---|
| 726 | sa_size_t stepa = a.AvgStep();
|
---|
| 727 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 728 | pe = Data();
|
---|
| 729 | pea = a.Data();
|
---|
[1072] | 730 | if(divzero) {
|
---|
| 731 | if (fginv)
|
---|
| 732 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa )
|
---|
| 733 | {if(pe[k]==(T)0) pe[k] = (T)0; else pe[k] = pea[ka]/pe[k];}
|
---|
| 734 | else
|
---|
| 735 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa )
|
---|
| 736 | {if(pea[k]==(T)0) pe[k] = (T)0; else pe[k] /= pea[ka] ;}
|
---|
| 737 | } else {
|
---|
| 738 | if (fginv)
|
---|
| 739 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] = pea[ka]/pe[k];
|
---|
| 740 | else
|
---|
| 741 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] /= pea[ka] ;
|
---|
| 742 | }
|
---|
[772] | 743 | }
|
---|
[785] | 744 | else { // Non regular data spacing ...
|
---|
[1156] | 745 | int_4 ax,axa;
|
---|
| 746 | sa_size_t step, stepa;
|
---|
| 747 | sa_size_t gpas, naxa;
|
---|
[1099] | 748 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 749 | for(j=0; j<naxa; j++) {
|
---|
| 750 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 751 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[1072] | 752 | if(divzero) {
|
---|
| 753 | if (fginv)
|
---|
| 754 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa)
|
---|
| 755 | {if(pe[k]==(T)0) pe[k] = (T)0; else pe[k] = pea[ka]/pe[k];}
|
---|
| 756 | else
|
---|
| 757 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa)
|
---|
| 758 | {if(pea[k]==(T)0) pe[k] = (T)0; else pe[k] /= pea[ka];}
|
---|
| 759 | } else {
|
---|
| 760 | if (fginv)
|
---|
| 761 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka]/pe[k];
|
---|
| 762 | else
|
---|
| 763 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] /= pea[ka];
|
---|
| 764 | }
|
---|
[785] | 765 | }
|
---|
| 766 | }
|
---|
[772] | 767 | return(*this);
|
---|
| 768 | }
|
---|
| 769 |
|
---|
[894] | 770 | //! Copy elements of \b a
|
---|
[804] | 771 | template <class T>
|
---|
| 772 | TArray<T>& TArray<T>::CopyElt(const TArray<T>& a)
|
---|
| 773 | {
|
---|
| 774 | if (NbDimensions() < 1)
|
---|
| 775 | throw RangeCheckError("TArray<T>::CopyElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 776 | bool smo;
|
---|
| 777 | if (!CompareSizes(a, smo))
|
---|
[1050] | 778 | throw(SzMismatchError("TArray<T>::CopyElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[772] | 779 |
|
---|
[804] | 780 | T * pe;
|
---|
| 781 | const T * pea;
|
---|
[1156] | 782 | sa_size_t j,k,ka;
|
---|
[1099] | 783 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0) ) { // regularly spaced elements
|
---|
[1156] | 784 | sa_size_t step = AvgStep();
|
---|
| 785 | sa_size_t stepa = a.AvgStep();
|
---|
| 786 | sa_size_t maxx = totsize_*step;
|
---|
[804] | 787 | pe = Data();
|
---|
| 788 | pea = a.Data();
|
---|
| 789 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] = pea[ka] ;
|
---|
| 790 | }
|
---|
| 791 | else { // Non regular data spacing ...
|
---|
[1156] | 792 | int_4 ax,axa;
|
---|
| 793 | sa_size_t step, stepa;
|
---|
| 794 | sa_size_t gpas, naxa;
|
---|
[1099] | 795 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 796 | for(j=0; j<naxa; j++) {
|
---|
| 797 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 798 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[804] | 799 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka];
|
---|
| 800 | }
|
---|
| 801 | }
|
---|
| 802 | return(*this);
|
---|
| 803 | }
|
---|
| 804 |
|
---|
[1081] | 805 | //! Converts and Copy elements of \b a
|
---|
| 806 | template <class T>
|
---|
| 807 | TArray<T>& TArray<T>::ConvertAndCopyElt(const BaseArray& a)
|
---|
| 808 | {
|
---|
| 809 | if (NbDimensions() < 1)
|
---|
| 810 | throw RangeCheckError("TArray<T>::ConvertAndCopyElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 811 | bool smo;
|
---|
| 812 | if (!CompareSizes(a, smo))
|
---|
[1081] | 813 | throw(SzMismatchError("TArray<T>::ConvertAndCopyElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[804] | 814 |
|
---|
[1081] | 815 | T * pe;
|
---|
[1156] | 816 | sa_size_t j,k,ka;
|
---|
| 817 | sa_size_t offa;
|
---|
[1081] | 818 | // Non regular data spacing ...
|
---|
[1156] | 819 | int_4 ax,axa;
|
---|
| 820 | sa_size_t step, stepa;
|
---|
| 821 | sa_size_t gpas, naxa;
|
---|
[1099] | 822 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[1081] | 823 | for(j=0; j<naxa; j++) {
|
---|
| 824 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 825 | offa = a.Offset(axa,j);
|
---|
[1085] | 826 | #if !defined(__GNUG__)
|
---|
| 827 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = (T)a.ValueAtPosition(offa+ka);
|
---|
| 828 | #else
|
---|
| 829 | // g++ (up to 2.95.1) se melange les pinceaux s'il y a le cast (T) pour l'instanciation des complexes
|
---|
[1081] | 830 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = a.ValueAtPosition(offa+ka);
|
---|
[1085] | 831 | #endif
|
---|
[1081] | 832 | }
|
---|
| 833 | return(*this);
|
---|
| 834 | }
|
---|
| 835 |
|
---|
| 836 |
|
---|
[804] | 837 | // Somme et produit des elements
|
---|
[894] | 838 | //! Sum all elements
|
---|
[804] | 839 | template <class T>
|
---|
| 840 | T TArray<T>::Sum() const
|
---|
| 841 | {
|
---|
| 842 | if (NbDimensions() < 1)
|
---|
| 843 | throw RangeCheckError("TArray<T>::Sum() - Not Allocated Array ! ");
|
---|
| 844 | T ret=0;
|
---|
| 845 | const T * pe;
|
---|
[1156] | 846 | sa_size_t j,k;
|
---|
[804] | 847 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
[1156] | 848 | sa_size_t step = AvgStep();
|
---|
| 849 | sa_size_t maxx = totsize_*step;
|
---|
[804] | 850 | pe = Data();
|
---|
| 851 | for(k=0; k<maxx; k+=step ) ret += pe[k];
|
---|
| 852 | }
|
---|
| 853 | else { // Non regular data spacing ...
|
---|
[1156] | 854 | int_4 ka = MaxSizeKA();
|
---|
| 855 | sa_size_t step = Step(ka);
|
---|
| 856 | sa_size_t gpas = Size(ka)*step;
|
---|
| 857 | sa_size_t naxa = Size()/Size(ka);
|
---|
[813] | 858 | for(j=0; j<naxa; j++) {
|
---|
| 859 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[804] | 860 | for(k=0; k<gpas; k+=step) ret += pe[k] ;
|
---|
| 861 | }
|
---|
| 862 | }
|
---|
| 863 | return ret;
|
---|
| 864 | }
|
---|
| 865 |
|
---|
[894] | 866 | //! Multiply all elements
|
---|
[804] | 867 | template <class T>
|
---|
| 868 | T TArray<T>::Product() const
|
---|
| 869 | {
|
---|
| 870 | if (NbDimensions() < 1)
|
---|
| 871 | throw RangeCheckError("TArray<T>::Product() - Not Allocated Array ! ");
|
---|
[1113] | 872 | T ret=(T)1;
|
---|
[804] | 873 | const T * pe;
|
---|
[1156] | 874 | sa_size_t j,k;
|
---|
[804] | 875 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
[1156] | 876 | sa_size_t step = AvgStep();
|
---|
| 877 | sa_size_t maxx = totsize_*step;
|
---|
[804] | 878 | pe = Data();
|
---|
| 879 | for(k=0; k<maxx; k+=step ) ret *= pe[k];
|
---|
| 880 | }
|
---|
| 881 | else { // Non regular data spacing ...
|
---|
[1156] | 882 | int_4 ka = MaxSizeKA();
|
---|
| 883 | sa_size_t step = Step(ka);
|
---|
| 884 | sa_size_t gpas = Size(ka)*step;
|
---|
| 885 | sa_size_t naxa = Size()/Size(ka);
|
---|
[813] | 886 | for(j=0; j<naxa; j++) {
|
---|
| 887 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[804] | 888 | for(k=0; k<gpas; k+=step) ret *= pe[k] ;
|
---|
| 889 | }
|
---|
| 890 | }
|
---|
| 891 | return ret;
|
---|
| 892 | }
|
---|
| 893 |
|
---|
[1113] | 894 | //! Returns the sum of all elements squared (Sum
|
---|
| 895 | template <class T>
|
---|
| 896 | T TArray<T>::SumX2() const
|
---|
| 897 | {
|
---|
| 898 | if (NbDimensions() < 1)
|
---|
| 899 | throw RangeCheckError("TArray<T>::SumX2() - Not Allocated Array ! ");
|
---|
| 900 | T ret=0;
|
---|
| 901 | const T * pe;
|
---|
[1156] | 902 | sa_size_t j,k;
|
---|
[1113] | 903 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
[1156] | 904 | sa_size_t step = AvgStep();
|
---|
| 905 | sa_size_t maxx = totsize_*step;
|
---|
[1113] | 906 | pe = Data();
|
---|
| 907 | for(k=0; k<maxx; k+=step ) ret += pe[k]*pe[k];
|
---|
| 908 | }
|
---|
| 909 | else { // Non regular data spacing ...
|
---|
[1156] | 910 | int_4 ka = MaxSizeKA();
|
---|
| 911 | sa_size_t step = Step(ka);
|
---|
| 912 | sa_size_t gpas = Size(ka)*step;
|
---|
| 913 | sa_size_t naxa = Size()/Size(ka);
|
---|
[1113] | 914 | for(j=0; j<naxa; j++) {
|
---|
| 915 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
| 916 | for(k=0; k<gpas; k+=step) ret += pe[k]*pe[k] ;
|
---|
| 917 | }
|
---|
| 918 | }
|
---|
| 919 | return ret;
|
---|
| 920 | }
|
---|
[804] | 921 |
|
---|
[1113] | 922 | //! Return the minimum and the maximum values of the array elements
|
---|
| 923 | /*!
|
---|
| 924 | This method generates an exception (\c MathExc) if called for complex arrays
|
---|
| 925 | */
|
---|
| 926 | template <class T>
|
---|
| 927 | void TArray<T>::MinMax(T& min, T& max) const
|
---|
| 928 | {
|
---|
| 929 | const T * pe;
|
---|
[1156] | 930 | sa_size_t j,k;
|
---|
| 931 | int_4 ka = MaxSizeKA();
|
---|
| 932 | sa_size_t step = Step(ka);
|
---|
| 933 | sa_size_t gpas = Size(ka)*step;
|
---|
| 934 | sa_size_t naxa = Size()/Size(ka);
|
---|
[1113] | 935 | min = (*this)[0];
|
---|
| 936 | max = (*this)[0];
|
---|
| 937 | for(j=0; j<naxa; j++) {
|
---|
| 938 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
| 939 | for(k=0; k<gpas; k+=step) {
|
---|
| 940 | if (pe[k]<min) min = pe[k];
|
---|
| 941 | else if (pe[k]>max) max = pe[k];
|
---|
| 942 | }
|
---|
| 943 | }
|
---|
| 944 | return;
|
---|
| 945 | }
|
---|
[804] | 946 |
|
---|
[1113] | 947 | void TArray< complex<r_4> >::MinMax(complex<r_4>& min, complex<r_4>& max) const
|
---|
| 948 | {
|
---|
| 949 | throw MathExc("TArray< complex<r_4> >::MinMax(...) - No order in complex");
|
---|
| 950 | }
|
---|
| 951 |
|
---|
| 952 | void TArray< complex<r_8> >::MinMax(complex<r_8>& min, complex<r_8>& max) const
|
---|
| 953 | {
|
---|
| 954 | throw MathExc("TArray< complex<r_4> >::MinMax(...) - No order in complex");
|
---|
| 955 | }
|
---|
| 956 |
|
---|
[772] | 957 | // ----------------------------------------------------
|
---|
| 958 | // Impression, etc ...
|
---|
| 959 | // ----------------------------------------------------
|
---|
| 960 |
|
---|
[894] | 961 | //! Return a string that contain the type \b T of the array
|
---|
[772] | 962 | template <class T>
|
---|
[813] | 963 | string TArray<T>::InfoString() const
|
---|
[772] | 964 | {
|
---|
[813] | 965 | string rs = "TArray<" ;
|
---|
| 966 | rs += typeid(T).name();
|
---|
| 967 | rs += "> ";
|
---|
[787] | 968 | return(rs);
|
---|
[772] | 969 | }
|
---|
| 970 |
|
---|
[894] | 971 | //! Print array
|
---|
| 972 | /*!
|
---|
| 973 | \param os : output stream
|
---|
| 974 | \param maxprt : maximum numer of print
|
---|
| 975 | \param si : if true, display attached DvList
|
---|
| 976 | \sa SetMaxPrint
|
---|
| 977 | */
|
---|
[772] | 978 | template <class T>
|
---|
| 979 | void TArray<T>::Print(ostream& os, int_4 maxprt, bool si) const
|
---|
| 980 | {
|
---|
| 981 | if (maxprt < 0) maxprt = max_nprt_;
|
---|
[1156] | 982 | sa_size_t npr = 0;
|
---|
[772] | 983 | Show(os, si);
|
---|
[850] | 984 | if (ndim_ < 1) return;
|
---|
[1156] | 985 | sa_size_t k0,k1,k2,k3,k4;
|
---|
[772] | 986 | for(k4=0; k4<size_[4]; k4++) {
|
---|
[785] | 987 | if (size_[4] > 1) cout << "\n ----- Dimension 5 (U) K4= " << k4 << endl;
|
---|
[772] | 988 | for(k3=0; k3<size_[3]; k3++) {
|
---|
[785] | 989 | if (size_[3] > 1) cout << "\n ----- Dimension 4 (T) K3= " << k3 << endl;
|
---|
[772] | 990 | for(k2=0; k2<size_[2]; k2++) {
|
---|
[785] | 991 | if (size_[2] > 1) cout << "\n ----- Dimension 3 (Z) K2= " << k2 << endl;
|
---|
[772] | 992 | for(k1=0; k1<size_[1]; k1++) {
|
---|
[785] | 993 | if ( (size_[1] > 1) && (size_[0] > 10) ) cout << "----- Dimension 2 (Y) K1= " << k1 << endl;
|
---|
[772] | 994 | for(k0=0; k0<size_[0]; k0++) {
|
---|
[785] | 995 | if(k0 > 0) os << ", ";
|
---|
| 996 | os << Elem(k0, k1, k2, k3, k4); npr++;
|
---|
[1156] | 997 | if (npr >= (sa_size_t) maxprt) {
|
---|
[772] | 998 | if (npr < totsize_) os << "\n .... " << endl; return;
|
---|
| 999 | }
|
---|
| 1000 | }
|
---|
| 1001 | os << endl;
|
---|
| 1002 | }
|
---|
| 1003 | }
|
---|
| 1004 | }
|
---|
| 1005 | }
|
---|
[813] | 1006 | os << endl;
|
---|
[772] | 1007 | }
|
---|
| 1008 |
|
---|
| 1009 |
|
---|
| 1010 |
|
---|
| 1011 | ///////////////////////////////////////////////////////////////
|
---|
| 1012 | ///////////////////////////////////////////////////////////////
|
---|
| 1013 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
[804] | 1014 | /*
|
---|
[772] | 1015 | #pragma define_template TArray<uint_1>
|
---|
[804] | 1016 | #pragma define_template TArray<int_2>
|
---|
| 1017 | #pragma define_template TArray<uint_4>
|
---|
| 1018 | #pragma define_template TArray<uint_8>
|
---|
| 1019 | */
|
---|
[772] | 1020 | #pragma define_template TArray<uint_2>
|
---|
| 1021 | #pragma define_template TArray<int_4>
|
---|
| 1022 | #pragma define_template TArray<int_8>
|
---|
| 1023 | #pragma define_template TArray<r_4>
|
---|
| 1024 | #pragma define_template TArray<r_8>
|
---|
| 1025 | #pragma define_template TArray< complex<r_4> >
|
---|
| 1026 | #pragma define_template TArray< complex<r_8> >
|
---|
| 1027 | #endif
|
---|
| 1028 |
|
---|
| 1029 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
[804] | 1030 | /*
|
---|
| 1031 | template class TArray<uint_1>;
|
---|
| 1032 | template class TArray<int_2>;
|
---|
| 1033 | template class TArray<uint_4>;
|
---|
| 1034 | template class TArray<uint_8>;
|
---|
| 1035 | */
|
---|
[772] | 1036 | template class TArray<uint_2>;
|
---|
| 1037 | template class TArray<int_4>;
|
---|
| 1038 | template class TArray<int_8>;
|
---|
| 1039 | template class TArray<r_4>;
|
---|
| 1040 | template class TArray<r_8>;
|
---|
| 1041 | template class TArray< complex<r_4> >;
|
---|
| 1042 | template class TArray< complex<r_8> >;
|
---|
| 1043 | #endif
|
---|
| 1044 |
|
---|
| 1045 |
|
---|