Changeset 2917 in Sophya


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

Location:
trunk/SophyaLib/TArray
Files:
8 edited

Legend:

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

    r2788 r2917  
    360360}
    361361
    362 //! Change dimension if some size == 1
     362//! Compact arrays - supresses size=1 axes.
    363363void BaseArray::CompactAllDim()
    364364{
     
    383383}
    384384
    385 //! Change dimension if some trailed size == 1
     385//! Compact array taling dimensions, for size=1 traling axes.
    386386void BaseArray::CompactTrailingDim()
    387387{
     
    391391  sa_size_t step[BASEARRAY_MAXNDIMS];
    392392  for(int_4 k=0; k<ndim_; k++) {
    393     size[ndim] = size_[k];
    394     step[ndim] = step_[k];
    395     if (size_[k] > 1)  ndim=k;
     393    size[k] = size_[k];
     394    step[k] = step_[k];
     395    if (size_[k] > 1)  ndim=k+1;
    396396  }
    397397  if (ndim == 0)  ndim = 1;
     
    714714
    715715
    716 //! Update sizes and information relative to array \b a
    717 /*!
    718   \param a : array to be compare with
    719   \param ndim : could be change (but should be less than the ndim of the current class)
    720   \param siz[ndim],pos[ndim],step[ndim] : could be changed but must be
    721              compatible within the memory size with those of the current class.
    722   \return true if all OK, false if problems appear
    723   \return string \b exmsg for explanation in case of problems
     716//! Update sizes information for sub-array \b ra
     717/*!
     718  \param ra : sub-array for which size information has to be computed
     719  \param ndim : number of dimensions for \b ra
     720  \param siz[ndim],pos[ndim],step[ndim] : number of elements, offset and step along each dimension,
     721   relative to the original array.
     722  \warning throw SzMismatchError in case of incompatible dimensions.
    724723 */
    725724void BaseArray::UpdateSubArraySizes(BaseArray & ra, int_4 ndim, sa_size_t * siz, sa_size_t * pos, sa_size_t * step) const
     
    729728  int_4 k;
    730729  for(k=0; k<ndim; k++)
    731     if ( (siz[k]*step[k]+pos[k]) > size_[k] ) 
     730    if ( ((siz[k]-1)*step[k]+pos[k]) >= size_[k] ) 
    732731      throw(SzMismatchError("BaseArray::UpdateSubArraySizes( ... ) Size/Pos Error") );
    733732  sa_size_t offset = offset_;
  • trunk/SophyaLib/TArray/basarr.h

    r2888 r2917  
    6868  virtual bool CompareSizes(const BaseArray& a, bool& smo) const;
    6969
    70   // Compacts \b size=1 array dimensions
    71   virtual void CompactAllDim(); // suppresses all size==1 dimensions
    72   virtual void CompactTrailingDim(); // suppresses size==1 dimensions after the last size>1 dimension
    73 
    7470  // Array dimensions
    7571  //! Return true if the array was allocated ( Rank() > 0 )
     
    170166  inline int_4 CheckDI(int_4 ka, int msg) const ;
    171167  inline void CheckBound(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu, int msg) const ;
     168  // Compacts size=1 array dimensions
     169  void CompactAllDim(); // suppresses all size==1 dimensions
     170  void CompactTrailingDim(); // suppresses size==1 dimensions after the last size>1 dimension
    172171  // Changing Sizes/NDim ... return true if OK
    173172  bool UpdateSizes(int_4 ndim, const sa_size_t * siz, sa_size_t step, sa_size_t offset, string & exmsg);
  • trunk/SophyaLib/TArray/sopemtx.h

    r1007 r2917  
    2020  \class SimpleMatrixOperation
    2121  \ingroup TArray
    22   Class for simple operation on TMatrix
    23   \sa TMatrix TArray
     22  \brief Class for simple operation on TMatrix
     23  This class provides presently a basic implementation of the Gauss
     24  pivoting for linear system solving and matrix inversion.
     25
     26  \warning For large or ill conditioned matrices, use the methods
     27  from LinAlg module.
     28  \sa SOPHYA::LapackServer  SOPHYA::TMatrix
    2429*/
    2530//! Class for simple operation on TMatrix
  • 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);
  • trunk/SophyaLib/TArray/tarray.h

    r2915 r2917  
    7575
    7676  // SubArrays - $CHECK$ Reza 03/2000 je ne sais pas s'il faut declarer ca const ??
    77   TArray<T> SubArray(Range rx, Range ry, Range rz, Range rt, Range ru) const ;
     77  TArray<T> SubArray(Range rx, Range ry, Range rz, Range rt, Range ru, bool compact=true) const ;
    7878
    7979  //! Extract the first 3D subarray specified by rx, ry, rz. (see SubArray() )
  • trunk/SophyaLib/TArray/tmatrix.cc

    r2915 r2917  
    1 // $Id: tmatrix.cc,v 1.34 2006-02-22 18:17:30 ansari Exp $
     1// $Id: tmatrix.cc,v 1.35 2006-02-23 13:50:26 ansari Exp $
    22//                         C.Magneville          04/99
    33#include "sopnamsp.h"
     
    1717  two dimensional arrays as matrices. Matrix and vector operations,
    1818  such as matrix multiplication or transposition is implemented.
     19
     20  Sub-matrices, in particular matrix rows and columns can easily and
     21  efficiently be extracted and manipulated.
     22  It should be noted that a significant memory overhead is associated with
     23  small matrices (typically less than 10x10=100 elements).However,
     24  higher dimension arrays (3D for examples) can be used to represent large
     25  number of small matrices or vectors.
     26
    1927  \b Matrix is a typedef for double precision floating point matrix ( TMatrix<r_8> ).
    2028
    2129  \sa SOPHYA::TArray  SOPHYA::TVector
    22   \sa SOPHYA::Range  \sa SOPHYA::Sequence
    23   \sa SOPHYA::MathArray  \sa SOPHYA::SimpleMatrixOperation
     30  \sa SOPHYA::Range  SOPHYA::Sequence
     31  \sa SOPHYA::MathArray  SOPHYA::SimpleMatrixOperation
    2432
    2533  The following sample code illustrates vector-matrix multiplication
     
    254262  if (mm == CMemoryMapping)  { rx = rcol;  ry = rline; }
    255263  else { ry = rcol;  rx = rline; }
    256   TMatrix sm(SubArray(rx, ry, Range::first(), Range::first(), Range::first()), true);
     264  TMatrix sm(SubArray(rx, ry, Range::first(), Range::first(), Range::first(), false), true);
    257265  sm.UpdateMemoryMapping(mm);
    258266  return(sm);
  • trunk/SophyaLib/TArray/utilarr.cc

    r2915 r2917  
    313313  \class SOPHYA::Range
    314314  \ingroup TArray
    315   Class to define a range of indices, to be used with TArra<T> TMatrix<T> TVector<T> ...
    316 */
    317 
    318 /*!
    319   Constructor defining defining the range of indices, starting from \b start to the last.
    320   \param start : start index (inclusive)
     315  This class can be used to define a range of indices. Range objects are used to extract
     316  sub-arrays and slices, from arrays and matrices.
     317  \sa SOPHYA::TArray SOPHYA::TMatrix
     318*/
     319
     320/*!
     321  Constructor defining a range corresponding to the single index \b start
     322  \param start : start=end index
    321323*/
    322324Range::Range(sa_size_t start)
    323325{
    324326  start_ = start;
    325   end_ = Range::lastIndex();
    326   size_ = 0;
     327  end_ = start;
     328  size_ = 1;
    327329  step_ = 1;
    328330}
     
    375377  if (size > 0) {  // Nb d'elements fixe
    376378    size_ = size;
    377     if (end == Range::lastIndex()) start_ = end_ = end;
    378     else end_ = start_+size_*step_;   
     379    if ( (start == end) && (end == Range::lastIndex()) ) start_ = end_ = end;
     380    else end_ = start_+(size_-1)*step_;   
    379381  }
    380382  else {
     
    406408void Range::Update(sa_size_t osz)
    407409{
    408   if (end_ >= 0)  return;
     410  if (end_ >= 0)  return; 
    409411  if (osz == 0) {
    410412    start_ = end_ = 0;
     
    415417    end_ = osz-1;
    416418    if ((size_ > 0) && (size_ <= osz/step_))
    417       start_ = end_ - size_*step_;
     419      start_ = end_ - (size_-1)*step_;
    418420    else {
    419421      start_ = end_;
     
    425427    size_ = (end_-start_)/step_+1;
    426428  }
     429  //DBG  cout << ">>> DBG/Update start=" << start_ << " end=" << end_
     430  //DBG     << " size=" << size_ << " step=" << step_ << endl;
    427431  return;
    428432}
     
    443447  \class SOPHYA::IdentityMatrix
    444448  \ingroup TArray
    445   Class to define an identity matrix
    446 */
    447 
    448 //! Constructor of a (n,n) diagonal matrix with value diag on the diagonal
     449  Class to define an identity matrix. This class is mainly intented for
     450  initializing TMatrix<T> objects, proportional to the identity matrix.
     451*/
     452
     453//! Constructor representing a square matrix (\b n x \b n) with value \b diag on the diagonal
    449454IdentityMatrix::IdentityMatrix(double diag, sa_size_t n)
    450455{
  • trunk/SophyaLib/TArray/utilarr.h

    r2915 r2917  
    128128class Range {
    129129public:
    130   //! Index range start \<= index \<= last()
     130  //! Index range containing a single index = \b start
    131131  Range(sa_size_t start);
    132132  //! Index range start \<= index \<= end
     
    153153  //! return a Range object specifing the first index
    154154  inline static Range first()
    155   { return Range(Range::firstIndex() , Range::lastIndex(), 1, 1); }
     155  { return Range(Range::firstIndex() , Range::firstIndex(), 1, 1); }
    156156  //! return a Range object specifing the last valid index
    157157  inline static Range last()
Note: See TracChangeset for help on using the changeset viewer.