Changeset 1103 in Sophya for trunk/SophyaLib


Ignore:
Timestamp:
Jul 27, 2000, 2:00:10 AM (25 years ago)
Author:
ansari
Message:

Suite operations entre matrices de <> MemOrg, Amelioration des Sequences - Reza 27/7/2000

Location:
trunk/SophyaLib/TArray
Files:
9 edited

Legend:

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

    r1099 r1103  
    301301  else {
    302302    smo = false;
    303     if ( (size_[marowi_] != a.size_[marowi_]) ||
    304          (size_[macoli_] != a.size_[macoli_])  ) return(false);
     303    if ( (size_[marowi_] != a.size_[a.marowi_]) ||
     304         (size_[macoli_] != a.size_[a.macoli_])  ) return(false);
     305    if (ndim_ > 2) 
     306      for(uint_4 k=2; k<ndim_; k++)
     307        if (size_[k] != a.size_[k])  return(false);
    305308    if ( (macoli_ == a.macoli_) && (marowi_ == a.marowi_) ||
    306309         (veceli_ == a.veceli_) )  smo = true;
     
    353356int  BaseArray::MinStepKA() const
    354357{
    355   for(int ka=0; ka<ndim_; ka++)
    356     if (step_[ka] == minstep_) return(ka);
     358  for(uint_4 ka=0; ka<ndim_; ka++)
     359    if (step_[ka] == minstep_) return((int)ka);
    357360  return(0);
    358361}
     
    363366  int ka = 0;
    364367  uint_4 mx = size_[0];
    365   for(int k=0; k<ndim_; k++) 
     368  for(uint_4 k=1; k<ndim_; k++) 
    366369    if (size_[k] > mx) {  ka = k;  mx = size_[k]; }
    367370  return(ka);
     
    475478    os << " MemoryMapping=" << GetMemoryMapping() << " VecType= " << GetVectorType()
    476479       << " RowsKA= " << RowsKA() << " ColsKA= " << ColsKA()
    477        << " VectKA=" << VectKA() << endl;
     480       << " VectKA=" << VectKA() << " ArrayType=" << arrtype_ << endl;
    478481  }
    479482  if (!si && (prt_lev_ < 2)) return;
  • trunk/SophyaLib/TArray/tarray.cc

    r1099 r1103  
    200200{
    201201  string exmsg = "TArray<T>::CloneOrShare()";
    202   if (!UpdateSizes(a.ndim_, a.size_, a.step_, a.offset_, exmsg))  throw( ParmError(exmsg) );
     202  if (!UpdateSizes(a, exmsg))  throw( ParmError(exmsg) );
    203203  mNDBlock.CloneOrShare(a.mNDBlock);
     204  if (mInfo) {delete mInfo; mInfo = NULL;}
     205  if (a.mInfo) mInfo = new DVList(*(a.mInfo));
    204206}
    205207
     
    209211{
    210212  string exmsg = "TArray<T>::Share()";
    211   if (!UpdateSizes(a.ndim_, a.size_, a.step_, a.offset_, exmsg))  throw( ParmError(exmsg) );
     213  if (!UpdateSizes(a, exmsg))  throw( ParmError(exmsg) );
    212214  mNDBlock.Share(a.mNDBlock);
     215  if (mInfo) {delete mInfo; mInfo = NULL;}
     216  if (a.mInfo) mInfo = new DVList(*(a.mInfo));
    213217}
    214218
     
    363367 */
    364368template <class T>
    365 TArray<T>& TArray<T>::SetSeq(Sequence seq)
     369TArray<T>& TArray<T>::SetSeq(Sequence const & seq)
    366370{
    367371  if (NbDimensions() < 1)
    368372    throw RangeCheckError("TArray<T>::SetSeq(Sequence ) - Not Allocated Array ! ");
     373 
    369374  T * pe;
    370375  uint_8 j,k;
    371   if (AvgStep() > 0)   {  // regularly spaced elements
    372     uint_8 step = AvgStep();
    373     pe = Data();
    374     for(k=0; k<totsize_; k++ )  pe[k*step] = (T) seq(k);
    375   }
    376   else {    // Non regular data spacing ...
    377     //    uint_4 ka = MaxSizeKA();
    378     uint_4 ka = 0;
    379     uint_8 step = Step(ka);
    380     uint_8 gpas = Size(ka);
    381     uint_8 naxa = Size()/Size(ka);
    382     for(j=0; j<naxa; j++)  {
    383       pe = mNDBlock.Begin()+Offset(ka,j);
    384       for(k=0; k<gpas; k++)  pe[k*step] = (T) seq(j*gpas+k);
    385     }
     376  int ka;
     377  if (arrtype_ == 0)  ka = 0;
     378  else ka = macoli_;
     379  uint_8 step = Step(ka);
     380  uint_8 gpas = Size(ka);
     381  uint_8 naxa = Size()/Size(ka);
     382  for(j=0; j<naxa; j++)  {
     383    pe = mNDBlock.Begin()+Offset(ka,j);
     384#if !defined(__GNUG__)
     385    for(k=0; k<gpas; k++)  pe[k*step] = (T) seq(j*gpas+k);
     386#else
     387    // g++ (up to 2.95.1) se melange les pinceaux  s'il y a le cast (T) pour l'instanciation des complexes
     388    for(k=0; k<gpas; k++)  pe[k*step] = seq(j*gpas+k);
     389#endif
    386390  }
    387391  return(*this);
  • trunk/SophyaLib/TArray/tarray.h

    r1081 r1103  
    122122  inline T toScalar();
    123123// Met les elements a une suite de valeurs
    124   virtual TArray<T>&  SetSeq(Sequence seq);
     124  virtual TArray<T>&  SetSeq(Sequence const & seq);
    125125  //! Fill TArray with Sequence \b seq
    126   inline  TArray<T>&  operator = (Sequence seq)    { return SetSeq(seq); }
     126  inline  TArray<T>&  operator = (Sequence const & seq)    { return SetSeq(seq); }
    127127// A = x (tous les elements a x)
    128128  virtual TArray<T>&  SetT(T x);
  • trunk/SophyaLib/TArray/tmatrix.cc

    r1099 r1103  
    1 // $Id: tmatrix.cc,v 1.14 2000-07-26 16:29:45 ansari Exp $
     1// $Id: tmatrix.cc,v 1.15 2000-07-27 00:00:09 ansari Exp $
    22//                         C.Magneville          04/99
    33#include "machdefs.h"
     
    5454{
    5555  arrtype_ = 1;   // Type = Matrix
     56  UpdateMemoryMapping(a, SameMemoryMapping);
    5657}
    5758
     
    6667{
    6768  arrtype_ = 1;   // Type = Matrix
     69  UpdateMemoryMapping(a, SameMemoryMapping);
    6870}
    6971
     
    111113{
    112114  arrtype_ = 1;   // Type = Matrix
     115  UpdateMemoryMapping(a, SameMemoryMapping);
    113116  SetBA(a);
    114117}
  • trunk/SophyaLib/TArray/tmatrix.h

    r1099 r1103  
    8282
    8383  // = : fill matrix with a Sequence \b seq
    84   inline  TMatrix<T>&  operator = (Sequence seq)    { SetSeq(seq); return(*this); }
     84  inline  TMatrix<T>&  operator = (Sequence const & seq)    { SetSeq(seq); return(*this); }
    8585
    8686  // Operations diverses  avec une constante
     
    137137              r*step_[marowi_] + c*step_[macoli_] ) );
    138138}
     139////////////////////////////////////////////////////////////////
     140// Surcharge d'operateurs A (+,-,*,/) (T) x
     141
     142/*! \ingroup TMatrix \fn operator+(const TMatrix<T>&,T)
     143  \brief Operator TMatrix = TMatrix + constant */
     144template <class T> inline TMatrix<T> operator + (const TMatrix<T>& a, T b)
     145    {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     146    result.Add(b); return result;}
     147
     148/*! \ingroup TMatrix \fn operator+(T,const TMatrix<T>&)
     149  \brief Operator TMatrix = constant + TMatrix */
     150template <class T> inline TMatrix<T> operator + (T b,const TMatrix<T>& a)
     151    {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     152    result.Add(b); return result;}
     153
     154/*! \ingroup TMatrix \fn operator-(const TMatrix<T>&,T)
     155  \brief Operator TMatrix = TMatrix - constant */
     156template <class T> inline TMatrix<T> operator - (const TMatrix<T>& a, T b)
     157    {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     158    result.Sub(b); return result;}
     159
     160/*! \ingroup TMatrix \fn operator-(T,const TMatrix<T>&)
     161  \brief Operator TMatrix = constant - TMatrix */
     162template <class T> inline TMatrix<T> operator - (T b,const TMatrix<T>& a)
     163    {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     164    result.Sub(b,true); return result;}
     165
     166/*! \ingroup TMatrix \fn operator*(const TMatrix<T>&,T)
     167  \brief Operator TMatrix = TMatrix * constant */
     168template <class T> inline TMatrix<T> operator * (const TMatrix<T>& a, T b)
     169    {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     170    result.Mul(b); return result;}
     171
     172/*! \ingroup TMatrix \fn operator*(T,const TMatrix<T>&)
     173  \brief Operator TMatrix = constant * TMatrix */
     174template <class T> inline TMatrix<T> operator * (T b,const TMatrix<T>& a)
     175    {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     176    result.Mul(b); return result;}
     177
     178/*! \ingroup TMatrix \fn operator/(const TMatrix<T>&,T)
     179  \brief Operator TMatrix = TMatrix / constant */
     180template <class T> inline TMatrix<T> operator / (const TMatrix<T>& a, T b)
     181    {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     182    result.Div(b); return result;}
     183
     184/*! \ingroup TMatrix \fn operator/(T,const TMatrix<T>&)
     185  \brief Operator TMatrix = constant / TMatrix  */
     186template <class T> inline TMatrix<T> operator / (T b, const TMatrix<T>& a)
     187    {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
     188    result.Div(b, true); return result;}
     189
    139190
    140191// Surcharge d'operateurs C = A (+,-) B
  • trunk/SophyaLib/TArray/tvector.cc

    r1099 r1103  
    1 // $Id: tvector.cc,v 1.9 2000-07-26 16:29:46 ansari Exp $
     1// $Id: tvector.cc,v 1.10 2000-07-27 00:00:10 ansari Exp $
    22//                         C.Magneville          04/99
    33#include "machdefs.h"
     
    101101template <class T>
    102102TVector<T>::TVector(const BaseArray& a)
    103 : TMatrix<T>()
    104 {
    105   arrtype_ = 2;   // Type = Vector
    106   SetBA(a);
     103: TMatrix<T>(a)
     104{
     105  if ( (size_[0] != 1) && (size_[1] != 1) )
     106    throw SzMismatchError("TVector<T>::TVector(const BaseArray& a) NRows()!=1 && NCols()!=1 ");
     107  arrtype_ = 2;   // Type = Vector
    107108}
    108109
  • trunk/SophyaLib/TArray/tvector.h

    r1099 r1103  
    5858  // Operateur d'affectation
    5959  //! Fill the vector with Sequence \b seq
    60   inline  TVector<T>&  operator = (Sequence seq) { SetSeq(seq); return(*this); }
     60  inline  TVector<T>&  operator = (Sequence const & seq) { SetSeq(seq); return(*this); }
    6161
    6262  // Operations diverses  avec une constante
  • trunk/SophyaLib/TArray/utilarr.cc

    r935 r1103  
    77
    88// Classe utilitaires
     9
     10Sequence::~Sequence()
     11{
     12}
    913
    1014//////////////////////////////////////////////////////////
     
    2731  sig_ = s;
    2832}
     33RandomSequence::~RandomSequence()
     34{
     35}
    2936
    3037//! Return random sequence values.
     
    4148}
    4249
     50MuTyV & RandomSequence::Value(uint_8 k) const
     51{
     52  if (typ_ == Flat) retv_ = drandpm1()*sig_ + mean_;
     53  else retv_ = GauRnd(mean_, sig_);
     54  return retv_;
     55}
     56
    4357
    4458//////////////////////////////////////////////////////////
    4559/*!
    46   \class SOPHYA::Sequence
     60  \class SOPHYA::RegularSequence
    4761  \ingroup TArray
    4862  Class to generate a sequence of values
     
    5569  \param f : pointer to the sequence function
    5670
    57   See \ref SequenceOperat "operator()"
     71  See \ref RegularSequenceOperat "operator()"
    5872 */
    59 Sequence::Sequence(double start, double step, Arr_DoubleFunctionOfX f)
    60   : rseq_(RandomSequence::Gaussian)
     73RegularSequence::RegularSequence(double start, double step, Arr_DoubleFunctionOfX f)
    6174{
    6275  start_ = start;
    6376  step_ = step;
    6477  myf_ = f;
    65   fgrseq_ = false;
    6678}
    6779
    68 //! Constructor
    69 /*!
    70   \param rseq : RandomSequence
    71 
    72   See \ref SequenceOperat "operator()"
    73  */
    74 Sequence::Sequence(RandomSequence rseq)
     80RegularSequence::~RegularSequence()
    7581{
    76   start_ = 0.;
    77   step_ = 1.;
    78   myf_ = NULL; 
    79   rseq_ = rseq;
    80   fgrseq_ = true;
    8182}
    8283
     
    8485/*!
    8586  \param k : index of the value
    86   \anchor SequenceOperat
     87  \anchor RegularSequenceOperat
    8788
    8889  If the constructor was done with RandomSequence, return a RandomSequence
     
    9495  \return the \b k th value
    9596 */
    96 double Sequence::operator () (uint_4 k)
     97
     98MuTyV & RegularSequence::Value (uint_8 k) const
    9799{
    98   if (fgrseq_) return(rseq_.Rand());
    99   else {
    100     double x = start_+(double)k*step_;
    101     if (myf_)  return(myf_(x));
    102     else return x;
    103   }
     100  double x = start_+(double)k*step_;
     101  if (myf_)  x = myf_(x);
     102  retv_ = x;
     103  return(retv_);
     104}
     105
     106EnumeratedSequence::~EnumeratedSequence()
     107{
     108}
     109
     110MuTyV & EnumeratedSequence::Value (uint_8 k) const
     111{
     112  if (k >= vecv_.size())  retv_ = 0;
     113  else retv_ = vecv_[k];
     114  return(retv_);
     115}
     116
     117EnumeratedSequence & EnumeratedSequence::operator , (MuTyV const & v)
     118{
     119  vecv_.push_back(v);
     120  return(*this);
    104121}
    105122
  • trunk/SophyaLib/TArray/utilarr.h

    r956 r1103  
    77
    88#include "machdefs.h"
     9#include "mutyv.h"
     10
    911#include <stdlib.h>
     12#include <vector>
    1013
    1114namespace SOPHYA {   
     
    2629//////////////////////////////////////////////////////////
    2730//! Class to generate a random sequence of values
    28 class RandomSequence {
     31class Sequence {
     32public:
     33  virtual ~Sequence();
     34  virtual MuTyV & Value(uint_8 k) const = 0;
     35  inline MuTyV & operator () (uint_8 k) const { return(Value(k)) ; }
     36};
     37
     38class RandomSequence : public Sequence {
    2939public:
    3040  //! to define the generator type
     
    3444    };
    3545
    36   RandomSequence(int typ = RandomSequence::Gaussian, double m=0., double s=1.);
    37   double Rand();
     46  explicit RandomSequence(int typ = RandomSequence::Gaussian, double m=0., double s=1.);
     47  virtual  ~RandomSequence();
     48  virtual MuTyV & Value(uint_8 k) const ;
     49  double   Rand();
     50
    3851protected:
    3952  int typ_;            //!< random generation type
    4053  double mean_, sig_;  //!< generation parameters mean and sigma (if needed)
     54  mutable MuTyV retv_;
    4155};
    4256
     
    4458//////////////////////////////////////////////////////////
    4559//! Class to generate a sequence of values
    46 class Sequence {
     60class RegularSequence : public Sequence {
    4761public:
    48   explicit Sequence (double start=0., double step=1., Arr_DoubleFunctionOfX f=NULL);
    49   explicit Sequence (RandomSequence rseq);
     62  explicit RegularSequence (double start=0., double step=1., Arr_DoubleFunctionOfX f=NULL);
     63  virtual  ~RegularSequence();
    5064
    5165  //! return start value of the sequence
     
    5367  //! return step value of the sequence
    5468  inline double & Step() { return step_; }
    55   double operator () (uint_4 k);
     69
     70  virtual MuTyV & Value(uint_8 k) const ;
     71
    5672protected:
    5773  double start_;              //!< start value of the sequence
    5874  double step_;               //!< step value of the sequence
    5975  Arr_DoubleFunctionOfX myf_; //!< pointer to the sequence function
    60   bool fgrseq_;               //!< true if RandomSequence is used
    61   RandomSequence rseq_;       //!< RandomSequence
     76  mutable MuTyV retv_;
    6277};
     78
     79class EnumeratedSequence : public Sequence  {
     80public:
     81  virtual ~EnumeratedSequence();
     82  virtual MuTyV & Value(uint_8 k) const ;
     83  EnumeratedSequence & operator , (MuTyV const & v);
     84private:
     85  vector<MuTyV> vecv_;
     86  mutable MuTyV retv_;
     87};
     88
     89inline EnumeratedSequence operator , (MuTyV const & a, MuTyV const & b)
     90{ EnumeratedSequence seq;   return ((seq,a),b) ; }
    6391
    6492//////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.