Changeset 2917 in Sophya for trunk/SophyaLib/TArray/tarray.cc


Ignore:
Timestamp:
Feb 23, 2006, 2:50:26 PM (20 years ago)
Author:
ansari
Message:

Documentation + debug Range et extraction sous-tableaux , Reza 23/02/2006

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/TArray/tarray.cc

    r2915 r2917  
    1717  Class for template arrays with numerical data types (int, float, complex).
    1818
    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
    2444  \b Array is a typedef for double precision floating point arrays ( TArray<r_8> )
     45
    2546  \sa SOPHYA::Range
    2647  \sa SOPHYA::Sequence
    2748  \sa SOPHYA::MathArray
     49  \sa SOPHYA::NDataBlock
    2850
    2951  \code
     
    3557  es = 24, 35, 46, 57, 68;
    3658  ia = es;
    37   cout << "Array<int> ia = " << ia;
     59  cout << "Array<int> ia = \n" << ia;
    3860  // 2-D array of floats
    3961  TArray<r_4> b(6,4), c(6,4);
     
    4466  // Arithmetic operations
    4567  TArray<r_4> d = b+0.3f*c;
    46   cout << "Array<float> d = " << d; 
     68  cout << "Array<float> d = \n" << d; 
    4769  \endcode
    4870
     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
    4985*/
    5086
     
    344380
    345381
    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*/
    347388template <class T>
    348389TArray<T>& TArray<T>::CompactAllDimensions()
     
    352393}
    353394
    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*/
    355402template <class T>
    356403TArray<T>& TArray<T>::CompactTrailingDimensions()
     
    393440}
    394441
    395 //! Return array with elements packed
    396 /*!
     442/*!
     443  \brief Return a new array with elements packed in memory
     444
     445
    397446  \param force : if true, pack elements in a new array.
    398447                 If false and array is already packed, return
     
    424473/*!
    425474  \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() )
    426477  \sa SOPHYA::Range
    427478 */
    428479template <class T>
    429 TArray<T> TArray<T>::SubArray(Range rx, Range ry, Range rz, Range rt, Range ru) const
     480TArray<T> TArray<T>::SubArray(Range rx, Range ry, Range rz, Range rt, Range ru, bool compact) const
    430481{
    431482  if (NbDimensions() < 1)
     
    467518  UpdateSubArraySizes(ra, ndim, size, pos, step);
    468519  ra.DataBlock().Share(this->DataBlock());
     520  if (compact) ra.CompactTrailingDim();
    469521  ra.SetTemp(true);
    470522  return(ra);
Note: See TracChangeset for help on using the changeset viewer.