Changeset 2564 in Sophya


Ignore:
Timestamp:
Jul 26, 2004, 7:30:40 PM (21 years ago)
Author:
ansari
Message:

Remplacement methodes Add/Mul/Sub/Div(T x) par AddCst/MulCst/SubCst/DivCst(T x, TArray<T> res) ds TArray - Reza 26 Juillet 2004

Location:
trunk/SophyaLib/TArray
Files:
4 edited

Legend:

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

    r2338 r2564  
    7070  \param siz[ndim] : size along each dimension
    7171  \param step : step (same for all dimensions)
    72  */
    73 template <class T>
    74 TArray<T>::TArray(int_4 ndim, const sa_size_t * siz, sa_size_t step)
    75   : BaseArray() , mNDBlock(ComputeTotalSize(ndim, siz, step, 1))
     72  \param fzero : if \b true , set array elements to zero
     73 */
     74template <class T>
     75TArray<T>::TArray(int_4 ndim, const sa_size_t * siz, sa_size_t step, bool fzero)
     76  : BaseArray() , mNDBlock(ComputeTotalSize(ndim, siz, step, 1), fzero)
    7677{
    7778  string exmsg = "TArray<T>::TArray(int_4, sa_size_t *, sa_size_t)";
     
    8283/*!
    8384  \param nx,ny,nz,nt,nu : sizes along first, second, third, fourth and fifth dimension
    84  */
    85 template <class T>
    86 TArray<T>::TArray(sa_size_t nx, sa_size_t ny, sa_size_t nz, sa_size_t nt, sa_size_t nu)
     85  \param fzero : if \b true , set array elements to zero
     86 */
     87template <class T>
     88TArray<T>::TArray(sa_size_t nx, sa_size_t ny, sa_size_t nz, sa_size_t nt, sa_size_t nu, bool fzero)
    8789  : BaseArray() , mNDBlock(nx*((ny>0)?ny:1)*((nz>0)?nz:1)*((nt>0)?nt:1)*((nu>0)?nu:1))
    8890{
     
    268270  \param siz[ndim] : size along each dimension
    269271  \param step : step (same for all dimensions)
    270  */
    271 template <class T>
    272 void TArray<T>::ReSize(int_4 ndim, sa_size_t * siz, sa_size_t step)
     272  \param fzero : if \b true , set array elements to zero
     273 */
     274template <class T>
     275void TArray<T>::ReSize(int_4 ndim, sa_size_t * siz, sa_size_t step, bool fzero)
    273276{
    274277  if (arrtype_ != 0) {
     
    280283  string exmsg = "TArray<T>::ReSize(int_4 ...)";
    281284  if (!UpdateSizes(ndim, siz, step, 0, exmsg))  throw( ParmError(exmsg) );
    282   mNDBlock.ReSize(totsize_);   
     285  mNDBlock.ReSize(totsize_, fzero);   
    283286}
    284287
     
    287290  The array size and memory layout are copied from the array \b a.
    288291  \param a : Array used as template for setting the size and memory layout.
    289  */
    290 template <class T>
    291 void TArray<T>::ReSize(const BaseArray& a)
     292  \param pack : if \b true , create a packed array, else same memory layout as \b a.
     293  \param fzero : if \b true , set array elements to zero
     294 */
     295template <class T>
     296void TArray<T>::ReSize(const BaseArray& a, bool pack, bool fzero)
    292297{
    293298  if (arrtype_ != 0) {
     
    298303  }
    299304  string exmsg = "TArray<T>::ReSize(const TArray<T>&)";
    300   if (!UpdateSizes(a, exmsg))  throw( ParmError(exmsg) );
    301   mNDBlock.ReSize(totsize_);     
     305  if (pack) {
     306    sa_size_t siz[BASEARRAY_MAXNDIMS];
     307    for(int ksz=0; ksz<BASEARRAY_MAXNDIMS; ksz++) siz[ksz] = a.Size(ksz);
     308    if (!UpdateSizes(a.NbDimensions(), siz, 1, 0, exmsg))  throw( ParmError(exmsg) );
     309    mNDBlock.ReSize(totsize_, fzero);       
     310  }
     311  else {
     312    if (!UpdateSizes(a, exmsg))  throw( ParmError(exmsg) );
     313    mNDBlock.ReSize(totsize_);     
     314  }
    302315}
    303316
     
    491504}
    492505
    493 //! Add a constant value \b x to an array
    494 template <class T>
    495 TArray<T>& TArray<T>::Add(T x)
    496 {
    497   if (NbDimensions() < 1)
    498     throw RangeCheckError("TArray<T>::Add(T )  - Not Allocated Array ! ");
    499   T * pe;
    500   sa_size_t j,k;
    501   if (AvgStep() > 0)   {  // regularly spaced elements
    502     sa_size_t step = AvgStep();
    503     sa_size_t maxx = totsize_*step;
    504     pe = Data();
    505     for(k=0; k<maxx; k+=step )  pe[k] += x;
    506   }
    507   else {    // Non regular data spacing ...
    508     int_4 ka = MaxSizeKA();
    509     sa_size_t step = Step(ka);
    510     sa_size_t gpas = Size(ka)*step;
    511     sa_size_t naxa = Size()/Size(ka);
    512     for(j=0; j<naxa; j++)  {
    513       pe = mNDBlock.Begin()+Offset(ka,j);
    514       for(k=0; k<gpas; k+=step)  pe[k] += x;
    515     }
    516   }
    517   return(*this);
    518 }
    519 
    520 //! Substract a constant value \b x to an array
     506//! Add a constant value \b x to the source array and store the result in \b res.
    521507/*!
    522 Substract a constant from the *this = *this-x
    523 \param fginv == true : Perfoms the inverse subtraction (*this = x-(*this))
    524 */
    525 template <class T>
    526 TArray<T>& TArray<T>::Sub(T x, bool fginv)
    527 {
    528   if (NbDimensions() < 1)
    529     throw RangeCheckError("TArray<T>::Sub(T )  - Not Allocated Array ! ");
    530   T * pe;
    531   sa_size_t j,k;
    532   if (AvgStep() > 0)   {  // regularly spaced elements
    533     sa_size_t step = AvgStep();
    534     sa_size_t maxx = totsize_*step;
    535     pe = Data();
    536     if (fginv)
    537       for(k=0; k<maxx; k+=step )  pe[k] = x-pe[k];
    538     else
    539       for(k=0; k<maxx; k+=step )  pe[k] -= x;
    540   }
    541   else {    // Non regular data spacing ...
    542     int_4 ka = MaxSizeKA();
    543     sa_size_t step = Step(ka);
    544     sa_size_t gpas = Size(ka)*step;
    545     sa_size_t naxa = Size()/Size(ka);
    546     for(j=0; j<naxa; j++)  {
    547       pe = mNDBlock.Begin()+Offset(ka,j);
    548       if (fginv)
    549         for(k=0; k<gpas; k+=step)  pe[k] = x-pe[k];
     508Add a constant to the source array \b this and store the result in \b res (res = *this+x). 
     509If not initially allocated, the output array \b res is automatically
     510resized as a packed array with the same sizes as the source (this) array.
     511Returns a reference to the output array \b res.
     512\param x : constant to add to the array elements
     513\param res : Output array containing the result (res=this+x).
     514*/
     515template <class T>
     516TArray<T>& TArray<T>::AddCst(T x, TArray<T>& res) const
     517{
     518  if (NbDimensions() < 1)
     519    throw RangeCheckError("TArray<T>::AddCst(T,res)  - Not allocated source array ");
     520  if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     521  bool smo;
     522  if (!CompareSizes(res, smo))
     523    throw(SzMismatchError("TArray<T>::AddCst(T, res) SizeMismatch(this,res) ")) ;
     524
     525  const T * pe;
     526  T * per;
     527  sa_size_t j,k,kr;
     528  if (smo && (IsPacked() > 0) && (res.IsPacked() > 0))   {  // regularly spaced elements
     529    sa_size_t maxx = totsize_;
     530    pe = Data();
     531    per = res.Data();
     532    for(k=0; k<maxx; k++) { *per = (*pe)+x;  per++;  pe++; }
     533  }
     534  else {    // Non regular data spacing ...
     535    int_4 ax,axr;
     536    sa_size_t step, stepr;
     537    sa_size_t gpas, naxr;
     538    GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr);
     539    for(j=0; j<naxr; j++)  {
     540      pe = mNDBlock.Begin()+Offset(ax,j);
     541      per = res.DataBlock().Begin()+res.Offset(axr,j);
     542      for(k=0, kr=0;  k<gpas;  k+=step, kr+=stepr)  per[kr] = pe[k]+x;
     543    }
     544  }
     545  return(res);
     546}
     547
     548//! Subtract a constant value \b x from the source array and store the result in \b res.
     549/*!
     550Subtract a constant from the source array \b this and store the result in \b res (res = *this-x). 
     551If not initially allocated, the output array \b res is automatically
     552resized as a packed array with the same sizes as the source (this) array.
     553Returns a reference to the output array \b res.
     554\param x : constant to subtract from the array elements
     555\param res : Output array containing the result (res=this+x or res=x-this).
     556\param fginv == true : Invert subtraction argument order (*this = x-(*this))
     557*/
     558template <class T>
     559TArray<T>& TArray<T>::SubCst(T x, TArray<T>& res, bool fginv) const
     560{
     561  if (NbDimensions() < 1)
     562    throw RangeCheckError("TArray<T>::SubCst(T,res)  - Not allocated source array ");
     563  if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     564  bool smo;
     565  if (!CompareSizes(res, smo))
     566    throw(SzMismatchError("TArray<T>::SubCst(T, res) SizeMismatch(this,res) ")) ;
     567
     568  const T * pe;
     569  T * per;
     570  sa_size_t j,k,kr;
     571  if (smo && (IsPacked() > 0) && (res.IsPacked() > 0))   {  // regularly spaced elements
     572    sa_size_t maxx = totsize_;
     573    pe = Data();
     574    per = res.Data();
     575    if (!fginv)
     576      for(k=0; k<maxx; k++) { *per = (*pe)-x;  per++;  pe++; }
     577    else
     578      for(k=0; k<maxx; k++) { *per = x-(*pe);  per++;  pe++; }
     579  }
     580  else {    // Non regular data spacing ...
     581    int_4 ax,axr;
     582    sa_size_t step, stepr;
     583    sa_size_t gpas, naxr;
     584    GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr);
     585    for(j=0; j<naxr; j++)  {
     586      pe = mNDBlock.Begin()+Offset(ax,j);
     587      per = res.DataBlock().Begin()+res.Offset(axr,j);
     588      if (!fginv)
     589        for(k=0, kr=0;  k<gpas;  k+=step, kr+=stepr)  per[kr] = pe[k]-x;
    550590      else
    551         for(k=0; k<gpas; k+=step)  pe[k] -= x;
    552     }
    553   }
    554   return(*this);
    555 }
    556 
    557 //! Multiply an array by a constant value \b x
    558 template <class T>
    559 TArray<T>& TArray<T>::Mul(T x)
    560 {
    561   if (NbDimensions() < 1)
    562     throw RangeCheckError("TArray<T>::Mul(T )  - Not Allocated Array ! ");
    563   T * pe;
    564   sa_size_t j,k;
    565   if (AvgStep() > 0)   {  // regularly spaced elements
    566     sa_size_t step = AvgStep();
    567     sa_size_t maxx = totsize_*step;
    568     pe = Data();
    569     for(k=0; k<maxx; k+=step )  pe[k] *= x;
    570   }
    571   else {    // Non regular data spacing ...
    572     int_4 ka = MaxSizeKA();
    573     sa_size_t step = Step(ka);
    574     sa_size_t gpas = Size(ka)*step;
    575     sa_size_t naxa = Size()/Size(ka);
    576     for(j=0; j<naxa; j++)  {
    577       pe = mNDBlock.Begin()+Offset(ka,j);
    578       for(k=0; k<gpas; k+=step)  pe[k] *= x;
    579     }
    580   }
    581   return(*this);
    582 }
    583 
    584 //! Divide an array by a constant value \b x
     591        for(k=0, kr=0;  k<gpas;  k+=step, kr+=stepr)  per[kr] = x-pe[k];
     592    }
     593  }
     594  return(res);
     595}
     596
     597//! Multiply the source array by a constant value \b x and store the result in \b res.
    585598/*!
    586 Divide the array by a constant *this = *this/x
    587 \param fginv == true : Perfoms the inverse division (*this = x/(*this))
    588 */
    589 template <class T>
    590 TArray<T>& TArray<T>::Div(T x, bool fginv)
    591 {
    592   if (NbDimensions() < 1)
    593     throw RangeCheckError("TArray<T>::Div(T )  - Not Allocated Array ! ");
     599Multiply the source array \b this by a constant \b x and store the result in \b res (res = *this*x). 
     600If not initially allocated, the output array \b res is automatically
     601resized as a packed array with the same sizes as the source (this) array.
     602Returns a reference to the output array \b res.
     603\param x : Array elements are multiplied by x
     604\param res : Output array containing the result (res=this*x).
     605*/
     606template <class T>
     607TArray<T>& TArray<T>::MulCst(T x, TArray<T>& res) const
     608{
     609  if (NbDimensions() < 1)
     610    throw RangeCheckError("TArray<T>::MulCst(T,res)  - Not allocated source array ");
     611  if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     612  bool smo;
     613  if (!CompareSizes(res, smo))
     614    throw(SzMismatchError("TArray<T>::MulCst(T, res) SizeMismatch(this,res) ")) ;
     615
     616  const T * pe;
     617  T * per;
     618  sa_size_t j,k,kr;
     619  if (smo && (IsPacked() > 0) && (res.IsPacked() > 0))   {  // regularly spaced elements
     620    sa_size_t maxx = totsize_;
     621    pe = Data();
     622    per = res.Data();
     623    for(k=0; k<maxx; k++) { *per = (*pe)*x;  per++;  pe++; }
     624  }
     625  else {    // Non regular data spacing ...
     626    int_4 ax,axr;
     627    sa_size_t step, stepr;
     628    sa_size_t gpas, naxr;
     629    GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr);
     630    for(j=0; j<naxr; j++)  {
     631      pe = mNDBlock.Begin()+Offset(ax,j);
     632      per = res.DataBlock().Begin()+res.Offset(axr,j);
     633      for(k=0, kr=0;  k<gpas;  k+=step, kr+=stepr)  per[kr] = pe[k]*x;
     634    }
     635  }
     636  return(res);
     637}
     638
     639//! Divide the source array by a constant value \b x and store the result in \b res.
     640/*!
     641Divide the source array \b this by a constant \b x and store the result in \b res (res = *this/x). 
     642If not initially allocated, the output array \b res is automatically
     643resized as a packed array with the same sizes as the source (this) array.
     644Returns a reference to the output array \b res.
     645\param x : Array elements are divied by x
     646\param res : Output array containing the result (res=(*this)/x or res=x/(*this)).
     647\param fginv == true : Invert the operation order (res = x/(*this))
     648*/
     649template <class T>
     650TArray<T>& TArray<T>::DivCst(T x, TArray<T>& res, bool fginv) const
     651{
     652  if (NbDimensions() < 1)
     653    throw RangeCheckError("TArray<T>::DivCst(T,res)  - Not allocated source array ! ");
    594654  if (!fginv && (x == (T) 0) )
    595     throw MathExc("TArray<T>::Div(T )  - Divide by zero ! ");
    596   T * pe;
    597   sa_size_t j,k;
    598   if (AvgStep() > 0)   {  // regularly spaced elements
    599     sa_size_t step = AvgStep();
    600     sa_size_t maxx = totsize_*step;
    601     pe = Data();
    602     if (fginv)
    603       for(k=0; k<maxx; k+=step )  pe[k] = x/pe[k];
     655    throw MathExc("TArray<T>::DivCst(T,res)  - Divide by zero ! ");
     656  if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     657  bool smo;
     658  if (!CompareSizes(res, smo))
     659    throw(SzMismatchError("TArray<T>::DivCst(T, res) SizeMismatch(this,res) ")) ;
     660
     661  const T * pe;
     662  T * per;
     663  sa_size_t j,k,kr;
     664  if (smo && (IsPacked() > 0) && (res.IsPacked() > 0))   {  // regularly spaced elements
     665    sa_size_t maxx = totsize_;
     666    pe = Data();
     667    per = res.Data();
     668    if (!fginv)
     669      for(k=0; k<maxx; k++) { *per = (*pe)/x;  per++;  pe++; }
    604670    else
    605       for(k=0; k<maxx; k+=step )  pe[k] /= x;
    606   }
    607   else {    // Non regular data spacing ...
    608     int_4 ka = MaxSizeKA();
    609     sa_size_t step = Step(ka);
    610     sa_size_t gpas = Size(ka)*step;
    611     sa_size_t naxa = Size()/Size(ka);
    612     for(j=0; j<naxa; j++)  {
    613       pe = mNDBlock.Begin()+Offset(ka,j);
    614       if (fginv)
    615         for(k=0; k<gpas; k+=step)  pe[k] = x/pe[k];
    616       else
    617         for(k=0; k<gpas; k+=step)  pe[k] /= x;
    618     }
    619   }
    620   return(*this);
    621 }
    622 
    623 
    624 //! Replace array elements values by their opposite ( a(i) -> -a(i) )
    625 template <class T>
    626 TArray<T>& TArray<T>::NegateElt()
    627 {
    628   if (NbDimensions() < 1)
    629     throw RangeCheckError("TArray<T>::NegateElt()  - Not Allocated Array ! ");
    630   T * pe;
    631   sa_size_t j,k;
    632   if (AvgStep() > 0)   {  // regularly spaced elements
    633     sa_size_t step = AvgStep();
    634     sa_size_t maxx = totsize_*step;
    635     pe = Data();
    636     for(k=0; k<maxx; k+=step )  pe[k] = -pe[k];
    637   }
    638   else {    // Non regular data spacing ...
    639     int_4 ka = MaxSizeKA();
    640     sa_size_t step = Step(ka);
    641     sa_size_t gpas = Size(ka)*step;
    642     sa_size_t naxa = Size()/Size(ka);
    643     for(j=0; j<naxa; j++)  {
    644       pe = mNDBlock.Begin()+Offset(ka,j);
    645       for(k=0; k<gpas; k+=step)  pe[k] = -pe[k];
    646     }
    647   }
    648   return(*this);
     671      for(k=0; k<maxx; k++) { *per = x/(*pe);  per++;  pe++; }
     672  }
     673  else {    // Non regular data spacing ...
     674    int_4 ax,axr;
     675    sa_size_t step, stepr;
     676    sa_size_t gpas, naxr;
     677    GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr);
     678    for(j=0; j<naxr; j++)  {
     679      pe = mNDBlock.Begin()+Offset(ax,j);
     680      per = res.DataBlock().Begin()+res.Offset(axr,j);
     681      if (!fginv)
     682        for(k=0, kr=0;  k<gpas;  k+=step, kr+=stepr)  per[kr] = pe[k]/x;
     683      else
     684        for(k=0, kr=0;  k<gpas;  k+=step, kr+=stepr)  per[kr] = x/pe[k];
     685    }
     686  }
     687  return(res);
     688}
     689
     690
     691//! Stores the opposite of the source array in \b res (res=-(*this)).
     692/*!
     693If not initially allocated, the output array \b res is automatically
     694resized as a packed array with the same sizes as the source (this) array.
     695Returns a reference to the output array \b res.
     696*/
     697template <class T>
     698TArray<T>& TArray<T>::NegateElt(TArray<T>& res) const
     699{
     700  if (NbDimensions() < 1)
     701    throw RangeCheckError("TArray<T>::NegateElt(res)  - Not allocated source array ");
     702  if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     703  bool smo;
     704  if (!CompareSizes(res, smo))
     705    throw(SzMismatchError("TArray<T>::NegateElt(res) SizeMismatch(this,res) ")) ;
     706
     707  const T * pe;
     708  T * per;
     709  sa_size_t j,k,kr;
     710  if (smo && (IsPacked() > 0) && (res.IsPacked() > 0))   {  // regularly spaced elements
     711    sa_size_t maxx = totsize_;
     712    pe = Data();
     713    per = res.Data();
     714    for(k=0; k<maxx; k++) { *per = -(*pe);  per++;  pe++; }
     715  }
     716  else {    // Non regular data spacing ...
     717    int_4 ax,axr;
     718    sa_size_t step, stepr;
     719    sa_size_t gpas, naxr;
     720    GetOpeParams(res, smo, ax, axr, step, stepr, gpas, naxr);
     721    for(j=0; j<naxr; j++)  {
     722      pe = mNDBlock.Begin()+Offset(ax,j);
     723      per = res.DataBlock().Begin()+res.Offset(axr,j);
     724      for(k=0, kr=0;  k<gpas;  k+=step, kr+=stepr)  per[kr] = -pe[k];
     725    }
     726  }
     727  return(res);
    649728}
    650729
  • trunk/SophyaLib/TArray/tarray.h

    r2322 r2564  
    2929  // Creation / destruction
    3030  TArray();
    31   TArray(int_4 ndim, const sa_size_t * siz, sa_size_t step =1);
    32   TArray(sa_size_t nx, sa_size_t ny=0, sa_size_t nz=0, sa_size_t nt=0, sa_size_t nu=0);
     31  TArray(int_4 ndim, const sa_size_t * siz, sa_size_t step =1, bool fzero=true);
     32  TArray(sa_size_t nx, sa_size_t ny=0, sa_size_t nz=0, sa_size_t nt=0, sa_size_t nu=0, bool fzero=true);
    3333  TArray(int_4 ndim, const sa_size_t * siz, NDataBlock<T> & db, bool share=false, sa_size_t step=1, sa_size_t offset=0);
    3434  TArray(int_4 ndim, const sa_size_t * siz, T* values, sa_size_t step=1, sa_size_t offset=0, Bridge* br=NULL);
     
    5757  void Share(const TArray<T>& a);
    5858
    59   void ReSize(int_4 ndim, sa_size_t * siz, sa_size_t step=1);
    60   void ReSize(const BaseArray& a);
     59  void ReSize(int_4 ndim, sa_size_t * siz, sa_size_t step=1, bool fzero=true);
     60  void ReSize(const BaseArray& a, bool pack=true, bool fzero=true);
    6161  //! a synonym (alias) for method ReSize(int_4, ...)
    62   inline void SetSize(int_4 ndim, sa_size_t * siz, sa_size_t step=1)
    63                 { ReSize(ndim, siz, step); }
     62  inline void SetSize(int_4 ndim, sa_size_t * siz, sa_size_t step=1, bool fzero=true)
     63                { ReSize(ndim, siz, step, fzero); }
    6464  //! a synonym (alias) for method ReSize(const BaseArray&)
    65   inline void SetSize(const BaseArray& a)
    66                 { ReSize(a); }
     65  inline void SetSize(const BaseArray& a, bool pack=true, bool fzero=true)
     66                { ReSize(a, pack, fzero); }
    6767  void Realloc(int_4 ndim, sa_size_t * siz, sa_size_t step=1, bool force=false);
    6868
     
    129129  //! Fill TArray with all elements equal to \b x
    130130  inline  TArray<T>&  operator = (T x)             { return SetT(x); }
     131
     132// addition et soustraction de constante
     133  virtual TArray<T>&  AddCst(T x, TArray<T>& res) const ;
     134  virtual TArray<T>&  SubCst(T x, TArray<T>& res, bool fginv=false) const ;
     135// Multiplication et division par une  constante
     136  virtual TArray<T>&  MulCst(T x, TArray<T>& res) const ;
     137  virtual TArray<T>&  DivCst(T x, TArray<T>& res, bool fginv=false) const ;
     138
    131139// A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
    132   virtual TArray<T>&  Add(T x);
     140  inline  TArray<T>&  Add(T x)                     { return AddCst(x, *this); }
     141  inline  TArray<T>&  Sub(T x, bool fginv=false)   { return SubCst(x, *this, fginv); }
     142  inline  TArray<T>&  Mul(T x)                     { return MulCst(x, *this); }
     143  inline  TArray<T>&  Div(T x, bool fginv=false)   { return DivCst(x, *this, fginv); }
     144
    133145  //! Add \b x to all elements
    134   inline  TArray<T>&  operator += (T x)            { return Add(x); }
    135   virtual TArray<T>&  Sub(T x, bool fginv=false);
     146  inline  TArray<T>&  operator += (T x)            { return AddCst(x, *this); }
    136147  //! Substract \b x to all elements
    137   inline  TArray<T>&  operator -= (T x)            { return Sub(x); }
    138   virtual TArray<T>&  Mul(T x);
     148  inline  TArray<T>&  operator -= (T x)            { return SubCst(x, *this); }
    139149  //! Multiply all elements by \b x
    140   inline  TArray<T>&  operator *= (T x)            { return Mul(x); }
    141   virtual TArray<T>&  Div(T x, bool fginv=false);
     150  inline  TArray<T>&  operator *= (T x)            { return MulCst(x, *this); }
    142151  //! Divide all elements by \b x
    143   inline  TArray<T>&  operator /= (T x)            { return Div(x); }
     152  inline  TArray<T>&  operator /= (T x)            { return DivCst(x, *this); }
    144153
    145154// applique le signe moins a tous les elements
    146   virtual TArray<T>&  NegateElt();
    147  
     155  virtual TArray<T>&  NegateElt(TArray<T>& res) const ;
     156//! Replace array elements values by their opposite ( (*this)(i) -> -(*this)(i) )
     157  inline  TArray<T>&  NegateElt()                  { return NegateElt(*this); }
     158
    148159// A += -=  (ajoute, soustrait element par element les deux tableaux )
    149160  virtual TArray<T>&  AddElt(const TArray<T>& a);
     
    209220  \brief Operator TArray = TArray + constant */
    210221template <class T> inline TArray<T> operator + (const TArray<T>& a, T b)
    211     {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
    212     result.Add(b); return result;}
     222    {TArray<T> result; result.SetTemp(true);
     223    a.Add(b, result); return result;}
    213224
    214225/*! \ingroup TArray \fn operator+(T,const TArray<T>&)
    215226  \brief Operator TArray = constant + TArray */
    216227template <class T> inline TArray<T> operator + (T b,const TArray<T>& a)
    217     {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
    218     result.Add(b); return result;}
     228    {TArray<T> result; result.SetTemp(true);
     229    a.Add(b, result); return result;}
    219230
    220231/*! \ingroup TArray \fn operator-(const TArray<T>&,T)
    221232  \brief Operator TArray = TArray - constant */
    222233template <class T> inline TArray<T> operator - (const TArray<T>& a, T b)
    223     {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
    224     result.Sub(b); return result;}
     234    {TArray<T> result; result.SetTemp(true);
     235    a.Sub(b,result); return result;}
    225236
    226237/*! \ingroup TArray \fn operator-(T,const TArray<T>&)
    227238  \brief Operator TArray = constant - TArray */
    228239template <class T> inline TArray<T> operator - (T b,const TArray<T>& a)
    229     {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
    230     result.Sub(b,true); return result;}
     240    {TArray<T> result; result.SetTemp(true);
     241    a.Sub(b,result,true); return result;}
    231242
    232243/*! \ingroup TArray \fn operator*(const TArray<T>&,T)
    233244  \brief Operator TArray = TArray * constant */
    234245template <class T> inline TArray<T> operator * (const TArray<T>& a, T b)
    235     {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
    236     result.Mul(b); return result;}
     246    {TArray<T> result; result.SetTemp(true);
     247    a.MulCst(b, result); return result;}
    237248
    238249/*! \ingroup TArray \fn operator*(T,const TArray<T>&)
    239250  \brief Operator TArray = constant * TArray */
    240251template <class T> inline TArray<T> operator * (T b,const TArray<T>& a)
    241     {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
    242     result.Mul(b); return result;}
     252    {TArray<T> result; result.SetTemp(true);
     253    a.MulCst(b,result); return result;}
    243254
    244255/*! \ingroup TArray \fn operator/(const TArray<T>&,T)
    245256  \brief Operator TArray = TArray / constant */
    246257template <class T> inline TArray<T> operator / (const TArray<T>& a, T b)
    247     {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
    248     result.Div(b); return result;}
     258    {TArray<T> result; result.SetTemp(true);
     259    a.Div(b,result); return result;}
    249260
    250261/*! \ingroup TArray \fn operator/(T,const TArray<T>&)
    251262  \brief Operator TArray = constant / TArray  */
    252263template <class T> inline TArray<T> operator / (T b, const TArray<T>& a)
    253     {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true);
    254     result.Div(b, true); return result;}
     264    {TArray<T> result; result.SetTemp(true);
     265    a.Div(b, result, true); return result;}
    255266
    256267////////////////////////////////////////////////////////////////
  • trunk/SophyaLib/TArray/tmatrix.h

    r2421 r2564  
    9393  inline  TMatrix<T>&  operator = (T x)             { SetT(x); return(*this); }
    9494  //! += : add constant value \b x to matrix
    95   inline  TMatrix<T>&  operator += (T x)            { Add(x); return(*this); }
     95  inline  TMatrix<T>&  operator += (T x)            { AddCst(x,*this); return(*this); }
    9696  //! -= : substract constant value \b x to matrix
    97   inline  TMatrix<T>&  operator -= (T x)            { Sub(x); return(*this); }
     97  inline  TMatrix<T>&  operator -= (T x)            { SubCst(x,*this); return(*this); }
    9898  //! *= : multiply matrix by constant value \b x
    99   inline  TMatrix<T>&  operator *= (T x)            { Mul(x); return(*this); }
     99  inline  TMatrix<T>&  operator *= (T x)            { MulCst(x,*this); return(*this); }
    100100  //! /= : divide matrix by constant value \b x
    101   inline  TMatrix<T>&  operator /= (T x)            { Div(x); return(*this); }
     101  inline  TMatrix<T>&  operator /= (T x)            { DivCst(x,*this); return(*this); }
    102102
    103103  //  operations avec matrices
     
    149149  \brief Operator TMatrix = TMatrix + constant */
    150150template <class T> inline TMatrix<T> operator + (const TMatrix<T>& a, T b)
    151     {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
    152     result.Add(b); return result;}
     151    {TMatrix<T> result; result.SetTemp(true);
     152    a.AddCst(b,result); return result;}
    153153
    154154/*! \ingroup TMatrix \fn operator+(T,const TMatrix<T>&)
    155155  \brief Operator TMatrix = constant + TMatrix */
    156156template <class T> inline TMatrix<T> operator + (T b,const TMatrix<T>& a)
    157     {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
    158     result.Add(b); return result;}
     157    {TMatrix<T> result; result.SetTemp(true);
     158    a.AddCst(b,result); return result;}
    159159
    160160/*! \ingroup TMatrix \fn operator-(const TMatrix<T>&,T)
    161161  \brief Operator TMatrix = TMatrix - constant */
    162162template <class T> inline TMatrix<T> operator - (const TMatrix<T>& a, T b)
    163     {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
    164     result.Sub(b); return result;}
     163    {TMatrix<T> result; result.SetTemp(true);
     164    a.SubCst(b,result); return result;}
    165165
    166166/*! \ingroup TMatrix \fn operator-(T,const TMatrix<T>&)
    167167  \brief Operator TMatrix = constant - TMatrix */
    168168template <class T> inline TMatrix<T> operator - (T b,const TMatrix<T>& a)
    169     {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
    170     result.Sub(b,true); return result;}
     169    {TMatrix<T> result; result.SetTemp(true);
     170    a.SubCst(b,result,true); return result;}
    171171
    172172/*! \ingroup TMatrix \fn operator*(const TMatrix<T>&,T)
    173173  \brief Operator TMatrix = TMatrix * constant */
    174174template <class T> inline TMatrix<T> operator * (const TMatrix<T>& a, T b)
    175     {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
    176     result.Mul(b); return result;}
     175    {TMatrix<T> result; result.SetTemp(true);
     176    a.MulCst(b,result); return result;}
    177177
    178178/*! \ingroup TMatrix \fn operator*(T,const TMatrix<T>&)
    179179  \brief Operator TMatrix = constant * TMatrix */
    180180template <class T> inline TMatrix<T> operator * (T b,const TMatrix<T>& a)
    181     {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
    182     result.Mul(b); return result;}
     181    {TMatrix<T> result; result.SetTemp(true);
     182    a.MulCst(b,result); return result;}
    183183
    184184/*! \ingroup TMatrix \fn operator/(const TMatrix<T>&,T)
    185185  \brief Operator TMatrix = TMatrix / constant */
    186186template <class T> inline TMatrix<T> operator / (const TMatrix<T>& a, T b)
    187     {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
    188     result.Div(b); return result;}
     187    {TMatrix<T> result; result.SetTemp(true);
     188    a.DivCst(b,result); return result;}
    189189
    190190/*! \ingroup TMatrix \fn operator/(T,const TMatrix<T>&)
    191191  \brief Operator TMatrix = constant / TMatrix  */
    192192template <class T> inline TMatrix<T> operator / (T b, const TMatrix<T>& a)
    193     {TMatrix<T> result; result.CloneOrShare(a); result.SetTemp(true);
    194     result.Div(b, true); return result;}
     193    {TMatrix<T> result; result.SetTemp(true);
     194    a.Div(b,result,true); return result;}
    195195
    196196////////////////////////////////////////////////////////////////
  • trunk/SophyaLib/TArray/tvector.h

    r2299 r2564  
    6767  inline  TVector<T>&  operator = (T x)             { SetT(x); return(*this); }
    6868  //! Add constant value \b x to vector elements
    69   inline  TVector<T>&  operator += (T x)            { Add(x); return(*this); }
     69  inline  TVector<T>&  operator += (T x)            { AddCst(x,*this); return(*this); }
    7070  //! Substract constant value \b x to vector elements
    71   inline  TVector<T>&  operator -= (T x)            { Sub(x); return(*this); }
     71  inline  TVector<T>&  operator -= (T x)            { SubCst(x,*this); return(*this); }
    7272  //! Multiply vector elements by constant value \b x
    73   inline  TVector<T>&  operator *= (T x)            { Mul(x); return(*this); }
     73  inline  TVector<T>&  operator *= (T x)            { MulCst(x,*this); return(*this); }
    7474  //! Divide vector elements by constant value \b x
    75   inline  TVector<T>&  operator /= (T x)            { Div(x); return(*this); }
     75  inline  TVector<T>&  operator /= (T x)            { DivCst(x,*this); return(*this); }
    7676
    7777  //  operations avec matrices
Note: See TracChangeset for help on using the changeset viewer.