[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
|
---|
[2267] | 14 | Class for template arrays with numerical data types (int, float, complex).
|
---|
[772] | 15 |
|
---|
[2267] | 16 | This class implements arrays with number of dimensions up to
|
---|
[926] | 17 | \ref BASEARRAY_MAXNDIMS "BASEARRAY_MAXNDIMS"
|
---|
[2267] | 18 |
|
---|
| 19 | Standard arithmetic operations on numerical arrays are implemented,
|
---|
| 20 | as well as sub-array manipulation services.
|
---|
| 21 | \b Array is a typedef for double precision floating point arrays ( TArray<r_8> )
|
---|
| 22 | \sa SOPHYA::Range
|
---|
| 23 | \sa SOPHYA::Sequence
|
---|
| 24 | \sa SOPHYA::MathArray
|
---|
| 25 |
|
---|
| 26 | \code
|
---|
| 27 | #include "array.h"
|
---|
| 28 | // ...
|
---|
| 29 | // Creating and initialising a 1-D array of integers
|
---|
| 30 | TArray<int> ia(5);
|
---|
| 31 | EnumeratedSequence es;
|
---|
| 32 | es = 24, 35, 46, 57, 68;
|
---|
| 33 | ia = es;
|
---|
| 34 | cout << "Array<int> ia = " << ia;
|
---|
| 35 | // 2-D array of floats
|
---|
| 36 | TArray<r_4> b(6,4), c(6,4);
|
---|
| 37 | // Initializing b with a constant
|
---|
| 38 | b = 2.71828;
|
---|
| 39 | // Filling c with random numbers
|
---|
| 40 | c = RandomSequence();
|
---|
| 41 | // Arithmetic operations
|
---|
| 42 | TArray<r_4> d = b+0.3f*c;
|
---|
| 43 | cout << "Array<float> d = " << d;
|
---|
| 44 | \endcode
|
---|
| 45 |
|
---|
[926] | 46 | */
|
---|
[772] | 47 |
|
---|
[1389] | 48 | /*! \ingroup TArray
|
---|
| 49 | \typedef sa_size_t
|
---|
| 50 | \brief Array index range and size, defined to be a 4-byte or 8-byte integer
|
---|
| 51 | */
|
---|
| 52 |
|
---|
[772] | 53 | // -------------------------------------------------------
|
---|
| 54 | // Methodes de la classe
|
---|
| 55 | // -------------------------------------------------------
|
---|
| 56 |
|
---|
[894] | 57 | ////////////////////////// Les constructeurs / destructeurs
|
---|
| 58 |
|
---|
| 59 | //! Default constructor
|
---|
[772] | 60 | template <class T>
|
---|
| 61 | TArray<T>::TArray()
|
---|
[804] | 62 | : BaseArray() , mNDBlock()
|
---|
[772] | 63 | {
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[894] | 66 | //! Constructor
|
---|
| 67 | /*!
|
---|
| 68 | \param ndim : number of dimensions (less or equal to
|
---|
| 69 | \ref BASEARRAY_MAXNDIMS "BASEARRAY_MAXNDIMS")
|
---|
| 70 | \param siz[ndim] : size along each dimension
|
---|
| 71 | \param step : step (same for all dimensions)
|
---|
[2564] | 72 | \param fzero : if \b true , set array elements to zero
|
---|
[894] | 73 | */
|
---|
[772] | 74 | template <class T>
|
---|
[2564] | 75 | TArray<T>::TArray(int_4 ndim, const sa_size_t * siz, sa_size_t step, bool fzero)
|
---|
| 76 | : BaseArray() , mNDBlock(ComputeTotalSize(ndim, siz, step, 1), fzero)
|
---|
[772] | 77 | {
|
---|
[1156] | 78 | string exmsg = "TArray<T>::TArray(int_4, sa_size_t *, sa_size_t)";
|
---|
[772] | 79 | if (!UpdateSizes(ndim, siz, step, 0, exmsg)) throw( ParmError(exmsg) );
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[894] | 82 | //! Constructor
|
---|
| 83 | /*!
|
---|
| 84 | \param nx,ny,nz,nt,nu : sizes along first, second, third, fourth and fifth dimension
|
---|
[2564] | 85 | \param fzero : if \b true , set array elements to zero
|
---|
[894] | 86 | */
|
---|
[772] | 87 | template <class T>
|
---|
[2564] | 88 | TArray<T>::TArray(sa_size_t nx, sa_size_t ny, sa_size_t nz, sa_size_t nt, sa_size_t nu, bool fzero)
|
---|
[804] | 89 | : BaseArray() , mNDBlock(nx*((ny>0)?ny:1)*((nz>0)?nz:1)*((nt>0)?nt:1)*((nu>0)?nu:1))
|
---|
[772] | 90 | {
|
---|
[1156] | 91 | sa_size_t size[BASEARRAY_MAXNDIMS];
|
---|
[772] | 92 | size[0] = nx; size[1] = ny; size[2] = nz;
|
---|
[804] | 93 | size[3] = nt; size[4] = nu;
|
---|
[1156] | 94 | int_4 ndim = 1;
|
---|
[804] | 95 | if ((size[1] > 0) && (size[2] > 0) && (size[3] > 0) && (size[4] > 0) ) ndim = 5;
|
---|
| 96 | else if ((size[1] > 0) && (size[2] > 0) && (size[3] > 0) ) ndim = 4;
|
---|
| 97 | else if ((size[1] > 0) && (size[2] > 0)) ndim = 3;
|
---|
[772] | 98 | else if (size[1] > 0) ndim = 2;
|
---|
| 99 | else ndim = 1;
|
---|
[1156] | 100 | string exmsg = "TArray<T>::TArray(sa_size_t, sa_size_t, sa_size_t, sa_size_t, sa_size_t)";
|
---|
[772] | 101 | if (!UpdateSizes(ndim, size, 1, 0, exmsg)) throw( ParmError(exmsg) );
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[894] | 104 | //! Constructor
|
---|
| 105 | /*!
|
---|
| 106 | \param ndim : number of dimensions
|
---|
| 107 | \param siz[ndim] : size along each dimension
|
---|
| 108 | \param db : datas are given by this NDataBlock
|
---|
| 109 | \param share : if true, data are shared, if false they are copied
|
---|
| 110 | \param step : step (same for all dimensions) in data block
|
---|
| 111 | \param offset : offset for first element in data block
|
---|
| 112 | */
|
---|
[772] | 113 | template <class T>
|
---|
[1156] | 114 | 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] | 115 | : BaseArray() , mNDBlock(db, share)
|
---|
[772] | 116 | {
|
---|
[1156] | 117 | string exmsg = "TArray<T>::TArray(int_4, sa_size_t *, NDataBlock<T> & ... )";
|
---|
[772] | 118 | if (!UpdateSizes(ndim, siz, step, offset, exmsg)) throw( ParmError(exmsg) );
|
---|
[1636] | 119 | if (mNDBlock.Size() < ComputeTotalSize(ndim, siz, step, offset)) {
|
---|
| 120 | exmsg += " DataBlock.Size() < ComputeTotalSize(...) " ;
|
---|
| 121 | throw( ParmError(exmsg) );
|
---|
| 122 | }
|
---|
[772] | 123 | }
|
---|
| 124 |
|
---|
[894] | 125 | //! Constructor
|
---|
| 126 | /*!
|
---|
| 127 | \param ndim : number of dimensions
|
---|
| 128 | \param siz[ndim] : size along each dimension
|
---|
| 129 | \param values : datas are given by this pointer
|
---|
| 130 | \param share : if true, data are shared, if false they are copied
|
---|
| 131 | \param step : step (same for all dimensions) in data block
|
---|
| 132 | \param offset : offset for first element in data block
|
---|
| 133 | \param br : if not NULL, dats are bridge with other datas
|
---|
| 134 | \sa NDataBlock
|
---|
| 135 | */
|
---|
[772] | 136 | template <class T>
|
---|
[1156] | 137 | TArray<T>::TArray(int_4 ndim, const sa_size_t * siz, T* values, sa_size_t step, sa_size_t offset, Bridge* br)
|
---|
[804] | 138 | : BaseArray() , mNDBlock(ComputeTotalSize(ndim, siz, step, 1), values, br)
|
---|
[772] | 139 | {
|
---|
[1156] | 140 | string exmsg = "TArray<T>::TArray(int_4, sa_size_t *, T* ... )";
|
---|
[772] | 141 | if (!UpdateSizes(ndim, siz, step, offset, exmsg)) throw( ParmError(exmsg) );
|
---|
| 142 | }
|
---|
| 143 |
|
---|
[894] | 144 | //! Constructor by copy
|
---|
[976] | 145 | /*!
|
---|
| 146 | \warning datas are \b SHARED with \b a.
|
---|
| 147 | \sa NDataBlock::NDataBlock(const NDataBlock<T>&)
|
---|
| 148 | */
|
---|
[772] | 149 | template <class T>
|
---|
| 150 | TArray<T>::TArray(const TArray<T>& a)
|
---|
[804] | 151 | : BaseArray() , mNDBlock(a.mNDBlock)
|
---|
[772] | 152 | {
|
---|
| 153 | string exmsg = "TArray<T>::TArray(const TArray<T>&)";
|
---|
| 154 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
| 155 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
| 156 | }
|
---|
| 157 |
|
---|
[894] | 158 | //! Constructor by copy
|
---|
| 159 | /*!
|
---|
| 160 | \param share : if true, data are shared, if false they are copied
|
---|
| 161 | */
|
---|
[772] | 162 | template <class T>
|
---|
| 163 | TArray<T>::TArray(const TArray<T>& a, bool share)
|
---|
[804] | 164 | : BaseArray() , mNDBlock(a.mNDBlock, share)
|
---|
[772] | 165 | {
|
---|
[1517] | 166 | if (a.NbDimensions() == 0) return;
|
---|
[772] | 167 | string exmsg = "TArray<T>::TArray(const TArray<T>&, bool)";
|
---|
| 168 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
| 169 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[1081] | 172 | //! Constructor with size and contents copied (after conversion) from a different type TArray
|
---|
| 173 | template <class T>
|
---|
| 174 | TArray<T>::TArray(const BaseArray& a)
|
---|
| 175 | : BaseArray() , mNDBlock()
|
---|
| 176 | {
|
---|
[1517] | 177 | if (a.NbDimensions() == 0) return;
|
---|
[1081] | 178 | string exmsg = "TArray<T>::TArray(const BaseArray&)";
|
---|
| 179 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
| 180 | mNDBlock.ReSize(totsize_);
|
---|
| 181 | // if (a.mInfo) mInfo = new DVList(*(a.mInfo)); - pb protected !
|
---|
| 182 | ConvertAndCopyElt(a);
|
---|
| 183 | }
|
---|
| 184 |
|
---|
[894] | 185 | //! Destructor
|
---|
[772] | 186 | template <class T>
|
---|
| 187 | TArray<T>::~TArray()
|
---|
| 188 | {
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[894] | 191 | ////////////////////////// Les methodes de copie/share
|
---|
| 192 |
|
---|
| 193 | //! Set array equal to \b a and return *this
|
---|
[976] | 194 | /*!
|
---|
[1364] | 195 | If the array is already allocated, CopyElt() is called
|
---|
| 196 | for checking that the two arrays have the same size and
|
---|
| 197 | for copying the array element values. For non allocated
|
---|
| 198 | arrays, CloneOrShare() is called. The array memory
|
---|
| 199 | organization is also copied from \b a.
|
---|
[976] | 200 | \warning Datas are copied (cloned) from \b a.
|
---|
[1364] | 201 | \sa CopyElt
|
---|
| 202 | \sa CloneOrShare
|
---|
[976] | 203 | \sa NDataBlock::operator=(const NDataBlock<T>&)
|
---|
| 204 | */
|
---|
[772] | 205 | template <class T>
|
---|
[804] | 206 | TArray<T>& TArray<T>::Set(const TArray<T>& a)
|
---|
[772] | 207 | {
|
---|
[970] | 208 | if (this == &a) return(*this);
|
---|
| 209 | if (a.NbDimensions() < 1)
|
---|
| 210 | throw RangeCheckError("TArray<T>::Set(a ) - Array a not allocated ! ");
|
---|
| 211 | if (NbDimensions() < 1) CloneOrShare(a);
|
---|
| 212 | else CopyElt(a);
|
---|
[772] | 213 | return(*this);
|
---|
| 214 | }
|
---|
| 215 |
|
---|
[1081] | 216 | //! Set array elements equal to the \b a array elements, after conversion
|
---|
| 217 | template <class T>
|
---|
| 218 | TArray<T>& TArray<T>::SetBA(const BaseArray& a)
|
---|
| 219 | {
|
---|
| 220 | if (this == &a) return(*this);
|
---|
| 221 | if (a.NbDimensions() < 1)
|
---|
| 222 | throw RangeCheckError("TArray<T>::SetBA(a ) - Array a not allocated ! ");
|
---|
| 223 | if (NbDimensions() < 1) {
|
---|
| 224 | string exmsg = "TArray<T>::SetBA(const BaseArray& a)";
|
---|
| 225 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
| 226 | mNDBlock.ReSize(totsize_);
|
---|
| 227 | }
|
---|
| 228 | ConvertAndCopyElt(a);
|
---|
| 229 | return(*this);
|
---|
| 230 | }
|
---|
| 231 |
|
---|
[894] | 232 | //! Clone array \b a
|
---|
[772] | 233 | template <class T>
|
---|
| 234 | void TArray<T>::Clone(const TArray<T>& a)
|
---|
| 235 | {
|
---|
| 236 | string exmsg = "TArray<T>::Clone()";
|
---|
| 237 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
| 238 | mNDBlock.Clone(a.mNDBlock);
|
---|
[894] | 239 | if (mInfo) {delete mInfo; mInfo = NULL;}
|
---|
[772] | 240 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
| 241 | }
|
---|
| 242 |
|
---|
[970] | 243 | //! Clone if \b a is not temporary, share if temporary
|
---|
[976] | 244 | /*! \sa NDataBlock::CloneOrShare(const NDataBlock<T>&) */
|
---|
[970] | 245 | template <class T>
|
---|
| 246 | void TArray<T>::CloneOrShare(const TArray<T>& a)
|
---|
| 247 | {
|
---|
| 248 | string exmsg = "TArray<T>::CloneOrShare()";
|
---|
[1103] | 249 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
[970] | 250 | mNDBlock.CloneOrShare(a.mNDBlock);
|
---|
[1103] | 251 | if (mInfo) {delete mInfo; mInfo = NULL;}
|
---|
| 252 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
[970] | 253 | }
|
---|
| 254 |
|
---|
| 255 | //! Share data with a
|
---|
| 256 | template <class T>
|
---|
| 257 | void TArray<T>::Share(const TArray<T>& a)
|
---|
| 258 | {
|
---|
| 259 | string exmsg = "TArray<T>::Share()";
|
---|
[1103] | 260 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
[970] | 261 | mNDBlock.Share(a.mNDBlock);
|
---|
[1103] | 262 | if (mInfo) {delete mInfo; mInfo = NULL;}
|
---|
| 263 | if (a.mInfo) mInfo = new DVList(*(a.mInfo));
|
---|
[970] | 264 | }
|
---|
| 265 |
|
---|
| 266 |
|
---|
[1393] | 267 | //! Sets or changes the array size
|
---|
[894] | 268 | /*!
|
---|
| 269 | \param ndim : number of dimensions
|
---|
| 270 | \param siz[ndim] : size along each dimension
|
---|
| 271 | \param step : step (same for all dimensions)
|
---|
[2564] | 272 | \param fzero : if \b true , set array elements to zero
|
---|
[894] | 273 | */
|
---|
[772] | 274 | template <class T>
|
---|
[2564] | 275 | void TArray<T>::ReSize(int_4 ndim, sa_size_t * siz, sa_size_t step, bool fzero)
|
---|
[772] | 276 | {
|
---|
[1099] | 277 | if (arrtype_ != 0) {
|
---|
| 278 | if (ndim != 2)
|
---|
| 279 | throw( ParmError("TArray<T>::ReSize(ndim!=2,...) for Matrix" ) );
|
---|
| 280 | if ((arrtype_ == 2) && (siz[0] > 1) && (siz[1] > 1))
|
---|
| 281 | throw( ParmError("TArray<T>::ReSize(,siz[0]>1 && size[1]>1) for Vector" ) );
|
---|
| 282 | }
|
---|
[1393] | 283 | string exmsg = "TArray<T>::ReSize(int_4 ...)";
|
---|
[772] | 284 | if (!UpdateSizes(ndim, siz, step, 0, exmsg)) throw( ParmError(exmsg) );
|
---|
[2564] | 285 | mNDBlock.ReSize(totsize_, fzero);
|
---|
[772] | 286 | }
|
---|
| 287 |
|
---|
[1393] | 288 | //! Sets or changes the array size.
|
---|
| 289 | /*!
|
---|
| 290 | The array size and memory layout are copied from the array \b a.
|
---|
| 291 | \param a : Array used as template for setting the size and memory layout.
|
---|
[2564] | 292 | \param pack : if \b true , create a packed array, else same memory layout as \b a.
|
---|
| 293 | \param fzero : if \b true , set array elements to zero
|
---|
[1393] | 294 | */
|
---|
| 295 | template <class T>
|
---|
[2564] | 296 | void TArray<T>::ReSize(const BaseArray& a, bool pack, bool fzero)
|
---|
[1393] | 297 | {
|
---|
| 298 | if (arrtype_ != 0) {
|
---|
| 299 | if (a.NbDimensions() != 2)
|
---|
| 300 | throw( ParmError("TArray<T>::ReSize(a.NbDimensions()!=2,...) for Matrix" ) );
|
---|
| 301 | if ((arrtype_ == 2) && (a.Size(0) > 1) && (a.Size(1) > 1))
|
---|
| 302 | throw( ParmError("TArray<T>::ReSize(a.Size(0)>1 && a.Size(1)>1) for Vector" ) );
|
---|
| 303 | }
|
---|
| 304 | string exmsg = "TArray<T>::ReSize(const TArray<T>&)";
|
---|
[2564] | 305 | if (pack) {
|
---|
| 306 | sa_size_t siz[BASEARRAY_MAXNDIMS];
|
---|
| 307 | for(int ksz=0; ksz<BASEARRAY_MAXNDIMS; ksz++) siz[ksz] = a.Size(ksz);
|
---|
| 308 | if (!UpdateSizes(a.NbDimensions(), siz, 1, 0, exmsg)) throw( ParmError(exmsg) );
|
---|
| 309 | mNDBlock.ReSize(totsize_, fzero);
|
---|
| 310 | }
|
---|
| 311 | else {
|
---|
| 312 | if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) );
|
---|
| 313 | mNDBlock.ReSize(totsize_);
|
---|
| 314 | }
|
---|
[1393] | 315 | }
|
---|
| 316 |
|
---|
[894] | 317 | //! Re-allocate space for array
|
---|
| 318 | /*!
|
---|
| 319 | \param ndim : number of dimensions
|
---|
| 320 | \param siz[ndim] : size along each dimension
|
---|
| 321 | \param step : step (same for all dimensions)
|
---|
| 322 | \param force : if true re-allocation is forced, if not it occurs
|
---|
| 323 | only if the required space is greater than the old one.
|
---|
| 324 | */
|
---|
[772] | 325 | template <class T>
|
---|
[1156] | 326 | void TArray<T>::Realloc(int_4 ndim, sa_size_t * siz, sa_size_t step, bool force)
|
---|
[772] | 327 | {
|
---|
[1099] | 328 | if (arrtype_ != 0) {
|
---|
| 329 | if (ndim != 2)
|
---|
| 330 | throw( ParmError("TArray<T>::Realloc(ndim!=2,...) for Matrix" ) );
|
---|
| 331 | if ((arrtype_ == 2) && (siz[0] > 1) && (siz[1] > 1))
|
---|
| 332 | throw( ParmError("TArray<T>::Realloc(,siz[0]>1 && size[1]>1) for Vector" ) );
|
---|
| 333 | }
|
---|
[772] | 334 | string exmsg = "TArray<T>::Realloc()";
|
---|
| 335 | if (!UpdateSizes(ndim, siz, step, 0, exmsg)) throw( ParmError(exmsg) );
|
---|
[1389] | 336 | mNDBlock.Realloc(totsize_, force);
|
---|
[772] | 337 | }
|
---|
| 338 |
|
---|
[787] | 339 |
|
---|
[894] | 340 | //! Compact dimensions in one or more is equal to 1.
|
---|
[772] | 341 | template <class T>
|
---|
[787] | 342 | TArray<T>& TArray<T>::CompactAllDimensions()
|
---|
[772] | 343 | {
|
---|
[787] | 344 | CompactAllDim();
|
---|
| 345 | return(*this);
|
---|
[772] | 346 | }
|
---|
| 347 |
|
---|
[894] | 348 | //! Compact dimensions if the last one is equal to 1.
|
---|
[785] | 349 | template <class T>
|
---|
[787] | 350 | TArray<T>& TArray<T>::CompactTrailingDimensions()
|
---|
[785] | 351 | {
|
---|
[787] | 352 | CompactTrailingDim();
|
---|
[785] | 353 | return(*this);
|
---|
| 354 | }
|
---|
| 355 |
|
---|
[894] | 356 | //! Give value (in \b double) for element at position \b ip..
|
---|
[785] | 357 | template <class T>
|
---|
[1156] | 358 | MuTyV & TArray<T>::ValueAtPosition(sa_size_t ip) const
|
---|
[785] | 359 | {
|
---|
[787] | 360 | #ifdef SO_BOUNDCHECKING
|
---|
[1156] | 361 | if (ip >= totsize_) throw( ParmError("TArray<T>::ValueAtPosition(sa_size_t ip) Out-of-bound Error") );
|
---|
[787] | 362 | #endif
|
---|
[1081] | 363 | my_mtv = *(mNDBlock.Begin()+Offset(ip));
|
---|
| 364 | return( my_mtv );
|
---|
[785] | 365 | }
|
---|
| 366 |
|
---|
[894] | 367 | //! Return array with elements packed
|
---|
| 368 | /*!
|
---|
| 369 | \param force : if true, pack elements in a new array.
|
---|
| 370 | If false and array is already packed, return
|
---|
| 371 | an array that share data with the current one.
|
---|
| 372 | \return packed array
|
---|
| 373 | */
|
---|
[804] | 374 | template <class T>
|
---|
| 375 | TArray<T> TArray<T>::PackElements(bool force) const
|
---|
| 376 | {
|
---|
| 377 | if (NbDimensions() < 1)
|
---|
| 378 | throw RangeCheckError("TArray<T>::PackElements() - Not Allocated Array ! ");
|
---|
| 379 | if ( !force && (AvgStep() == 1) ) {
|
---|
[970] | 380 | TArray<T> ra;
|
---|
| 381 | ra.Share(*this);
|
---|
[804] | 382 | ra.SetTemp(true);
|
---|
| 383 | return(ra);
|
---|
| 384 | }
|
---|
| 385 | else {
|
---|
| 386 | TArray<T> ra(ndim_, size_, 1);
|
---|
| 387 | ra.CopyElt(*this);
|
---|
| 388 | ra.SetTemp(true);
|
---|
| 389 | return(ra);
|
---|
| 390 | }
|
---|
| 391 | }
|
---|
| 392 |
|
---|
[785] | 393 | // SubArrays
|
---|
[804] | 394 | // $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
|
---|
[894] | 395 | //! Extract a sub-array
|
---|
| 396 | /*!
|
---|
| 397 | \param rx,ry,rz,rt,ru : range of extraction along dimensions
|
---|
| 398 | \sa Range
|
---|
| 399 | */
|
---|
[785] | 400 | template <class T>
|
---|
[804] | 401 | TArray<T> TArray<T>::SubArray(Range rx, Range ry, Range rz, Range rt, Range ru) const
|
---|
[785] | 402 | {
|
---|
[804] | 403 | if (NbDimensions() < 1)
|
---|
| 404 | throw RangeCheckError("TArray<T>::operator () (Range, ...) - Not Allocated Array ! ");
|
---|
[1156] | 405 | int_4 ndim = 0;
|
---|
| 406 | sa_size_t size[BASEARRAY_MAXNDIMS];
|
---|
| 407 | sa_size_t step[BASEARRAY_MAXNDIMS];
|
---|
| 408 | sa_size_t pos[BASEARRAY_MAXNDIMS];
|
---|
[785] | 409 | size[0] = rx.Size();
|
---|
| 410 | size[1] = ry.Size();
|
---|
| 411 | size[2] = rz.Size();
|
---|
| 412 | size[3] = rt.Size();
|
---|
| 413 | size[4] = ru.Size();
|
---|
| 414 |
|
---|
| 415 | step[0] = rx.Step();
|
---|
| 416 | step[1] = ry.Step();
|
---|
| 417 | step[2] = rz.Step();
|
---|
| 418 | step[3] = rt.Step();
|
---|
| 419 | step[4] = ru.Step();
|
---|
| 420 |
|
---|
| 421 | pos[0] = rx.Start();
|
---|
| 422 | pos[1] = ry.Start();
|
---|
| 423 | pos[2] = rz.Start();
|
---|
| 424 | pos[3] = rt.Start();
|
---|
| 425 | pos[4] = ru.Start();
|
---|
| 426 |
|
---|
| 427 | ndim = ndim_;
|
---|
| 428 | TArray<T> ra;
|
---|
[804] | 429 | UpdateSubArraySizes(ra, ndim, size, pos, step);
|
---|
[787] | 430 | ra.DataBlock().Share(this->DataBlock());
|
---|
[785] | 431 | ra.SetTemp(true);
|
---|
| 432 | return(ra);
|
---|
| 433 | }
|
---|
| 434 |
|
---|
[772] | 435 | // ...... Operation de calcul sur les tableaux ......
|
---|
| 436 | // ------- Attention --------
|
---|
| 437 | // Boucles normales prenant en compte les steps ....
|
---|
[894] | 438 | // Possibilite de // , vectorisation
|
---|
| 439 |
|
---|
| 440 | //! Fill TArray with Sequence \b seq
|
---|
| 441 | /*!
|
---|
| 442 | \param seq : sequence to fill the array
|
---|
| 443 | \sa Sequence
|
---|
| 444 | */
|
---|
[772] | 445 | template <class T>
|
---|
[1103] | 446 | TArray<T>& TArray<T>::SetSeq(Sequence const & seq)
|
---|
[772] | 447 | {
|
---|
[804] | 448 | if (NbDimensions() < 1)
|
---|
[813] | 449 | throw RangeCheckError("TArray<T>::SetSeq(Sequence ) - Not Allocated Array ! ");
|
---|
[1103] | 450 |
|
---|
[785] | 451 | T * pe;
|
---|
[1156] | 452 | sa_size_t j,k;
|
---|
| 453 | int_4 ka;
|
---|
[1103] | 454 | if (arrtype_ == 0) ka = 0;
|
---|
| 455 | else ka = macoli_;
|
---|
[1156] | 456 | sa_size_t step = Step(ka);
|
---|
| 457 | sa_size_t gpas = Size(ka);
|
---|
| 458 | sa_size_t naxa = Size()/Size(ka);
|
---|
[1103] | 459 | for(j=0; j<naxa; j++) {
|
---|
| 460 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[2153] | 461 | /*
|
---|
| 462 | Appel explicite de l'operateur de conversion
|
---|
| 463 | suite a la suggestion de M. Reinecke, Reza 31/7/2002
|
---|
[1103] | 464 | #if !defined(__GNUG__)
|
---|
| 465 | for(k=0; k<gpas; k++) pe[k*step] = (T) seq(j*gpas+k);
|
---|
| 466 | #else
|
---|
| 467 | // g++ (up to 2.95.1) se melange les pinceaux s'il y a le cast (T) pour l'instanciation des complexes
|
---|
| 468 | for(k=0; k<gpas; k++) pe[k*step] = seq(j*gpas+k);
|
---|
| 469 | #endif
|
---|
[2153] | 470 | --- Appel explicite de l'operateur de conversion sur l'objet MuTyV
|
---|
| 471 | */
|
---|
| 472 | for(k=0; k<gpas; k++) pe[k*step] = seq(j*gpas+k).operator T();
|
---|
[785] | 473 | }
|
---|
[772] | 474 | return(*this);
|
---|
| 475 | }
|
---|
| 476 |
|
---|
| 477 | // >>>> Operations avec 2nd membre de type scalaire
|
---|
| 478 |
|
---|
[894] | 479 | //! Fill an array with a constant value \b x
|
---|
[772] | 480 | template <class T>
|
---|
[813] | 481 | TArray<T>& TArray<T>::SetT(T x)
|
---|
[772] | 482 | {
|
---|
[804] | 483 | if (NbDimensions() < 1)
|
---|
[813] | 484 | throw RangeCheckError("TArray<T>::SetT(T ) - Not Allocated Array ! ");
|
---|
[785] | 485 | T * pe;
|
---|
[1156] | 486 | sa_size_t j,k;
|
---|
[785] | 487 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
[1156] | 488 | sa_size_t step = AvgStep();
|
---|
| 489 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 490 | pe = Data();
|
---|
| 491 | for(k=0; k<maxx; k+=step ) pe[k] = x;
|
---|
| 492 | }
|
---|
| 493 | else { // Non regular data spacing ...
|
---|
[1156] | 494 | int_4 ka = MaxSizeKA();
|
---|
| 495 | sa_size_t step = Step(ka);
|
---|
| 496 | sa_size_t gpas = Size(ka)*step;
|
---|
| 497 | sa_size_t naxa = Size()/Size(ka);
|
---|
[813] | 498 | for(j=0; j<naxa; j++) {
|
---|
| 499 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[785] | 500 | for(k=0; k<gpas; k+=step) pe[k] = x;
|
---|
| 501 | }
|
---|
| 502 | }
|
---|
[772] | 503 | return(*this);
|
---|
| 504 | }
|
---|
| 505 |
|
---|
[2564] | 506 | //! Add a constant value \b x to the source array and store the result in \b res.
|
---|
| 507 | /*!
|
---|
| 508 | Add a constant to the source array \b this and store the result in \b res (res = *this+x).
|
---|
| 509 | If not initially allocated, the output array \b res is automatically
|
---|
| 510 | resized as a packed array with the same sizes as the source (this) array.
|
---|
| 511 | Returns a reference to the output array \b res.
|
---|
| 512 | \param x : constant to add to the array elements
|
---|
| 513 | \param res : Output array containing the result (res=this+x).
|
---|
| 514 | */
|
---|
[772] | 515 | template <class T>
|
---|
[2564] | 516 | TArray<T>& TArray<T>::AddCst(T x, TArray<T>& res) const
|
---|
[772] | 517 | {
|
---|
[804] | 518 | if (NbDimensions() < 1)
|
---|
[2564] | 519 | throw RangeCheckError("TArray<T>::AddCst(T,res) - Not allocated source array ");
|
---|
| 520 | if (res.NbDimensions() < 1) res.SetSize(*this, true, false);
|
---|
| 521 | bool smo;
|
---|
| 522 | if (!CompareSizes(res, smo))
|
---|
| 523 | throw(SzMismatchError("TArray<T>::AddCst(T, res) SizeMismatch(this,res) ")) ;
|
---|
| 524 |
|
---|
| 525 | const T * pe;
|
---|
| 526 | T * per;
|
---|
| 527 | sa_size_t j,k,kr;
|
---|
| 528 | if (smo && (IsPacked() > 0) && (res.IsPacked() > 0)) { // regularly spaced elements
|
---|
| 529 | sa_size_t maxx = totsize_;
|
---|
[785] | 530 | pe = Data();
|
---|
[2564] | 531 | per = res.Data();
|
---|
| 532 | for(k=0; k<maxx; k++) { *per = (*pe)+x; per++; pe++; }
|
---|
[785] | 533 | }
|
---|
| 534 | else { // Non regular data spacing ...
|
---|
[2564] | 535 | int_4 ax,axr;
|
---|
| 536 | sa_size_t step, stepr;
|
---|
| 537 | sa_size_t gpas, naxr;
|
---|
| 538 | GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr);
|
---|
| 539 | for(j=0; j<naxr; j++) {
|
---|
| 540 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
| 541 | per = res.DataBlock().Begin()+res.Offset(axr,j);
|
---|
| 542 | for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = pe[k]+x;
|
---|
[785] | 543 | }
|
---|
| 544 | }
|
---|
[2564] | 545 | return(res);
|
---|
[772] | 546 | }
|
---|
| 547 |
|
---|
[2564] | 548 | //! Subtract a constant value \b x from the source array and store the result in \b res.
|
---|
[970] | 549 | /*!
|
---|
[2564] | 550 | Subtract a constant from the source array \b this and store the result in \b res (res = *this-x).
|
---|
| 551 | If not initially allocated, the output array \b res is automatically
|
---|
| 552 | resized as a packed array with the same sizes as the source (this) array.
|
---|
| 553 | Returns a reference to the output array \b res.
|
---|
| 554 | \param x : constant to subtract from the array elements
|
---|
| 555 | \param res : Output array containing the result (res=this+x or res=x-this).
|
---|
| 556 | \param fginv == true : Invert subtraction argument order (*this = x-(*this))
|
---|
[970] | 557 | */
|
---|
[772] | 558 | template <class T>
|
---|
[2564] | 559 | TArray<T>& TArray<T>::SubCst(T x, TArray<T>& res, bool fginv) const
|
---|
[772] | 560 | {
|
---|
[804] | 561 | if (NbDimensions() < 1)
|
---|
[2564] | 562 | throw RangeCheckError("TArray<T>::SubCst(T,res) - Not allocated source array ");
|
---|
| 563 | if (res.NbDimensions() < 1) res.SetSize(*this, true, false);
|
---|
| 564 | bool smo;
|
---|
| 565 | if (!CompareSizes(res, smo))
|
---|
| 566 | throw(SzMismatchError("TArray<T>::SubCst(T, res) SizeMismatch(this,res) ")) ;
|
---|
| 567 |
|
---|
| 568 | const T * pe;
|
---|
| 569 | T * per;
|
---|
| 570 | sa_size_t j,k,kr;
|
---|
| 571 | if (smo && (IsPacked() > 0) && (res.IsPacked() > 0)) { // regularly spaced elements
|
---|
| 572 | sa_size_t maxx = totsize_;
|
---|
[785] | 573 | pe = Data();
|
---|
[2564] | 574 | per = res.Data();
|
---|
| 575 | if (!fginv)
|
---|
| 576 | for(k=0; k<maxx; k++) { *per = (*pe)-x; per++; pe++; }
|
---|
| 577 | else
|
---|
| 578 | for(k=0; k<maxx; k++) { *per = x-(*pe); per++; pe++; }
|
---|
[785] | 579 | }
|
---|
| 580 | else { // Non regular data spacing ...
|
---|
[2564] | 581 | int_4 ax,axr;
|
---|
| 582 | sa_size_t step, stepr;
|
---|
| 583 | sa_size_t gpas, naxr;
|
---|
| 584 | GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr);
|
---|
| 585 | for(j=0; j<naxr; j++) {
|
---|
| 586 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
| 587 | per = res.DataBlock().Begin()+res.Offset(axr,j);
|
---|
| 588 | if (!fginv)
|
---|
| 589 | for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = pe[k]-x;
|
---|
[970] | 590 | else
|
---|
[2564] | 591 | for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = x-pe[k];
|
---|
[785] | 592 | }
|
---|
| 593 | }
|
---|
[2564] | 594 | return(res);
|
---|
[772] | 595 | }
|
---|
| 596 |
|
---|
[2564] | 597 | //! Multiply the source array by a constant value \b x and store the result in \b res.
|
---|
| 598 | /*!
|
---|
| 599 | Multiply the source array \b this by a constant \b x and store the result in \b res (res = *this*x).
|
---|
| 600 | If not initially allocated, the output array \b res is automatically
|
---|
| 601 | resized as a packed array with the same sizes as the source (this) array.
|
---|
| 602 | Returns a reference to the output array \b res.
|
---|
| 603 | \param x : Array elements are multiplied by x
|
---|
| 604 | \param res : Output array containing the result (res=this*x).
|
---|
| 605 | */
|
---|
[772] | 606 | template <class T>
|
---|
[2564] | 607 | TArray<T>& TArray<T>::MulCst(T x, TArray<T>& res) const
|
---|
[772] | 608 | {
|
---|
[804] | 609 | if (NbDimensions() < 1)
|
---|
[2564] | 610 | throw RangeCheckError("TArray<T>::MulCst(T,res) - Not allocated source array ");
|
---|
| 611 | if (res.NbDimensions() < 1) res.SetSize(*this, true, false);
|
---|
| 612 | bool smo;
|
---|
| 613 | if (!CompareSizes(res, smo))
|
---|
| 614 | throw(SzMismatchError("TArray<T>::MulCst(T, res) SizeMismatch(this,res) ")) ;
|
---|
| 615 |
|
---|
| 616 | const T * pe;
|
---|
| 617 | T * per;
|
---|
| 618 | sa_size_t j,k,kr;
|
---|
| 619 | if (smo && (IsPacked() > 0) && (res.IsPacked() > 0)) { // regularly spaced elements
|
---|
| 620 | sa_size_t maxx = totsize_;
|
---|
[785] | 621 | pe = Data();
|
---|
[2564] | 622 | per = res.Data();
|
---|
| 623 | for(k=0; k<maxx; k++) { *per = (*pe)*x; per++; pe++; }
|
---|
[785] | 624 | }
|
---|
| 625 | else { // Non regular data spacing ...
|
---|
[2564] | 626 | int_4 ax,axr;
|
---|
| 627 | sa_size_t step, stepr;
|
---|
| 628 | sa_size_t gpas, naxr;
|
---|
| 629 | GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr);
|
---|
| 630 | for(j=0; j<naxr; j++) {
|
---|
| 631 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
| 632 | per = res.DataBlock().Begin()+res.Offset(axr,j);
|
---|
| 633 | for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = pe[k]*x;
|
---|
[785] | 634 | }
|
---|
| 635 | }
|
---|
[2564] | 636 | return(res);
|
---|
[772] | 637 | }
|
---|
| 638 |
|
---|
[2564] | 639 | //! Divide the source array by a constant value \b x and store the result in \b res.
|
---|
[970] | 640 | /*!
|
---|
[2564] | 641 | Divide the source array \b this by a constant \b x and store the result in \b res (res = *this/x).
|
---|
| 642 | If not initially allocated, the output array \b res is automatically
|
---|
| 643 | resized as a packed array with the same sizes as the source (this) array.
|
---|
| 644 | Returns a reference to the output array \b res.
|
---|
| 645 | \param x : Array elements are divied by x
|
---|
| 646 | \param res : Output array containing the result (res=(*this)/x or res=x/(*this)).
|
---|
| 647 | \param fginv == true : Invert the operation order (res = x/(*this))
|
---|
[970] | 648 | */
|
---|
[772] | 649 | template <class T>
|
---|
[2564] | 650 | TArray<T>& TArray<T>::DivCst(T x, TArray<T>& res, bool fginv) const
|
---|
[772] | 651 | {
|
---|
[804] | 652 | if (NbDimensions() < 1)
|
---|
[2564] | 653 | throw RangeCheckError("TArray<T>::DivCst(T,res) - Not allocated source array ! ");
|
---|
[970] | 654 | if (!fginv && (x == (T) 0) )
|
---|
[2564] | 655 | throw MathExc("TArray<T>::DivCst(T,res) - Divide by zero ! ");
|
---|
| 656 | if (res.NbDimensions() < 1) res.SetSize(*this, true, false);
|
---|
| 657 | bool smo;
|
---|
| 658 | if (!CompareSizes(res, smo))
|
---|
| 659 | throw(SzMismatchError("TArray<T>::DivCst(T, res) SizeMismatch(this,res) ")) ;
|
---|
| 660 |
|
---|
| 661 | const T * pe;
|
---|
| 662 | T * per;
|
---|
| 663 | sa_size_t j,k,kr;
|
---|
| 664 | if (smo && (IsPacked() > 0) && (res.IsPacked() > 0)) { // regularly spaced elements
|
---|
| 665 | sa_size_t maxx = totsize_;
|
---|
[785] | 666 | pe = Data();
|
---|
[2564] | 667 | per = res.Data();
|
---|
| 668 | if (!fginv)
|
---|
| 669 | for(k=0; k<maxx; k++) { *per = (*pe)/x; per++; pe++; }
|
---|
[970] | 670 | else
|
---|
[2564] | 671 | for(k=0; k<maxx; k++) { *per = x/(*pe); per++; pe++; }
|
---|
[785] | 672 | }
|
---|
| 673 | else { // Non regular data spacing ...
|
---|
[2564] | 674 | int_4 ax,axr;
|
---|
| 675 | sa_size_t step, stepr;
|
---|
| 676 | sa_size_t gpas, naxr;
|
---|
| 677 | GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr);
|
---|
| 678 | for(j=0; j<naxr; j++) {
|
---|
| 679 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
| 680 | per = res.DataBlock().Begin()+res.Offset(axr,j);
|
---|
| 681 | if (!fginv)
|
---|
| 682 | for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = pe[k]/x;
|
---|
| 683 | else
|
---|
| 684 | for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = x/pe[k];
|
---|
[785] | 685 | }
|
---|
| 686 | }
|
---|
[2564] | 687 | return(res);
|
---|
[772] | 688 | }
|
---|
| 689 |
|
---|
| 690 |
|
---|
[2564] | 691 | //! Stores the opposite of the source array in \b res (res=-(*this)).
|
---|
| 692 | /*!
|
---|
| 693 | If not initially allocated, the output array \b res is automatically
|
---|
| 694 | resized as a packed array with the same sizes as the source (this) array.
|
---|
| 695 | Returns a reference to the output array \b res.
|
---|
| 696 | */
|
---|
[1156] | 697 | template <class T>
|
---|
[2564] | 698 | TArray<T>& TArray<T>::NegateElt(TArray<T>& res) const
|
---|
[1156] | 699 | {
|
---|
| 700 | if (NbDimensions() < 1)
|
---|
[2564] | 701 | throw RangeCheckError("TArray<T>::NegateElt(res) - Not allocated source array ");
|
---|
| 702 | if (res.NbDimensions() < 1) res.SetSize(*this, true, false);
|
---|
| 703 | bool smo;
|
---|
| 704 | if (!CompareSizes(res, smo))
|
---|
| 705 | throw(SzMismatchError("TArray<T>::NegateElt(res) SizeMismatch(this,res) ")) ;
|
---|
| 706 |
|
---|
| 707 | const T * pe;
|
---|
| 708 | T * per;
|
---|
| 709 | sa_size_t j,k,kr;
|
---|
| 710 | if (smo && (IsPacked() > 0) && (res.IsPacked() > 0)) { // regularly spaced elements
|
---|
| 711 | sa_size_t maxx = totsize_;
|
---|
[1156] | 712 | pe = Data();
|
---|
[2564] | 713 | per = res.Data();
|
---|
| 714 | for(k=0; k<maxx; k++) { *per = -(*pe); per++; pe++; }
|
---|
[1156] | 715 | }
|
---|
| 716 | else { // Non regular data spacing ...
|
---|
[2564] | 717 | int_4 ax,axr;
|
---|
| 718 | sa_size_t step, stepr;
|
---|
| 719 | sa_size_t gpas, naxr;
|
---|
| 720 | GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr);
|
---|
| 721 | for(j=0; j<naxr; j++) {
|
---|
| 722 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
| 723 | per = res.DataBlock().Begin()+res.Offset(axr,j);
|
---|
| 724 | for(k=0, kr=0; k<gpas; k+=step, kr+=stepr) per[kr] = -pe[k];
|
---|
[1156] | 725 | }
|
---|
| 726 | }
|
---|
[2564] | 727 | return(res);
|
---|
[1156] | 728 | }
|
---|
[804] | 729 |
|
---|
[772] | 730 | // >>>> Operations avec 2nd membre de type tableau
|
---|
[894] | 731 | //! Add two TArrays
|
---|
[772] | 732 | template <class T>
|
---|
[804] | 733 | TArray<T>& TArray<T>::AddElt(const TArray<T>& a)
|
---|
[772] | 734 | {
|
---|
[804] | 735 | if (NbDimensions() < 1)
|
---|
| 736 | throw RangeCheckError("TArray<T>::AddElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 737 | bool smo;
|
---|
| 738 | if (!CompareSizes(a, smo))
|
---|
[813] | 739 | throw(SzMismatchError("TArray<T>::AddElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[785] | 740 |
|
---|
| 741 | T * pe;
|
---|
| 742 | const T * pea;
|
---|
[1156] | 743 | sa_size_t j,k,ka;
|
---|
[1099] | 744 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0)) { // regularly spaced elements
|
---|
[1156] | 745 | sa_size_t step = AvgStep();
|
---|
| 746 | sa_size_t stepa = a.AvgStep();
|
---|
| 747 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 748 | pe = Data();
|
---|
| 749 | pea = a.Data();
|
---|
| 750 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] += pea[ka] ;
|
---|
[772] | 751 | }
|
---|
[785] | 752 | else { // Non regular data spacing ...
|
---|
[1156] | 753 | int_4 ax,axa;
|
---|
| 754 | sa_size_t step, stepa;
|
---|
| 755 | sa_size_t gpas, naxa;
|
---|
[1099] | 756 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 757 | for(j=0; j<naxa; j++) {
|
---|
| 758 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 759 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[785] | 760 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] += pea[ka];
|
---|
| 761 | }
|
---|
| 762 | }
|
---|
[772] | 763 | return(*this);
|
---|
| 764 | }
|
---|
| 765 |
|
---|
[894] | 766 | //! Substract two TArrays
|
---|
[970] | 767 | /*!
|
---|
| 768 | Substract two TArrays *this = *this-a
|
---|
| 769 | \param fginv == true : Perfoms the inverse subtraction (*this = a-(*this))
|
---|
| 770 | */
|
---|
[772] | 771 | template <class T>
|
---|
[970] | 772 | TArray<T>& TArray<T>::SubElt(const TArray<T>& a, bool fginv)
|
---|
[772] | 773 | {
|
---|
[804] | 774 | if (NbDimensions() < 1)
|
---|
| 775 | throw RangeCheckError("TArray<T>::SubElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 776 | bool smo;
|
---|
| 777 | if (!CompareSizes(a, smo))
|
---|
[813] | 778 | throw(SzMismatchError("TArray<T>::SubElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[785] | 779 |
|
---|
| 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;
|
---|
[785] | 787 | pe = Data();
|
---|
| 788 | pea = a.Data();
|
---|
[970] | 789 | if (fginv)
|
---|
| 790 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] = pea[ka]-pe[k] ;
|
---|
| 791 | else
|
---|
| 792 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] -= pea[ka] ;
|
---|
[772] | 793 | }
|
---|
[785] | 794 | else { // Non regular data spacing ...
|
---|
[1156] | 795 | int_4 ax,axa;
|
---|
| 796 | sa_size_t step, stepa;
|
---|
| 797 | sa_size_t gpas, naxa;
|
---|
[1099] | 798 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 799 | for(j=0; j<naxa; j++) {
|
---|
| 800 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 801 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[970] | 802 | if (fginv)
|
---|
| 803 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka]-pe[k] ;
|
---|
| 804 | else
|
---|
| 805 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] -= pea[ka];
|
---|
[785] | 806 | }
|
---|
| 807 | }
|
---|
[772] | 808 | return(*this);
|
---|
| 809 | }
|
---|
| 810 |
|
---|
[970] | 811 |
|
---|
[894] | 812 | //! Multiply two TArrays (elements by elements)
|
---|
[772] | 813 | template <class T>
|
---|
[804] | 814 | TArray<T>& TArray<T>::MulElt(const TArray<T>& a)
|
---|
[772] | 815 | {
|
---|
[804] | 816 | if (NbDimensions() < 1)
|
---|
| 817 | throw RangeCheckError("TArray<T>::MulElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 818 | bool smo;
|
---|
| 819 | if (!CompareSizes(a, smo))
|
---|
[813] | 820 | throw(SzMismatchError("TArray<T>::MulElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[785] | 821 |
|
---|
| 822 | T * pe;
|
---|
| 823 | const T * pea;
|
---|
[1156] | 824 | sa_size_t j,k,ka;
|
---|
[1099] | 825 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0) ) { // regularly spaced elements
|
---|
[1156] | 826 | sa_size_t step = AvgStep();
|
---|
| 827 | sa_size_t stepa = a.AvgStep();
|
---|
| 828 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 829 | pe = Data();
|
---|
| 830 | pea = a.Data();
|
---|
| 831 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] *= pea[ka] ;
|
---|
[772] | 832 | }
|
---|
[785] | 833 | else { // Non regular data spacing ...
|
---|
[1156] | 834 | int_4 ax,axa;
|
---|
| 835 | sa_size_t step, stepa;
|
---|
| 836 | sa_size_t gpas, naxa;
|
---|
[1099] | 837 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 838 | for(j=0; j<naxa; j++) {
|
---|
[1099] | 839 | pe = mNDBlock.Begin()+Offset(axa,j);
|
---|
| 840 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[785] | 841 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] *= pea[ka];
|
---|
| 842 | }
|
---|
| 843 | }
|
---|
[772] | 844 | return(*this);
|
---|
| 845 | }
|
---|
| 846 |
|
---|
[804] | 847 |
|
---|
[894] | 848 | //! Divide two TArrays (elements by elements)
|
---|
[970] | 849 | /*!
|
---|
| 850 | Divide two TArrays *this = (*this)/a
|
---|
| 851 | \param fginv == true : Perfoms the inverse division (*this = a/(*this))
|
---|
[1072] | 852 | \param divzero == true : if a(i)==0. result is set to zero: (*this)(i)==0.
|
---|
[970] | 853 | */
|
---|
[772] | 854 | template <class T>
|
---|
[1072] | 855 | TArray<T>& TArray<T>::DivElt(const TArray<T>& a, bool fginv, bool divzero)
|
---|
[772] | 856 | {
|
---|
[804] | 857 | if (NbDimensions() < 1)
|
---|
| 858 | throw RangeCheckError("TArray<T>::DivElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 859 | bool smo;
|
---|
| 860 | if (!CompareSizes(a, smo))
|
---|
[813] | 861 | throw(SzMismatchError("TArray<T>::DivElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[785] | 862 |
|
---|
| 863 | T * pe;
|
---|
| 864 | const T * pea;
|
---|
[1156] | 865 | sa_size_t j,k,ka;
|
---|
[1099] | 866 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0) ) { // regularly spaced elements
|
---|
[1156] | 867 | sa_size_t step = AvgStep();
|
---|
| 868 | sa_size_t stepa = a.AvgStep();
|
---|
| 869 | sa_size_t maxx = totsize_*step;
|
---|
[785] | 870 | pe = Data();
|
---|
| 871 | pea = a.Data();
|
---|
[1072] | 872 | if(divzero) {
|
---|
| 873 | if (fginv)
|
---|
| 874 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa )
|
---|
| 875 | {if(pe[k]==(T)0) pe[k] = (T)0; else pe[k] = pea[ka]/pe[k];}
|
---|
| 876 | else
|
---|
| 877 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa )
|
---|
| 878 | {if(pea[k]==(T)0) pe[k] = (T)0; else pe[k] /= pea[ka] ;}
|
---|
| 879 | } else {
|
---|
| 880 | if (fginv)
|
---|
| 881 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] = pea[ka]/pe[k];
|
---|
| 882 | else
|
---|
| 883 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] /= pea[ka] ;
|
---|
| 884 | }
|
---|
[772] | 885 | }
|
---|
[785] | 886 | else { // Non regular data spacing ...
|
---|
[1156] | 887 | int_4 ax,axa;
|
---|
| 888 | sa_size_t step, stepa;
|
---|
| 889 | sa_size_t gpas, naxa;
|
---|
[1099] | 890 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 891 | for(j=0; j<naxa; j++) {
|
---|
| 892 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 893 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[1072] | 894 | if(divzero) {
|
---|
| 895 | if (fginv)
|
---|
| 896 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa)
|
---|
| 897 | {if(pe[k]==(T)0) pe[k] = (T)0; else pe[k] = pea[ka]/pe[k];}
|
---|
| 898 | else
|
---|
| 899 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa)
|
---|
| 900 | {if(pea[k]==(T)0) pe[k] = (T)0; else pe[k] /= pea[ka];}
|
---|
| 901 | } else {
|
---|
| 902 | if (fginv)
|
---|
| 903 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka]/pe[k];
|
---|
| 904 | else
|
---|
| 905 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] /= pea[ka];
|
---|
| 906 | }
|
---|
[785] | 907 | }
|
---|
| 908 | }
|
---|
[772] | 909 | return(*this);
|
---|
| 910 | }
|
---|
| 911 |
|
---|
[894] | 912 | //! Copy elements of \b a
|
---|
[804] | 913 | template <class T>
|
---|
| 914 | TArray<T>& TArray<T>::CopyElt(const TArray<T>& a)
|
---|
| 915 | {
|
---|
| 916 | if (NbDimensions() < 1)
|
---|
| 917 | throw RangeCheckError("TArray<T>::CopyElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 918 | bool smo;
|
---|
| 919 | if (!CompareSizes(a, smo))
|
---|
[1050] | 920 | throw(SzMismatchError("TArray<T>::CopyElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[772] | 921 |
|
---|
[804] | 922 | T * pe;
|
---|
| 923 | const T * pea;
|
---|
[1156] | 924 | sa_size_t j,k,ka;
|
---|
[1099] | 925 | if (smo && (AvgStep() > 0) && (a.AvgStep() > 0) ) { // regularly spaced elements
|
---|
[1156] | 926 | sa_size_t step = AvgStep();
|
---|
| 927 | sa_size_t stepa = a.AvgStep();
|
---|
| 928 | sa_size_t maxx = totsize_*step;
|
---|
[804] | 929 | pe = Data();
|
---|
| 930 | pea = a.Data();
|
---|
| 931 | for(k=0, ka=0; k<maxx; k+=step, ka+=stepa ) pe[k] = pea[ka] ;
|
---|
| 932 | }
|
---|
| 933 | else { // Non regular data spacing ...
|
---|
[1156] | 934 | int_4 ax,axa;
|
---|
| 935 | sa_size_t step, stepa;
|
---|
| 936 | sa_size_t gpas, naxa;
|
---|
[1099] | 937 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[813] | 938 | for(j=0; j<naxa; j++) {
|
---|
| 939 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 940 | pea = a.DataBlock().Begin()+a.Offset(axa,j);
|
---|
[804] | 941 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka];
|
---|
| 942 | }
|
---|
| 943 | }
|
---|
| 944 | return(*this);
|
---|
| 945 | }
|
---|
| 946 |
|
---|
[1081] | 947 | //! Converts and Copy elements of \b a
|
---|
| 948 | template <class T>
|
---|
| 949 | TArray<T>& TArray<T>::ConvertAndCopyElt(const BaseArray& a)
|
---|
| 950 | {
|
---|
| 951 | if (NbDimensions() < 1)
|
---|
| 952 | throw RangeCheckError("TArray<T>::ConvertAndCopyElt(const TArray<T>& ) - Not Allocated Array ! ");
|
---|
[1099] | 953 | bool smo;
|
---|
| 954 | if (!CompareSizes(a, smo))
|
---|
[1081] | 955 | throw(SzMismatchError("TArray<T>::ConvertAndCopyElt(const TArray<T>&) SizeMismatch")) ;
|
---|
[804] | 956 |
|
---|
[1081] | 957 | T * pe;
|
---|
[1156] | 958 | sa_size_t j,k,ka;
|
---|
| 959 | sa_size_t offa;
|
---|
[1081] | 960 | // Non regular data spacing ...
|
---|
[1156] | 961 | int_4 ax,axa;
|
---|
| 962 | sa_size_t step, stepa;
|
---|
| 963 | sa_size_t gpas, naxa;
|
---|
[1099] | 964 | GetOpeParams(a, smo, ax, axa, step, stepa, gpas, naxa);
|
---|
[1081] | 965 | for(j=0; j<naxa; j++) {
|
---|
| 966 | pe = mNDBlock.Begin()+Offset(ax,j);
|
---|
[1099] | 967 | offa = a.Offset(axa,j);
|
---|
[2147] | 968 | /*
|
---|
| 969 | Appel explicite de l'operateur de conversion
|
---|
| 970 | suite a la suggestion de M. Reinecke, Reza 31/7/2002
|
---|
[1085] | 971 | #if !defined(__GNUG__)
|
---|
| 972 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = (T)a.ValueAtPosition(offa+ka);
|
---|
| 973 | #else
|
---|
| 974 | // g++ (up to 2.95.1) se melange les pinceaux s'il y a le cast (T) pour l'instanciation des complexes
|
---|
[1081] | 975 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = a.ValueAtPosition(offa+ka);
|
---|
[1085] | 976 | #endif
|
---|
[2147] | 977 | --- Appel explicite de l'operateur de conversion sur l'objet MuTyV
|
---|
| 978 | */
|
---|
| 979 | for(k=0, ka=0; k<gpas; k+=step, ka+=stepa)
|
---|
| 980 | pe[k] = a.ValueAtPosition(offa+ka).operator T();
|
---|
[1081] | 981 | }
|
---|
| 982 | return(*this);
|
---|
| 983 | }
|
---|
| 984 |
|
---|
| 985 |
|
---|
[804] | 986 | // Somme et produit des elements
|
---|
[894] | 987 | //! Sum all elements
|
---|
[804] | 988 | template <class T>
|
---|
| 989 | T TArray<T>::Sum() const
|
---|
| 990 | {
|
---|
| 991 | if (NbDimensions() < 1)
|
---|
| 992 | throw RangeCheckError("TArray<T>::Sum() - Not Allocated Array ! ");
|
---|
| 993 | T ret=0;
|
---|
| 994 | const T * pe;
|
---|
[1156] | 995 | sa_size_t j,k;
|
---|
[804] | 996 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
[1156] | 997 | sa_size_t step = AvgStep();
|
---|
| 998 | sa_size_t maxx = totsize_*step;
|
---|
[804] | 999 | pe = Data();
|
---|
| 1000 | for(k=0; k<maxx; k+=step ) ret += pe[k];
|
---|
| 1001 | }
|
---|
| 1002 | else { // Non regular data spacing ...
|
---|
[1156] | 1003 | int_4 ka = MaxSizeKA();
|
---|
| 1004 | sa_size_t step = Step(ka);
|
---|
| 1005 | sa_size_t gpas = Size(ka)*step;
|
---|
| 1006 | sa_size_t naxa = Size()/Size(ka);
|
---|
[813] | 1007 | for(j=0; j<naxa; j++) {
|
---|
| 1008 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[804] | 1009 | for(k=0; k<gpas; k+=step) ret += pe[k] ;
|
---|
| 1010 | }
|
---|
| 1011 | }
|
---|
| 1012 | return ret;
|
---|
| 1013 | }
|
---|
| 1014 |
|
---|
[894] | 1015 | //! Multiply all elements
|
---|
[804] | 1016 | template <class T>
|
---|
| 1017 | T TArray<T>::Product() const
|
---|
| 1018 | {
|
---|
| 1019 | if (NbDimensions() < 1)
|
---|
| 1020 | throw RangeCheckError("TArray<T>::Product() - Not Allocated Array ! ");
|
---|
[1113] | 1021 | T ret=(T)1;
|
---|
[804] | 1022 | const T * pe;
|
---|
[1156] | 1023 | sa_size_t j,k;
|
---|
[804] | 1024 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
[1156] | 1025 | sa_size_t step = AvgStep();
|
---|
| 1026 | sa_size_t maxx = totsize_*step;
|
---|
[804] | 1027 | pe = Data();
|
---|
| 1028 | for(k=0; k<maxx; k+=step ) ret *= pe[k];
|
---|
| 1029 | }
|
---|
| 1030 | else { // Non regular data spacing ...
|
---|
[1156] | 1031 | int_4 ka = MaxSizeKA();
|
---|
| 1032 | sa_size_t step = Step(ka);
|
---|
| 1033 | sa_size_t gpas = Size(ka)*step;
|
---|
| 1034 | sa_size_t naxa = Size()/Size(ka);
|
---|
[813] | 1035 | for(j=0; j<naxa; j++) {
|
---|
| 1036 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
[804] | 1037 | for(k=0; k<gpas; k+=step) ret *= pe[k] ;
|
---|
| 1038 | }
|
---|
| 1039 | }
|
---|
| 1040 | return ret;
|
---|
| 1041 | }
|
---|
| 1042 |
|
---|
[1113] | 1043 | //! Returns the sum of all elements squared (Sum
|
---|
| 1044 | template <class T>
|
---|
| 1045 | T TArray<T>::SumX2() const
|
---|
| 1046 | {
|
---|
| 1047 | if (NbDimensions() < 1)
|
---|
| 1048 | throw RangeCheckError("TArray<T>::SumX2() - Not Allocated Array ! ");
|
---|
| 1049 | T ret=0;
|
---|
| 1050 | const T * pe;
|
---|
[1156] | 1051 | sa_size_t j,k;
|
---|
[1113] | 1052 | if (AvgStep() > 0) { // regularly spaced elements
|
---|
[1156] | 1053 | sa_size_t step = AvgStep();
|
---|
| 1054 | sa_size_t maxx = totsize_*step;
|
---|
[1113] | 1055 | pe = Data();
|
---|
| 1056 | for(k=0; k<maxx; k+=step ) ret += pe[k]*pe[k];
|
---|
| 1057 | }
|
---|
| 1058 | else { // Non regular data spacing ...
|
---|
[1156] | 1059 | int_4 ka = MaxSizeKA();
|
---|
| 1060 | sa_size_t step = Step(ka);
|
---|
| 1061 | sa_size_t gpas = Size(ka)*step;
|
---|
| 1062 | sa_size_t naxa = Size()/Size(ka);
|
---|
[1113] | 1063 | for(j=0; j<naxa; j++) {
|
---|
| 1064 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
| 1065 | for(k=0; k<gpas; k+=step) ret += pe[k]*pe[k] ;
|
---|
| 1066 | }
|
---|
| 1067 | }
|
---|
| 1068 | return ret;
|
---|
| 1069 | }
|
---|
[804] | 1070 |
|
---|
[1113] | 1071 | //! Return the minimum and the maximum values of the array elements
|
---|
| 1072 | /*!
|
---|
| 1073 | This method generates an exception (\c MathExc) if called for complex arrays
|
---|
| 1074 | */
|
---|
[2338] | 1075 |
|
---|
[1113] | 1076 | template <class T>
|
---|
| 1077 | void TArray<T>::MinMax(T& min, T& max) const
|
---|
| 1078 | {
|
---|
| 1079 | const T * pe;
|
---|
[1156] | 1080 | sa_size_t j,k;
|
---|
| 1081 | int_4 ka = MaxSizeKA();
|
---|
| 1082 | sa_size_t step = Step(ka);
|
---|
| 1083 | sa_size_t gpas = Size(ka)*step;
|
---|
| 1084 | sa_size_t naxa = Size()/Size(ka);
|
---|
[1113] | 1085 | min = (*this)[0];
|
---|
| 1086 | max = (*this)[0];
|
---|
| 1087 | for(j=0; j<naxa; j++) {
|
---|
| 1088 | pe = mNDBlock.Begin()+Offset(ka,j);
|
---|
| 1089 | for(k=0; k<gpas; k+=step) {
|
---|
| 1090 | if (pe[k]<min) min = pe[k];
|
---|
| 1091 | else if (pe[k]>max) max = pe[k];
|
---|
| 1092 | }
|
---|
| 1093 | }
|
---|
| 1094 | return;
|
---|
| 1095 | }
|
---|
[804] | 1096 |
|
---|
[2338] | 1097 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[1113] | 1098 | void TArray< complex<r_4> >::MinMax(complex<r_4>& min, complex<r_4>& max) const
|
---|
| 1099 | {
|
---|
| 1100 | throw MathExc("TArray< complex<r_4> >::MinMax(...) - No order in complex");
|
---|
| 1101 | }
|
---|
[2338] | 1102 | DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
|
---|
[1113] | 1103 | void TArray< complex<r_8> >::MinMax(complex<r_8>& min, complex<r_8>& max) const
|
---|
| 1104 | {
|
---|
| 1105 | throw MathExc("TArray< complex<r_4> >::MinMax(...) - No order in complex");
|
---|
| 1106 | }
|
---|
| 1107 |
|
---|
[2338] | 1108 |
|
---|
[772] | 1109 | // ----------------------------------------------------
|
---|
| 1110 | // Impression, etc ...
|
---|
| 1111 | // ----------------------------------------------------
|
---|
| 1112 |
|
---|
[894] | 1113 | //! Return a string that contain the type \b T of the array
|
---|
[772] | 1114 | template <class T>
|
---|
[813] | 1115 | string TArray<T>::InfoString() const
|
---|
[772] | 1116 | {
|
---|
[813] | 1117 | string rs = "TArray<" ;
|
---|
| 1118 | rs += typeid(T).name();
|
---|
| 1119 | rs += "> ";
|
---|
[787] | 1120 | return(rs);
|
---|
[772] | 1121 | }
|
---|
| 1122 |
|
---|
[894] | 1123 | //! Print array
|
---|
| 1124 | /*!
|
---|
| 1125 | \param os : output stream
|
---|
| 1126 | \param maxprt : maximum numer of print
|
---|
| 1127 | \param si : if true, display attached DvList
|
---|
[1550] | 1128 | \param ascd : if true, suppresses the display of line numbers,
|
---|
| 1129 | suitable for ascii dump format.
|
---|
[894] | 1130 | \sa SetMaxPrint
|
---|
[1550] | 1131 | \sa WriteASCII
|
---|
[894] | 1132 | */
|
---|
[772] | 1133 | template <class T>
|
---|
[1550] | 1134 | void TArray<T>::Print(ostream& os, sa_size_t maxprt, bool si, bool ascd) const
|
---|
[772] | 1135 | {
|
---|
| 1136 | if (maxprt < 0) maxprt = max_nprt_;
|
---|
[1156] | 1137 | sa_size_t npr = 0;
|
---|
[772] | 1138 | Show(os, si);
|
---|
[850] | 1139 | if (ndim_ < 1) return;
|
---|
[1156] | 1140 | sa_size_t k0,k1,k2,k3,k4;
|
---|
[772] | 1141 | for(k4=0; k4<size_[4]; k4++) {
|
---|
[1550] | 1142 | if ((size_[4] > 1) && ascd)
|
---|
| 1143 | cout << "\n ----- Dimension 5 (U) K4= " << k4 << endl;
|
---|
[772] | 1144 | for(k3=0; k3<size_[3]; k3++) {
|
---|
[1550] | 1145 | if ((size_[3] > 1) && ascd)
|
---|
| 1146 | cout << "\n ----- Dimension 4 (T) K3= " << k3 << endl;
|
---|
[772] | 1147 | for(k2=0; k2<size_[2]; k2++) {
|
---|
[1550] | 1148 | if ((size_[2] > 1) & ascd)
|
---|
| 1149 | cout << "\n ----- Dimension 3 (Z) K2= " << k2 << endl;
|
---|
[772] | 1150 | for(k1=0; k1<size_[1]; k1++) {
|
---|
[1550] | 1151 | if ( (size_[1] > 1) && (size_[0] > 10) && ascd)
|
---|
| 1152 | cout << "----- Dimension 2 (Y) K1= " << k1 << endl;
|
---|
[772] | 1153 | for(k0=0; k0<size_[0]; k0++) {
|
---|
[1550] | 1154 | if(k0 > 0) os << " ";
|
---|
[785] | 1155 | os << Elem(k0, k1, k2, k3, k4); npr++;
|
---|
[1156] | 1156 | if (npr >= (sa_size_t) maxprt) {
|
---|
[772] | 1157 | if (npr < totsize_) os << "\n .... " << endl; return;
|
---|
| 1158 | }
|
---|
| 1159 | }
|
---|
| 1160 | os << endl;
|
---|
| 1161 | }
|
---|
| 1162 | }
|
---|
| 1163 | }
|
---|
| 1164 | }
|
---|
[813] | 1165 | os << endl;
|
---|
[772] | 1166 | }
|
---|
| 1167 |
|
---|
[1517] | 1168 | //! Fill the array, decoding the ASCII input stream
|
---|
| 1169 | /*!
|
---|
| 1170 | \param is : input stream (ASCII)
|
---|
[1558] | 1171 | \param nr : Number of non empty (or comment) lines in stream (return value)
|
---|
| 1172 | \param nc : Number of columns (= ntot/nlines) (return value)
|
---|
[2286] | 1173 | \param clm : Lines starting with clm character are treated as comment lines
|
---|
| 1174 | \param sep : word separator in lines
|
---|
[1558] | 1175 | \return Number of decoded elements
|
---|
[2286] | 1176 | */
|
---|
[1517] | 1177 | template <class T>
|
---|
[2286] | 1178 | sa_size_t TArray<T>::ReadASCII(istream& is, sa_size_t & nr, sa_size_t & nc,
|
---|
| 1179 | char clm, const char* sep)
|
---|
[1517] | 1180 | {
|
---|
[1550] | 1181 | EnumeratedSequence es;
|
---|
[2286] | 1182 | sa_size_t n = es.FillFromFile(is, nr, nc, clm, sep);
|
---|
[1558] | 1183 | if ( (n < 1) || (nr < 1) || (nc < 1) ) return(n);
|
---|
| 1184 | if (!IsAllocated()) {
|
---|
| 1185 | sa_size_t sz[2];
|
---|
| 1186 | if (arrtype_ == 2) { // C'est un vecteur
|
---|
| 1187 | sz[0] = sz[1] = 1;
|
---|
| 1188 | sz[veceli_] = n;
|
---|
| 1189 | }
|
---|
| 1190 | else {
|
---|
| 1191 | sz[RowsKA()] = nr;
|
---|
| 1192 | sz[ColsKA()] = nc;
|
---|
| 1193 | }
|
---|
| 1194 | ReSize(2, sz);
|
---|
| 1195 | }
|
---|
| 1196 | SetSeq(es);
|
---|
| 1197 | cout << "TArray<T>::ReadASCII()/Info: " << n << " elements read from stream "
|
---|
| 1198 | << " (Row,Col= " << nr << "," << nc << ")" << endl;
|
---|
| 1199 | return(n);
|
---|
[1517] | 1200 | }
|
---|
[772] | 1201 |
|
---|
[1517] | 1202 | //! Writes the array content to the output stream, (in ASCII)
|
---|
| 1203 | /*!
|
---|
| 1204 | \param os : output stream (ASCII)
|
---|
[1558] | 1205 | \sa Print
|
---|
[1517] | 1206 | */
|
---|
| 1207 | template <class T>
|
---|
| 1208 | void TArray<T>::WriteASCII(ostream& os) const
|
---|
| 1209 | {
|
---|
[1550] | 1210 | Print(os, Size(), false, true);
|
---|
[1517] | 1211 | }
|
---|
[772] | 1212 |
|
---|
[1517] | 1213 |
|
---|
| 1214 |
|
---|
[772] | 1215 | ///////////////////////////////////////////////////////////////
|
---|
| 1216 | ///////////////////////////////////////////////////////////////
|
---|
| 1217 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
[804] | 1218 | /*
|
---|
[772] | 1219 | #pragma define_template TArray<uint_1>
|
---|
[804] | 1220 | #pragma define_template TArray<int_2>
|
---|
| 1221 | #pragma define_template TArray<uint_4>
|
---|
| 1222 | */
|
---|
[772] | 1223 | #pragma define_template TArray<uint_2>
|
---|
[1543] | 1224 | #pragma define_template TArray<uint_8>
|
---|
[772] | 1225 | #pragma define_template TArray<int_4>
|
---|
| 1226 | #pragma define_template TArray<int_8>
|
---|
| 1227 | #pragma define_template TArray<r_4>
|
---|
| 1228 | #pragma define_template TArray<r_8>
|
---|
| 1229 | #pragma define_template TArray< complex<r_4> >
|
---|
| 1230 | #pragma define_template TArray< complex<r_8> >
|
---|
| 1231 | #endif
|
---|
| 1232 |
|
---|
| 1233 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
[804] | 1234 | /*
|
---|
| 1235 | template class TArray<uint_1>;
|
---|
| 1236 | template class TArray<int_2>;
|
---|
| 1237 | template class TArray<uint_4>;
|
---|
| 1238 | */
|
---|
[772] | 1239 | template class TArray<uint_2>;
|
---|
[1543] | 1240 | template class TArray<uint_8>;
|
---|
[772] | 1241 | template class TArray<int_4>;
|
---|
| 1242 | template class TArray<int_8>;
|
---|
| 1243 | template class TArray<r_4>;
|
---|
| 1244 | template class TArray<r_8>;
|
---|
| 1245 | template class TArray< complex<r_4> >;
|
---|
| 1246 | template class TArray< complex<r_8> >;
|
---|
| 1247 | #endif
|
---|
| 1248 |
|
---|
| 1249 |
|
---|