Changeset 2917 in Sophya for trunk/SophyaLib/TArray
- Timestamp:
- Feb 23, 2006, 2:50:26 PM (20 years ago)
- Location:
- trunk/SophyaLib/TArray
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/basarr.cc
r2788 r2917 360 360 } 361 361 362 //! C hange dimension if some size == 1362 //! Compact arrays - supresses size=1 axes. 363 363 void BaseArray::CompactAllDim() 364 364 { … … 383 383 } 384 384 385 //! C hange dimension if some trailed size == 1385 //! Compact array taling dimensions, for size=1 traling axes. 386 386 void BaseArray::CompactTrailingDim() 387 387 { … … 391 391 sa_size_t step[BASEARRAY_MAXNDIMS]; 392 392 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; 396 396 } 397 397 if (ndim == 0) ndim = 1; … … 714 714 715 715 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. 724 723 */ 725 724 void BaseArray::UpdateSubArraySizes(BaseArray & ra, int_4 ndim, sa_size_t * siz, sa_size_t * pos, sa_size_t * step) const … … 729 728 int_4 k; 730 729 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] ) 732 731 throw(SzMismatchError("BaseArray::UpdateSubArraySizes( ... ) Size/Pos Error") ); 733 732 sa_size_t offset = offset_; -
trunk/SophyaLib/TArray/basarr.h
r2888 r2917 68 68 virtual bool CompareSizes(const BaseArray& a, bool& smo) const; 69 69 70 // Compacts \b size=1 array dimensions71 virtual void CompactAllDim(); // suppresses all size==1 dimensions72 virtual void CompactTrailingDim(); // suppresses size==1 dimensions after the last size>1 dimension73 74 70 // Array dimensions 75 71 //! Return true if the array was allocated ( Rank() > 0 ) … … 170 166 inline int_4 CheckDI(int_4 ka, int msg) const ; 171 167 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 172 171 // Changing Sizes/NDim ... return true if OK 173 172 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 20 20 \class SimpleMatrixOperation 21 21 \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 24 29 */ 25 30 //! Class for simple operation on TMatrix -
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); -
trunk/SophyaLib/TArray/tarray.h
r2915 r2917 75 75 76 76 // 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 ; 78 78 79 79 //! 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.3 4 2006-02-22 18:17:30ansari Exp $1 // $Id: tmatrix.cc,v 1.35 2006-02-23 13:50:26 ansari Exp $ 2 2 // C.Magneville 04/99 3 3 #include "sopnamsp.h" … … 17 17 two dimensional arrays as matrices. Matrix and vector operations, 18 18 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 19 27 \b Matrix is a typedef for double precision floating point matrix ( TMatrix<r_8> ). 20 28 21 29 \sa SOPHYA::TArray SOPHYA::TVector 22 \sa SOPHYA::Range \saSOPHYA::Sequence23 \sa SOPHYA::MathArray \saSOPHYA::SimpleMatrixOperation30 \sa SOPHYA::Range SOPHYA::Sequence 31 \sa SOPHYA::MathArray SOPHYA::SimpleMatrixOperation 24 32 25 33 The following sample code illustrates vector-matrix multiplication … … 254 262 if (mm == CMemoryMapping) { rx = rcol; ry = rline; } 255 263 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); 257 265 sm.UpdateMemoryMapping(mm); 258 266 return(sm); -
trunk/SophyaLib/TArray/utilarr.cc
r2915 r2917 313 313 \class SOPHYA::Range 314 314 \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 321 323 */ 322 324 Range::Range(sa_size_t start) 323 325 { 324 326 start_ = start; 325 end_ = Range::lastIndex();326 size_ = 0;327 end_ = start; 328 size_ = 1; 327 329 step_ = 1; 328 330 } … … 375 377 if (size > 0) { // Nb d'elements fixe 376 378 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_; 379 381 } 380 382 else { … … 406 408 void Range::Update(sa_size_t osz) 407 409 { 408 if (end_ >= 0) return; 410 if (end_ >= 0) return; 409 411 if (osz == 0) { 410 412 start_ = end_ = 0; … … 415 417 end_ = osz-1; 416 418 if ((size_ > 0) && (size_ <= osz/step_)) 417 start_ = end_ - size_*step_;419 start_ = end_ - (size_-1)*step_; 418 420 else { 419 421 start_ = end_; … … 425 427 size_ = (end_-start_)/step_+1; 426 428 } 429 //DBG cout << ">>> DBG/Update start=" << start_ << " end=" << end_ 430 //DBG << " size=" << size_ << " step=" << step_ << endl; 427 431 return; 428 432 } … … 443 447 \class SOPHYA::IdentityMatrix 444 448 \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 449 454 IdentityMatrix::IdentityMatrix(double diag, sa_size_t n) 450 455 { -
trunk/SophyaLib/TArray/utilarr.h
r2915 r2917 128 128 class Range { 129 129 public: 130 //! Index range start \<= index \<= last()130 //! Index range containing a single index = \b start 131 131 Range(sa_size_t start); 132 132 //! Index range start \<= index \<= end … … 153 153 //! return a Range object specifing the first index 154 154 inline static Range first() 155 { return Range(Range::firstIndex() , Range:: lastIndex(), 1, 1); }155 { return Range(Range::firstIndex() , Range::firstIndex(), 1, 1); } 156 156 //! return a Range object specifing the last valid index 157 157 inline static Range last()
Note:
See TracChangeset
for help on using the changeset viewer.