Changeset 2917 in Sophya for trunk/SophyaLib/TArray/tarray.cc
- Timestamp:
- Feb 23, 2006, 2:50:26 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/tarray.cc
r2915 r2917 17 17 Class for template arrays with numerical data types (int, float, complex). 18 18 19 This class implements arrays with number of dimensions up to 20 \ref BASEARRAY_MAXNDIMS "BASEARRAY_MAXNDIMS" 21 22 Standard arithmetic operations on numerical arrays are implemented, 23 as well as sub-array manipulation services. 19 This class handles arrays with number of dimensions up to 20 \ref BASEARRAY_MAXNDIMS "BASEARRAY_MAXNDIMS" (=5). The class has a performant 21 memory management system, including reference sharing for the array data. 22 (copy constructor and sub-arrays (or slices)). 23 24 An important feature of this class is the transparent handling of sub-arrays, 25 or slices. Arbitrary sub-arrays or slices can be defined, provided regular 26 spacing along each array axe (or dimension). 27 The second example below illustrate the use of this possibility. 28 29 Standard arithmetic operations, sum or product as well as application of usual 30 math functions (Sin, Cos ...) on numerical arrays are implemented. 31 These operations usually provide high performance, despite of the complex 32 memory management pattern. 33 34 ASCII input/output (or read write) and binary I/O (persistence) in different 35 formats are also provided through helper (or handler) classes. 36 37 This class is mainly intented for arrays with large number of data elements. 38 (Size() \> 100 .. 1000). Arrays with few data elements (\< 10) have significant 39 memory overhead, due to variables describing array shape and memory organisation. 40 However, a single higher dimensional array can be used to represent a large number 41 of identical size small arrays. For example, TArray<T> tab(2,2, 1000) can be used 42 to hold 1000 2x2 matrices. 43 24 44 \b Array is a typedef for double precision floating point arrays ( TArray<r_8> ) 45 25 46 \sa SOPHYA::Range 26 47 \sa SOPHYA::Sequence 27 48 \sa SOPHYA::MathArray 49 \sa SOPHYA::NDataBlock 28 50 29 51 \code … … 35 57 es = 24, 35, 46, 57, 68; 36 58 ia = es; 37 cout << "Array<int> ia = " << ia;59 cout << "Array<int> ia = \n" << ia; 38 60 // 2-D array of floats 39 61 TArray<r_4> b(6,4), c(6,4); … … 44 66 // Arithmetic operations 45 67 TArray<r_4> d = b+0.3f*c; 46 cout << "Array<float> d = " << d;68 cout << "Array<float> d = \n" << d; 47 69 \endcode 48 70 71 Example for sub-arrays, or slices 72 \code 73 // Creating and initialising a 2-D (6 x 4) array of integers 74 TArray<int> iaa(6, 4); 75 iaa = RegularSequence(1,2); 76 cout << "Array<int> iaa = \n" << iaa; 77 // We extract a sub-array - data is shared with iaa 78 TArray<int> iae = iaa(Range(1, Range::lastIndex(), 3) , 79 Range::all(), Range::first() ); 80 cout << "Array<int> iae=subarray(iaa) = \n" << iae; 81 // Changing iae elements changes corresponding iaa elements 82 iae = 0; 83 cout << "Array<int> iae=0 --> iaa = \n" << iaa; 84 \endcode 49 85 */ 50 86 … … 344 380 345 381 346 //! Compact dimensions in one or more is equal to 1. 382 /*! 383 \brief Compact arrays - supresses size=1 axes. 384 Changes the array rank (number of dimensions), suppressing all axes with size equal 1. 385 Example: 386 Compacting Rank=NDim=5 Sizes=3x1x6x1x1 =====\> Rank=NDim=2 Sizes=3x6 387 */ 347 388 template <class T> 348 389 TArray<T>& TArray<T>::CompactAllDimensions() … … 352 393 } 353 394 354 //! Compact dimensions if the last one is equal to 1. 395 /*! 396 \brief Compact array taling dimensions, for size=1 traling axes. 397 Changes the array rank (number of dimensions), suppressing all axes with size equal 1, 398 after the last axe with size \> 1 399 Example: 400 Compacting Rank=NDim=5 Sizes=3x1x6x1x1 =====\> Rank=NDim=3 Sizes=3x1x6 401 */ 355 402 template <class T> 356 403 TArray<T>& TArray<T>::CompactTrailingDimensions() … … 393 440 } 394 441 395 //! Return array with elements packed 396 /*! 442 /*! 443 \brief Return a new array with elements packed in memory 444 445 397 446 \param force : if true, pack elements in a new array. 398 447 If false and array is already packed, return … … 424 473 /*! 425 474 \param rx,ry,rz,rt,ru : range of extraction along dimensions 475 \param compact : if \b compact == true, compact trailing dimensions (suppressed if =1) 476 (See CompactTrailingDimensions() ) 426 477 \sa SOPHYA::Range 427 478 */ 428 479 template <class T> 429 TArray<T> TArray<T>::SubArray(Range rx, Range ry, Range rz, Range rt, Range ru ) const480 TArray<T> TArray<T>::SubArray(Range rx, Range ry, Range rz, Range rt, Range ru, bool compact) const 430 481 { 431 482 if (NbDimensions() < 1) … … 467 518 UpdateSubArraySizes(ra, ndim, size, pos, step); 468 519 ra.DataBlock().Share(this->DataBlock()); 520 if (compact) ra.CompactTrailingDim(); 469 521 ra.SetTemp(true); 470 522 return(ra);
Note:
See TracChangeset
for help on using the changeset viewer.