Changeset 2575 in Sophya for trunk/SophyaLib/TArray/tarray.h


Ignore:
Timestamp:
Jul 29, 2004, 2:31:16 PM (21 years ago)
Author:
ansari
Message:

1/ Remplacement des methodes Add/Sub/Mul/DivElt(a) par

Add/Sub/Mul/DivElt(TArray a, TArray res)

2/ Operateurs += -= A+B A-B TArray et TMatrix/TVecteur modifies en consequence
3/ Ajout methode TArray::ScalarProduct()
4/ Methode TArray::SetT renomme en SetCst() SetT garde en alias
5/ Ajout parametre bool fzero (mise a zero) ajoute ds constructeur et

ReSize() de TMatrix et TVecteur.

Reza 29/07/2004

File:
1 edited

Legend:

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

    r2569 r2575  
    125125  //! Fill TArray with Sequence \b seq
    126126  inline  TArray<T>&  operator = (Sequence const & seq)    { return SetSeq(seq); }
     127
    127128// A = x (tous les elements a x)
    128   virtual TArray<T>&  SetT(T x);
     129  virtual TArray<T>&  SetCst(T x);
     130  //! Fill an array with a constant value \b x ( alias for \b SetCst() method )
     131  inline  TArray<T>&  SetT(T x) { return SetCst(x); }
    129132  //! Fill TArray with all elements equal to \b x
    130133  inline  TArray<T>&  operator = (T x)             { return SetT(x); }
     
    138141
    139142// A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
     143  // Methodes Add/Sub/Mul/Div() sont la pour compatibilite avant V=2 (1.818)
     144  // Faut-il les garder ? Reza, Juillet 2004
    140145  inline  TArray<T>&  Add(T x)                     { return AddCst(x, *this); }
    141146  inline  TArray<T>&  Sub(T x, bool fginv=false)   { return SubCst(x, *this, fginv); }
     
    158163
    159164// A += -=  (ajoute, soustrait element par element les deux tableaux )
    160   virtual TArray<T>&  AddElt(const TArray<T>& a);
    161   //! Operator TArray += TArray
    162   inline  TArray<T>&  operator += (const TArray<T>& a)  { return AddElt(a); }
    163   virtual TArray<T>&  SubElt(const TArray<T>& a, bool fginv=false);
    164   //! Operator TArray -= TArray
    165   inline  TArray<T>&  operator -= (const TArray<T>& a)  { return SubElt(a); }
     165  virtual TArray<T>&  AddElt(const TArray<T>& a, TArray<T>& res) const ;
     166  virtual TArray<T>&  SubElt(const TArray<T>& a, TArray<T>& res, bool fginv=false) const ;
    166167// Multiplication, division element par element les deux tableaux
    167   virtual TArray<T>&  MulElt(const TArray<T>& a);
    168   virtual TArray<T>&  DivElt(const TArray<T>& a, bool fginv=false, bool divzero=false);
     168  virtual TArray<T>&  MulElt(const TArray<T>& a, TArray<T>& res) const ;
     169  virtual TArray<T>&  DivElt(const TArray<T>& a, TArray<T>& res, bool fginv=false, bool divzero=false) const ;
     170
     171  //! Operator TArray += TArray (element by element addition in place)
     172  inline  TArray<T>&  operator += (const TArray<T>& a)  { return AddElt(a, *this); }
     173  //! Operator TArray -= TArray (element by element subtraction in place)
     174  inline  TArray<T>&  operator -= (const TArray<T>& a)  { return SubElt(a, *this); }
     175
    169176// Recopie des valeurs, element par element
    170177  virtual TArray<T>&  CopyElt(const TArray<T>& a);
    171178// Recopie des valeurs avec conversion prealable, element par element
    172179  virtual TArray<T>&  ConvertAndCopyElt(const BaseArray& a);
     180
     181// Calcul du produit scalaire ( Somme_i (*this)(i)*a(i) )
     182  virtual T ScalarProduct(const TArray<T>& a) const ;
     183// Norme(^2)
     184  //! Returns the squarred of the array norm, defined as  Sum_k (*this)(k)*(*this)(k)
     185  inline T Norm2() const { return ScalarProduct(*this); }
    173186
    174187// Somme et produit des elements
     
    283296inline TArray<T> operator + (const TArray<T>& a,const TArray<T>& b)
    284297    { TArray<T> result; result.SetTemp(true);
    285     if (b.IsTemp())  { result.Share(b); result.AddElt(a); }
    286     else { result.CloneOrShare(a); result.AddElt(b); }
    287     return result; }
     298    a.AddElt(b, result);    return result; }
    288299
    289300/*! \ingroup TArray \fn operator-(const TArray<T>&,const TArray<T>&)
     
    292303inline TArray<T> operator - (const TArray<T>& a,const TArray<T>& b)
    293304    { TArray<T> result; result.SetTemp(true);
    294     if (b.IsTemp())  { result.Share(b); result.SubElt(a, true); }
    295     else { result.CloneOrShare(a); result.SubElt(b); }
    296     return result; }
     305    a.SubElt(b, result);    return result; }
    297306
    298307
Note: See TracChangeset for help on using the changeset viewer.