Changeset 1081 in Sophya for trunk/SophyaLib/TArray


Ignore:
Timestamp:
Jul 24, 2000, 2:51:27 PM (25 years ago)
Author:
ansari
Message:

Adaptation modifs MuTyV et services de copie entre tableaux de type different - Reza 24/7/2000

Location:
trunk/SophyaLib/TArray
Files:
5 edited

Legend:

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

    r1005 r1081  
    1010#include <iostream.h>
    1111#include "anydataobj.h"
     12#include "mutyv.h"
    1213#include "dvlist.h"
    1314
     
    134135
    135136  // an abstract element acces methode
    136   virtual double ValueAtPosition(uint_8 ip) const = 0;
     137  virtual MuTyV & ValueAtPosition(uint_8 ip) const = 0;
    137138
    138139 // Impression, I/O, ...
  • trunk/SophyaLib/TArray/tarray.cc

    r1072 r1081  
    131131}
    132132
     133//! Constructor with size and contents copied (after conversion) from a different type TArray
     134template <class T>
     135TArray<T>::TArray(const BaseArray& a)
     136  : BaseArray() , mNDBlock()
     137{
     138  string exmsg = "TArray<T>::TArray(const BaseArray&)";
     139  if (!UpdateSizes(a, exmsg))  throw( ParmError(exmsg) );
     140  mNDBlock.ReSize(totsize_);   
     141  //  if (a.mInfo) mInfo = new DVList(*(a.mInfo));  - pb protected !
     142  ConvertAndCopyElt(a);
     143}
     144
    133145//! Destructor
    134146template <class T>
     
    155167}
    156168
     169//! Set array elements equal to the \b a array elements, after conversion
     170template <class T>
     171TArray<T>& TArray<T>::SetBA(const BaseArray& a)
     172{
     173  if (this == &a) return(*this);
     174  if (a.NbDimensions() < 1)
     175    throw RangeCheckError("TArray<T>::SetBA(a ) - Array a not allocated ! ");
     176  if (NbDimensions() < 1) {
     177    string exmsg = "TArray<T>::SetBA(const BaseArray& a)";
     178    if (!UpdateSizes(a, exmsg))  throw( ParmError(exmsg) );
     179    mNDBlock.ReSize(totsize_);   
     180  }
     181  ConvertAndCopyElt(a);
     182  return(*this);
     183}
     184
    157185//! Clone array \b a
    158186template <class T>
     
    233261}
    234262
    235 inline double _SqrtRz_(double x) { return sqrt(x); }  // Pb avec SGI-CC - $CHECK$ - Reza 04/2000
    236 
    237263//! Give value (in \b double) for element at position \b ip..
    238264template <class T>
    239 double TArray<T>::ValueAtPosition(uint_8 ip) const
     265MuTyV & TArray<T>::ValueAtPosition(uint_8 ip) const
    240266{
    241267#ifdef SO_BOUNDCHECKING
    242268  if (ip >= totsize_)  throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") );
    243269#endif
    244   return( (double)(*(mNDBlock.Begin()+Offset(ip))) );
    245 }
    246 
    247 //! Give value (in \b double) for element at position \b ip..
    248 /*!
    249   For complex values, we return the module of the complex number
    250 */
    251 double TArray< complex<r_4> >::ValueAtPosition(uint_8 ip) const
    252 {
    253 #ifdef SO_BOUNDCHECKING
    254   if (ip >= totsize_)  throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") );
    255 #endif
    256   complex<r_4> c = *(mNDBlock.Begin()+Offset(ip));
    257   double cr = (double)(c.real());
    258   double ci = (double)(c.imag());
    259   return( _SqrtRz_(cr*cr+ci*ci) );
    260 }
    261 
    262 //! Give value (in \b double) for element at position \b ip..
    263 /*!
    264   For complex values, we return the module of the complex number
    265 */
    266 double TArray< complex<r_8> >::ValueAtPosition(uint_8 ip) const
    267 {
    268 #ifdef SO_BOUNDCHECKING
    269   if (ip >= totsize_)  throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") );
    270 #endif
    271   complex<r_8> c = *(mNDBlock.Begin()+Offset(ip));
    272   double cr = (double)(c.real());
    273   double ci = (double)(c.imag());
    274   return( _SqrtRz_(cr*cr+ci*ci) );
     270  my_mtv = *(mNDBlock.Begin()+Offset(ip));
     271  return( my_mtv );
    275272}
    276273
     
    754751      for(k=0, ka=0;  k<gpas;  k+=step, ka+=stepa)  pe[k] = pea[ka];
    755752    }
     753  }
     754  return(*this);
     755}
     756
     757//! Converts and Copy elements of \b a
     758template <class T>
     759TArray<T>& TArray<T>::ConvertAndCopyElt(const BaseArray& a)
     760{
     761  if (NbDimensions() < 1)
     762    throw RangeCheckError("TArray<T>::ConvertAndCopyElt(const TArray<T>& )  - Not Allocated Array ! ");
     763  if (!CompareSizes(a))
     764    throw(SzMismatchError("TArray<T>::ConvertAndCopyElt(const TArray<T>&) SizeMismatch")) ;
     765
     766  T * pe;
     767  uint_8 j,k,ka;
     768  uint_8 offa;
     769  // Non regular data spacing ...
     770  uint_4 ax = MaxSizeKA();
     771  uint_8 step = Step(ax);
     772  uint_8 stepa = a.Step(ax);
     773  uint_8 gpas = Size(ax)*step;
     774  uint_8 naxa = Size()/Size(ax);
     775  for(j=0; j<naxa; j++)  {
     776    pe = mNDBlock.Begin()+Offset(ax,j);
     777    offa = a.Offset(ax,j);
     778    for(k=0, ka=0;  k<gpas;  k+=step, ka+=stepa)  pe[k] = a.ValueAtPosition(offa+ka);
    756779  }
    757780  return(*this);
  • trunk/SophyaLib/TArray/tarray.h

    r1072 r1081  
    3535  TArray(const TArray<T>& a);
    3636  TArray(const TArray<T>& a, bool share);
     37  TArray(const BaseArray& a);
    3738
    3839  virtual ~TArray();
     
    4445  inline  TArray<T>& operator = (const TArray<T>& a) { return Set(a); }
    4546  virtual TArray<T>& Set(const TArray<T>& a);
     47
     48  //! = operator between  TArray 's with different types - Elements are converted.
     49  inline  TArray<T>& operator = (const BaseArray& a) { return SetBA(a); }
     50  virtual TArray<T>& SetBA(const BaseArray& a);
    4651
    4752  // Gestion taille/Remplissage
     
    8388  // ---- Access to data
    8489  // Definition of virtual element acces method inherited from BaseArray class
    85   virtual double ValueAtPosition(uint_8 ip) const;
     90  virtual MuTyV & ValueAtPosition(uint_8 ip) const;
    8691
    8792  // Data Access: operator overloaded inline acces methods
     
    150155// Recopie des valeurs, element par element
    151156  virtual TArray<T>&  CopyElt(const TArray<T>& a);
     157// Recopie des valeurs avec conversion prealable, element par element
     158  virtual TArray<T>&  ConvertAndCopyElt(const BaseArray& a);
    152159
    153160// Somme et produit des elements
     
    165172
    166173  NDataBlock<T> mNDBlock; //!< Block for datas
     174  mutable MuTyV my_mtv;   //!< for use by ValueAtPosition()
    167175};
    168176
  • trunk/SophyaLib/TArray/tmatrix.cc

    r996 r1081  
    1 // $Id: tmatrix.cc,v 1.12 2000-05-02 15:49:29 ansari Exp $
     1// $Id: tmatrix.cc,v 1.13 2000-07-24 12:51:27 ansari Exp $
    22//                         C.Magneville          04/99
    33#include "machdefs.h"
     
    9999  UpdateMemoryMapping(a, mm);
    100100}
     101
     102template <class T>
     103TMatrix<T>::TMatrix(const BaseArray& a)
     104: TArray<T>()
     105{
     106  SetBA(a);
     107}
     108
     109
    101110
    102111//! Destructor
     
    125134  return(*this);
    126135}
     136
     137template <class T>
     138TArray<T>& TMatrix<T>::SetBA(const BaseArray& a)
     139{
     140  if (a.NbDimensions() > 2)
     141    throw SzMismatchError("TMatrix<T>::SetBA(const BaseArray& a) a.NbDimensions() > 2");
     142  TArray<T>::SetBA(a);
     143  if (NbDimensions() == 1) {
     144    size_[1] = 1;
     145    step_[1] = size_[0]*step_[0];
     146    ndim_ = 2;
     147  }
     148  UpdateMemoryMapping(*this, SameMemoryMapping);
     149  return(*this);
     150}
     151
     152
    127153
    128154//! Resize the matrix
  • trunk/SophyaLib/TArray/tmatrix.h

    r1013 r1081  
    2020  TMatrix(const TArray<T>& a);
    2121  TMatrix(const TArray<T>& a,  bool share, short mm=BaseArray::AutoMemoryMapping);
     22  TMatrix(const BaseArray& a);
    2223
    2324  virtual ~TMatrix();
     
    3031  inline  TMatrix<T>& operator = (const TMatrix<T>& a)
    3132                     { Set(a);  return(*this); }
     33
     34  virtual TArray<T>& SetBA(const BaseArray& a);
     35  inline  TMatrix<T>& operator = (const BaseArray& a)
     36                     { SetBA(a);  return(*this); }
    3237
    3338  // Size - Changing the Size
Note: See TracChangeset for help on using the changeset viewer.