Changeset 787 in Sophya for trunk/SophyaLib/TArray


Ignore:
Timestamp:
Mar 20, 2000, 7:22:49 PM (26 years ago)
Author:
ansari
Message:

Introduction de BaseArray comme classe parente de TArray<T>
Separation des operations math (fonctions) ds la classe MathArr<T>

Reza 20/3/2000

Location:
trunk/SophyaLib/TArray
Files:
4 added
3 edited

Legend:

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

    r785 r787  
    7070// On lit les tailles, etc ...
    7171  is.Get(dobj->ndim_);
    72   is.Get(dobj->size_, TARRAY_MAXNDIMS);
     72  is.Get(dobj->size_, BASEARRAY_MAXNDIMS);
    7373  is.Get(dobj->totsize_);
    74   is.Get(dobj->step_, TARRAY_MAXNDIMS);
     74  is.Get(dobj->step_, BASEARRAY_MAXNDIMS);
    7575  is.Get(dobj->minstep_);
    7676  is.Get(dobj->moystep_);
     
    9898// On ecrit les tailles, etc ...
    9999  os.Put(dobj->ndim_);
    100   os.Put(dobj->size_, TARRAY_MAXNDIMS);
     100  os.Put(dobj->size_, BASEARRAY_MAXNDIMS);
    101101  os.Put(dobj->totsize_);
    102   os.Put(dobj->step_, TARRAY_MAXNDIMS);
     102  os.Put(dobj->step_, BASEARRAY_MAXNDIMS);
    103103  os.Put(dobj->minstep_);
    104104  os.Put(dobj->moystep_);
  • trunk/SophyaLib/TArray/tarray.cc

    r785 r787  
    1010
    1111
    12 // Variables statiques globales
    13 template <class T>
    14 char * TArray<T>::ck_op_msg_[6] = {"???", "Size(int )", "IsPacked(int )",
    15                                  "Stride(int )", "ElemCheckBound()", "operator()" };
    16 template <class T>
    17 uint_4 TArray<T>::max_nprt_ = 50;
    18 
    19 // Methodes statiques globales
    20 template <class T>
    21 void TArray<T>::SetMaxPrint(uint_4 nprt)
    22 {
    23   max_nprt_ = nprt;
    24 }
    25 
    26 
    27 template <class T>
    28 uint_8 TArray<T>::ComputeTotalSize(uint_4 ndim, uint_4 * siz, uint_4 step, uint_8 offset)
    29 {
    30   uint_8 rs = step;
    31   for(int k=0; k<ndim; k++) rs *= siz[k];
    32   return(rs+offset);
    33 }
    3412
    3513// -------------------------------------------------------
     
    4018template <class T>
    4119TArray<T>::TArray()
    42   : mNDBlock() , mInfo(NULL)
     20  : mNDBlock() , BaseArray()
    4321// Default constructor
    4422{
    45   ndim_ = 0;
    46   for(int k=0; k<TARRAY_MAXNDIMS; k++) step_[k] = size_[k] = 0;
    47   totsize_ = 0;
    48   minstep_ = 0;
    49   moystep_ = 0;
    50   offset_ = 0;
    51   // Default for matrices : Lines = Y , Columns = X
    52   macoli_ = 0;
    53   marowi_ = 1;
    5423}
    5524
    5625template <class T>
    5726TArray<T>::TArray(uint_4 ndim, uint_4 * siz, uint_4 step)
    58   : mNDBlock(ComputeTotalSize(ndim, siz, step, 1)) , mInfo(NULL)
     27  : mNDBlock(ComputeTotalSize(ndim, siz, step, 1)) , BaseArray()
    5928{
    6029  string exmsg = "TArray<T>::TArray(uint_4, uint_4 *, uint_4)";
     
    6433template <class T>
    6534TArray<T>::TArray(uint_4 nx, uint_4 ny=1, uint_4 nz=1)
    66   : mNDBlock(nx*((ny>0)?ny:1)*((nz>0)?nz:1)) , mInfo(NULL)
    67 {
    68   uint_4 size[TARRAY_MAXNDIMS];
     35  : mNDBlock(nx*((ny>0)?ny:1)*((nz>0)?nz:1)) , BaseArray()
     36{
     37  uint_4 size[BASEARRAY_MAXNDIMS];
    6938  size[0] = nx;   size[1] = ny;   size[2] = nz;
    7039  int ndim = 1;
     
    7847template <class T>
    7948TArray<T>::TArray(uint_4 ndim, uint_4 * siz, NDataBlock<T> & db, bool share, uint_4 step, uint_8 offset)
    80   : mNDBlock(db, share) , mInfo(NULL)
     49  : mNDBlock(db, share) , BaseArray()
    8150{
    8251  string exmsg = "TArray<T>::TArray(uint_4, uint_4 *,  NDataBlock<T> & ... )";
     
    8756template <class T>
    8857TArray<T>::TArray(uint_4 ndim, uint_4 * siz, T* values, uint_4 step, uint_8 offset, Bridge* br)
    89   : mNDBlock(ComputeTotalSize(ndim, siz, step, 1), values, br) , mInfo(NULL)
     58  : mNDBlock(ComputeTotalSize(ndim, siz, step, 1), values, br) , BaseArray()
    9059{
    9160  string exmsg = "TArray<T>::TArray(uint_4, uint_4 *, T* ... )";
     
    9564template <class T>
    9665TArray<T>::TArray(const TArray<T>& a)
    97   : mNDBlock(a.mNDBlock) , mInfo(NULL)
     66  : mNDBlock(a.mNDBlock) , BaseArray()
    9867{
    9968  string exmsg = "TArray<T>::TArray(const TArray<T>&)";
     
    10473template <class T>
    10574TArray<T>::TArray(const TArray<T>& a, bool share)
    106   : mNDBlock(a.mNDBlock, share) , mInfo(NULL)
     75  : mNDBlock(a.mNDBlock, share) , BaseArray()
    10776{
    10877  string exmsg = "TArray<T>::TArray(const TArray<T>&, bool)";
     
    154123}
    155124
    156 template <class T>
    157 bool TArray<T>::CompareSizes(const TArray<T>& a)
    158 {
    159   if (ndim_ != a.ndim_)  return(false);
    160   for(int k=0; k<ndim_; k++)
    161     if (size_[k] != a.size_[k])  return(false);
    162   if ( (macoli_ != a.macoli_) || (marowi_ != a.marowi_) )  return(false);
    163   return(true);
    164 }
    165 
    166 template <class T>
    167 TArray<T>& TArray<T>::CompactDim()
    168 {
    169   if (ndim_ < 2)  return(*this);
     125
     126template <class T>
     127TArray<T>& TArray<T>::CompactAllDimensions()
     128{
     129  CompactAllDim();
     130  return(*this);
     131}
     132
     133template <class T>
     134TArray<T>& TArray<T>::CompactTrailingDimensions()
     135{
     136  CompactTrailingDim();
     137  return(*this);
     138}
     139
     140template <class T>
     141double TArray<T>::ValueAtPosition(uint_8 ip) const
     142{
     143#ifdef SO_BOUNDCHECKING
     144  if (ip >= totsize_)  throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") );
     145#endif
     146  return( (double)(*(mNDBlock.Begin()+Offset(ip))) );
     147}
     148
     149// For complex values, we return the module of the complex number
     150double TArray< complex<r_4> >::ValueAtPosition(uint_8 ip) const
     151{
     152#ifdef SO_BOUNDCHECKING
     153  if (ip >= totsize_)  throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") );
     154#endif
     155  complex<r_4> c = *(mNDBlock.Begin()+Offset(ip));
     156  double cr = (double)(c.real());
     157  double ci = (double)(c.imag());
     158  return( sqrt(cr*cr+ci*ci) );
     159}
     160
     161double TArray< complex<r_8> >::ValueAtPosition(uint_8 ip) const
     162{
     163#ifdef SO_BOUNDCHECKING
     164  if (ip >= totsize_)  throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") );
     165#endif
     166  complex<r_8> c = *(mNDBlock.Begin()+Offset(ip));
     167  double cr = (double)(c.real());
     168  double ci = (double)(c.imag());
     169  return( sqrt(cr*cr+ci*ci) );
     170}
     171
     172
     173// SubArrays
     174template <class T>
     175TArray<T> TArray<T>::operator () (Range rx, Range ry, Range rz, Range rt, Range ru)
     176{
    170177  uint_4 ndim = 0;
    171   uint_4 size[TARRAY_MAXNDIMS];
    172   uint_4 step[TARRAY_MAXNDIMS];
    173   for(int k=0; k<ndim_; k++) {
    174     if (size_[k] < 2)  continue;
    175     size[ndim] = size_[k];
    176     step[ndim] = step_[k];
    177     ndim++;
    178   }
    179   if (ndim == 0)  {
    180     size[0] = size_[0];
    181     step[0] = step_[0];
    182     ndim = 1;
    183   }
    184   string exmsg = "TArray<T>::CompactDim() ";
    185   if (!UpdateSizes(ndim, size, step, offset_, exmsg))  throw( ParmError(exmsg) );
    186   return(*this);
    187 }
    188 
    189 
    190 template <class T>
    191 uint_4 TArray<T>::MinStepKA() const
    192 {
    193   for(int ka=0; ka<ndim_; ka++)
    194     if (step_[ka] == minstep_) return(ka);
    195   return(0);
    196 }
    197 
    198 template <class T>
    199 uint_4 TArray<T>::MaxSizeKA() const
    200 {
    201   uint_4 ka = 0;
    202   uint_4 mx = size_[0];
    203   for(int k=0; k<ndim_; k++) 
    204     if (size_[k] > mx) {  ka = k;  mx = size_[k];  }
    205   return(ka);
    206 }
    207 
    208 
    209 //  Acces lineaire aux elements ....  Calcul d'offset
    210 
    211 template <class T>
    212 uint_8 TArray<T>::Offset(uint_8 ip) const
    213 {
    214 if (ip == 0)  return(offset_);
    215 uint_4 idx[TARRAY_MAXNDIMS];
    216 int k;
    217 uint_8 rest = ip;
    218 for(k=0; k<ndim_; k++)   { idx[k] = rest%size_[k];   rest /= size_[k];  }   
    219 uint_8 off = offset_;
    220 for(k=0; k<ndim_; k++)  off += idx[k]*step_[k];
    221 return (off);
    222 }
    223 
    224 // SubArrays
    225 template <class T>
    226 TArray<T> TArray<T>::operator () (Range rx, Range ry, Range rz, Range rt, Range ru)
    227 {
    228   uint_4 ndim = 0;
    229   uint_4 size[TARRAY_MAXNDIMS];
    230   uint_4 step[TARRAY_MAXNDIMS];
    231   uint_4 pos[TARRAY_MAXNDIMS];
     178  uint_4 size[BASEARRAY_MAXNDIMS];
     179  uint_4 step[BASEARRAY_MAXNDIMS];
     180  uint_4 pos[BASEARRAY_MAXNDIMS];
    232181  size[0] = rx.Size();
    233182  size[1] = ry.Size();
     
    251200  TArray<T> ra;
    252201  SubArray(ra, ndim, size, pos, step);
     202  ra.DataBlock().Share(this->DataBlock());
    253203  ra.SetTemp(true);
    254204  return(ra);
     
    523473
    524474// ----------------------------------------------------
    525 //          Application d'une fonction
    526 // ----------------------------------------------------
    527 template <class T>
    528 TArray<T>& TArray<T>::ApplyFunction(Arr_DoubleFunctionOfX f)
    529 {
    530   T * pe;
    531   uint_8 j,k;
    532   if (AvgStep() > 0)   {  // regularly spaced elements
    533     uint_8 step = AvgStep();
    534     uint_8 maxx = totsize_*step;
    535     pe = Data();
    536     for(k=0; k<maxx; k+=step )  pe[k] = (T)(f((double)pe[k]));
    537   }
    538   else {    // Non regular data spacing ...
    539     uint_4 ka = MaxSizeKA();
    540     uint_8 step = Step(ka);
    541     uint_8 gpas = Size(ka)*step;
    542     for(j=0; j<totsize_; j += Size(ka))  {
    543       pe = mNDBlock.Begin()+Offset(j);
    544       for(k=0; k<gpas; k+=step)  pe[k] = (T)(f((double)pe[k]));
    545     }
    546   }
    547   return(*this);
    548 }
    549 
    550 template <class T>
    551 TArray<T>& TArray<T>::ApplyFunction(Arr_FloatFunctionOfX f)
    552 {
    553   T * pe;
    554   uint_8 j,k;
    555   if (AvgStep() > 0)   {  // regularly spaced elements
    556     uint_8 step = AvgStep();
    557     uint_8 maxx = totsize_*step;
    558     pe = Data();
    559     for(k=0; k<maxx; k+=step )  pe[k] = (T)(f((float)pe[k]));
    560   }
    561   else {    // Non regular data spacing ...
    562     uint_4 ka = MaxSizeKA();
    563     uint_8 step = Step(ka);
    564     uint_8 gpas = Size(ka)*step;
    565     for(j=0; j<totsize_; j += Size(ka))  {
    566       pe = mNDBlock.Begin()+Offset(j);
    567       for(k=0; k<gpas; k+=step)  pe[k] = (T)(f((float)pe[k]));
    568     }
    569   }
    570   return(*this);
    571 }
    572 
    573 TArray< complex<r_4> >& TArray< complex<r_4> >::ApplyFunction(Arr_DoubleFunctionOfX f)
    574 {
    575   throw( NotAvailableOperation("TArray< complex<r_4> >::ApplyFunction() - Unsupported operation ") );
    576 }
    577 
    578 TArray< complex<r_4> >& TArray< complex<r_4> >::ApplyFunction(Arr_FloatFunctionOfX f)
    579 {
    580   throw(NotAvailableOperation( "TArray< complex<r_4> >::ApplyFunction() - Unsupported operation ") );
    581 }
    582 
    583 TArray< complex<r_8> >& TArray< complex<r_8> >::ApplyFunction(Arr_DoubleFunctionOfX f)
    584 {
    585   throw(NotAvailableOperation("TArray< complex<r_8> >::ApplyFunction() - Unsupported operation ") );
    586 }
    587 
    588 TArray< complex<r_8> >& TArray< complex<r_8> >::ApplyFunction(Arr_FloatFunctionOfX f)
    589 {
    590   throw(NotAvailableOperation("TArray< complex<r_8> >::ApplyFunction() - Unsupported operation ") );
    591 }
    592 
    593 // ----------------------------------------------------
    594475//       Impression, etc ...
    595476// ----------------------------------------------------
    596477
    597478template <class T>
    598 void TArray<T>::Show(ostream& os, bool si) const
    599 {
    600   os << " TArray< " << typeid(T).name() << " NDim= " << ndim_
    601      << "(" << typeid(*this).name() << " )" << endl;
    602   os << "TotSize=" << totsize_ << " Size(X*Y*...)= " ;
    603   for(int k=0; k<ndim_; k++) {
    604     os << size_[k];
    605     if (k<ndim_-1)  os << " x ";
    606   }
    607   os << endl;
    608   os <<  " Step(X Y ...)= " ;
    609   for(int k=0; k<ndim_; k++)     os << step_[k] << "  " ;
    610   os << " Offset= " << offset_  << "\n " << endl;
    611   if (si && (mInfo != NULL)) os << (*mInfo) << endl;
    612  
     479string TArray<T>::DataType() const
     480{
     481  string rs = typeid(T).name();
     482  return(rs);
    613483}
    614484
     
    643513}
    644514
    645 template <class T>
    646 DVList& TArray<T>::Info()
    647 {
    648 if (mInfo == NULL)  mInfo = new DVList;
    649 return(*mInfo);
    650 }
    651 
    652 
    653 template <class T>
    654 bool TArray<T>::UpdateSizes(uint_4 ndim, const uint_4 * siz, uint_4 step, uint_8 offset, string & exmsg)
    655 {
    656   if (ndim >= TARRAY_MAXNDIMS) {
    657     exmsg += " NDim Error";  return false;
    658   }
    659   if (step < 1) {
    660     exmsg += " Step(=0) Error";  return false;
    661   }
    662 
    663   minstep_ = moystep_ = step;
    664 
    665   // Flagging bad updates ...
    666   ndim_ = 0;
    667 
    668   totsize_ = 1;
    669   int k;
    670   for(k=0; k<TARRAY_MAXNDIMS; k++) {
    671     size_[k] = 1;
    672     step_[k] = 0;
    673   }
    674   for(k=0; k<ndim; k++) {
    675     size_[k] = siz[k] ;
    676     step_[k] = totsize_*step;
    677     totsize_ *= size_[k];
    678   }
    679   if (totsize_ < 1) {
    680     exmsg += " Size Error";  return false;
    681   }
    682   offset_ = offset;
    683   // Default for matrices : Lines = Y , Columns = X
    684   macoli_ = 0;
    685   marowi_ = 1;
    686   // Update OK
    687   ndim_ = ndim;
    688   return true;
    689 }
    690 
    691 template <class T>
    692 bool TArray<T>::UpdateSizes(uint_4 ndim, const uint_4 * siz, const uint_4 * step, uint_8 offset, string & exmsg)
    693 {
    694   if (ndim >= TARRAY_MAXNDIMS) {
    695     exmsg += " NDim Error";  return false;
    696   }
    697 
    698   // Flagging bad updates ...
    699   ndim_ = 0;
    700 
    701   totsize_ = 1;
    702   int k;
    703   for(k=0; k<TARRAY_MAXNDIMS; k++) {
    704     size_[k] = 1;
    705     step_[k] = 0;
    706   }
    707   uint_4 minstep = step[0];
    708   for(k=0; k<ndim; k++) {
    709     size_[k] = siz[k] ;
    710     step_[k] = step[k];
    711     totsize_ *= size_[k];
    712     if (step_[k] < minstep)  minstep = step_[k];
    713   }
    714   if (minstep < 1) {
    715     exmsg += " Step(=0) Error";  return false;
    716   }
    717   if (totsize_ < 1) {
    718     exmsg += " Size Error";  return false;
    719   }
    720   uint_8 plast = 0;
    721   for(k=0; k<ndim; k++)   plast += (siz[k]-1)*step[k];
    722   if (plast == minstep*totsize_ )  moystep_ = minstep;
    723   else moystep_ = 0;
    724   minstep_ = minstep;
    725   offset_ = offset;
    726   // Default for matrices : Lines = Y , Columns = X
    727   macoli_ = 0;
    728   marowi_ = 1;
    729   // Update OK
    730   ndim_ = ndim;
    731   return true;
    732 }
    733 
    734 template <class T>
    735 bool TArray<T>::UpdateSizes(const TArray<T>& a, string & exmsg)
    736 {
    737   if (a.ndim_ >= TARRAY_MAXNDIMS) {
    738     exmsg += " NDim Error";  return false;
    739   }
    740 
    741   // Flagging bad updates ...
    742   ndim_ = 0;
    743 
    744   totsize_ = 1;
    745   int k;
    746   for(k=0; k<TARRAY_MAXNDIMS; k++) {
    747     size_[k] = 1;
    748     step_[k] = 0;
    749   }
    750   uint_4 minstep = a.step_[0];
    751   for(k=0; k<a.ndim_; k++) {
    752     size_[k] = a.size_[k] ;
    753     step_[k] = a.step_[k];
    754     totsize_ *= size_[k];
    755     if (step_[k] < minstep)  minstep = step_[k];
    756   }
    757   if (minstep < 1) {
    758     exmsg += " Step(=0) Error";  return false;
    759   }
    760   if (totsize_ < 1) {
    761     exmsg += " Size Error";  return false;
    762   }
    763 
    764   minstep_ = a.minstep_;
    765   moystep_ = a.moystep_;
    766   offset_ = a.offset_;
    767   macoli_ = a.macoli_;
    768   marowi_ = a.marowi_;
    769   // Update OK
    770   ndim_ = a.ndim_;
    771   return true;
    772 }
    773515
    774516template <class T>
     
    789531
    790532
    791 template <class T>
    792 void TArray<T>::SubArray(TArray<T> & ra, uint_4 ndim, uint_4 * siz, uint_4 * pos, uint_4 * step)
    793 {
    794   if ( (ndim > ndim_) || (ndim < 1) ) throw(SzMismatchError("TArray<T>::SubArray( ... ) NDim Error") );
    795   int k;
    796   for(k=0; k<ndim; k++)
    797     if ( (siz[k]*step[k]+pos[k]) > size_[k] ) 
    798       throw(SzMismatchError("TArray<T>::SubArray( ... ) Size/Pos Error") );
    799   (ra.mNDBlock).Share(mNDBlock);
    800   uint_8 offset = offset_;
    801   for(k=0; k<ndim_; k++) {
    802     offset += pos[k]*step_[k];
    803     step[k] *= step_[k];
    804   }
    805   string exm = "TArray<T>::SubArray() ";
    806   if (!ra.UpdateSizes(ndim, siz, step, offset,  exm))
    807      throw( ParmError(exm) );
    808   (ra.mNDBlock).Share(mNDBlock);
    809   return;
    810 }
    811533
    812534///////////////////////////////////////////////////////////////
  • trunk/SophyaLib/TArray/tarray.h

    r785 r787  
    99#include <math.h>
    1010#include <iostream.h>
     11#include "basarr.h"
    1112#include "ndatablock.h"
    1213#include <complex>
    13 #include "anydataobj.h"
    14 #include "ndatablock.h"
    15 #include "dvlist.h"
    1614#include "utilarr.h"
    1715
    18 
    19 //  Maximum number of dimensions for array
    20 #define TARRAY_MAXNDIMS  5
    2116
    2217namespace SOPHYA {
     
    2520template <class T> class FIO_TArray;
    2621
    27 //   ------------ classe template Array -----------
    28 template <class T>
    29 class TArray : public AnyDataObj {
     22//   --------------------------- classe template Array -----------------------
     23//  ( See BaseArray class for data organisation in  memory and related methods )
     24
     25template <class T>
     26class TArray : public BaseArray {
    3027public:
    3128  // Creation / destruction
     
    4340  virtual TArray<T>& operator = (const TArray<T>& a);
    4441
    45 
    4642  // Gestion taille/Remplissage
    4743  virtual void Clone(const TArray<T>& a);
    4844  virtual void ReSize(uint_4 ndim, uint_4 * siz, uint_4 step=1);
    4945  virtual void Realloc(uint_4 ndim, uint_4 * siz, uint_4 step=1, bool force=false);
    50   // Returns true if ndim and sizes are equal
    51   virtual bool CompareSizes(const TArray<T>& a);
     46
    5247  // Compacts size=1 array dimensions
    53   virtual TArray<T>& CompactDim();
    54 
    55   // Array dimensions
    56   inline uint_4 NbDimensions() const { return( ndim_ ); }
    57 
    58   inline uint_8 Size() const { return(totsize_); }
    59   inline uint_4 SizeX() const { return(size_[0]); }
    60   inline uint_4 SizeY() const { return(size_[1]); }
    61   inline uint_4 SizeZ() const { return(size_[2]); }
    62   inline uint_4 Size(int ka) const { return(size_[CheckDI(ka,1)]); }
    63 
    64   uint_4 MaxSizeKA() const ;
    65 
    66   // memory organisation - packing information
    67   inline bool   IsPacked() const { return(moystep_ == 1); }
    68   inline bool   IsPackedX() const { return(step_[0] == 1); }
    69   inline bool   IsPackedY() const { return(step_[1] == 1); }
    70   inline bool   IsPackedZ() const { return(step_[2] == 1); }
    71   inline bool   IsPacked(int ka) const { return(step_[CheckDI(ka,2)] == 1); }
    72 
    73   inline uint_4 MinStep() const  { return(minstep_); }
    74   inline uint_4 AvgStep() const  { return(moystep_); }
    75   inline uint_4 StepX() const { return(step_[0]); }
    76   inline uint_4 StepZ() const { return(step_[1]); }
    77   inline uint_4 StepY() const { return(step_[2]); }
    78   inline uint_4 Step(int ka) const { return(step_[CheckDI(ka,3)]); }
    79 
    80   uint_4 MinStepKA() const ;
    81 
    82   uint_8 Offset(uint_8 ip=0) const ;
    83 
    84 
    85   // Temporaire?
    86   inline bool   IsTemp(void) const {return mNDBlock.IsTemp();}
    87   inline void   SetTemp(bool temp=false) const {mNDBlock.SetTemp(temp);}
     48  virtual TArray<T>& CompactAllDimensions();
     49  virtual TArray<T>& CompactTrailingDimensions();
    8850
    8951  // SubArrays
    9052  virtual TArray<T> operator () (Range rx, Range ry, Range rz=0, Range rt=0, Range ru=0);
    9153
    92   // Acces to data
     54
     55  // ---- Access to data
     56  // Definition of virtual element acces method inherited from BaseArray class
     57  virtual double ValueAtPosition(uint_8 ip) const;
     58
     59  // Data Access: operator overloaded inline acces methods
    9360  inline T const& operator()(uint_4 ix, uint_4 iy, uint_4 iz) const ;
    9461  inline T&       operator()(uint_4 ix, uint_4 iy, uint_4 iz);
     
    10875  inline const  NDataBlock<T>& DataBlock() const {return mNDBlock;}
    10976
     77  // Temporaire?
     78  inline bool   IsTemp(void) const {return mNDBlock.IsTemp();}
     79  inline void   SetTemp(bool temp=false) const {mNDBlock.SetTemp(temp);}
     80
    11081// Operations diverses  = , +=, ...
    11182// Conversion en type T, if Size() == 1
    112   inline operator T();
     83  inline T toScalar();
    11384// Met les elements a une suite de valeurs
    11485  virtual TArray<T>&  operator = (Sequence seq);
     
    12394  virtual TArray<T>&  operator += (const TArray<T>& a);
    12495  virtual TArray<T>&  operator -= (const TArray<T>& a);
    125 // Multilication, division element par element les deux tableaux
     96// Multiplication, division element par element les deux tableaux
    12697  virtual TArray<T>&  MultElt(const TArray<T>& a);
    12798  virtual TArray<T>&  DivElt(const TArray<T>& a);
    12899
    129 // Application d'une fonction
    130   virtual TArray<T>&  ApplyFunction(Arr_DoubleFunctionOfX f);
    131   virtual TArray<T>&  ApplyFunction(Arr_FloatFunctionOfX f);
    132 
    133100// Impression, I/O, ...
    134   static void   SetMaxPrint(uint_4 nprt=50);   
    135   void          Show(ostream& os, bool si=false) const;
    136   inline void   Show() const { Show(cout); }
    137   void          Print(ostream& os, int_4 maxprt=-1, bool si=false) const ;
    138 
    139 //  Objet DVList info
    140   DVList&       Info();
     101  virtual string DataType() const;   // definition of abstract method inherited from BaseArray
     102  virtual void  Print(ostream& os, int_4 maxprt=-1, bool si=false) const ;
    141103
    142104//  Pour la gestion de persistance
     
    144106
    145107protected:
    146   // Verifie la compatibilite de l'index de dimension
    147   inline int CheckDI(int ka, int msg) const ;
    148   // Verifie la compatibilite des bornes d'index
    149   inline void CheckBound(int ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu, int msg) const ;
    150   // Changing Sizes/NDim ... return true if OK
    151   bool UpdateSizes(uint_4 ndim, const uint_4 * siz, uint_4 step, uint_8 offset, string & exmsg);
    152   bool UpdateSizes(uint_4 ndim, const uint_4 * siz, const uint_4 * step, uint_8 offset, string & exmsg);
    153   bool UpdateSizes(const TArray<T>& a, string & exmsg);
    154   static uint_8 ComputeTotalSize(uint_4 ndim, uint_4 * siz, uint_4 step, uint_8 offset) ;
    155108  // partage les donnees si "a" temporaire, clone sinon.
    156109  void CloneOrShare(const TArray<T>& a);
    157110  // Share: partage les donnees de "a"
    158111  void Share(const TArray<T>& a);
    159   // Extraction de sous-tableau
    160   virtual void SubArray(TArray<T> & ra, uint_4 ndim, uint_4 * siz, uint_4 * pos, uint_4 * step);
    161 
    162   uint_4 ndim_;                   // nb of dimensions
    163   uint_4 size_[TARRAY_MAXNDIMS];     // array size in each dimension
    164   uint_8 totsize_;                   // Total number of elements
    165   uint_4 step_[TARRAY_MAXNDIMS];     // two consecutive elements distance in a given dimension
    166   uint_4 minstep_;                   // minimal step (in any axes)
    167   uint_4 moystep_;                   // mean step 0 non regular steps
    168   uint_8 offset_;              // global offset -> position of elem[0] in DataBlock
     112
    169113  NDataBlock<T> mNDBlock;      // Le bloc des donnees
    170   uint_4 marowi_, macoli_;     // For matrices, Row index and column index in dimensions
    171 
    172   DVList* mInfo;               // Infos (variables) attachees au tableau
    173 
    174   static char * ck_op_msg_[6];  // Operation messages for CheckDI() CheckBound()
    175   static uint_4 max_nprt_;      // Nb maxi d'elements imprimes
    176114};
    177115
     
    218156    {TArray<T> result(a); result.SetTemp(true); result += b; return result;}
    219157
    220 ////////////////////////////////////////////////
    221 //  Calcul de fonction
    222 template <class T>
    223 inline TArray<T> sin(const TArray<T>& a)
    224     {TArray<T> result(a); result.SetTemp(true); result.ApplyFunction(sin); return result;}
    225 
    226 template <class T>
    227 inline TArray<T> cos(const TArray<T>& a)
    228     {TArray<T> result(a); result.SetTemp(true); result.ApplyFunction(cos); return result;}
    229 
    230 // --------------------------------------------------
    231 //        Methodes inline de verification
    232 // --------------------------------------------------
    233 template <class T>
    234 inline int TArray<T>::CheckDI(int ka, int msg)  const
    235 {
    236   if ( (ka < 0) || (ka >= ndim_) ) {
    237     string txt = "TArray<T>::CheckDimensionIndex/Error ";   txt += ck_op_msg_[msg];
    238     throw(ParmError(txt));
    239   }
    240   return(ka);
    241 }
    242 
    243 template <class T>
    244 inline void TArray<T>::CheckBound(int ix, uint_4 iy, uint_4 iz, uint_4 it, uint_4 iu, int msg)  const
    245 {
    246   if ( (ix >= size_[0]) || (iy >= size_[1]) || (iz > size_[2]) ||
    247        (it >= size_[3]) || (iu >= size_[4]) ) {
    248     string txt = "TArray<T>::CheckArrayBound/Error ";   txt += ck_op_msg_[msg];
    249     throw(ParmError(txt));
    250   }
    251   return;
    252 }
    253 
    254158
    255159// --------------------------------------------------
     
    349253
    350254template <class T>
    351 inline TArray<T>::operator T()
     255inline T TArray<T>::toScalar()
    352256{
    353257  if (Size() != 1) throw(SzMismatchError("TArray<T>::operator T() Size() != 1")) ;
Note: See TracChangeset for help on using the changeset viewer.