Index: trunk/SophyaLib/TArray/tarray.h
===================================================================
--- trunk/SophyaLib/TArray/tarray.h	(revision 967)
+++ trunk/SophyaLib/TArray/tarray.h	(revision 970)
@@ -46,4 +46,9 @@
   // Gestion taille/Remplissage
   virtual void Clone(const TArray<T>& a); 
+  // partage les donnees si "a" temporaire, clone sinon.
+  void CloneOrShare(const TArray<T>& a);
+  // Share: partage les donnees de "a"
+
+  void Share(const TArray<T>& a);
   void ReSize(uint_4 ndim, uint_4 * siz, uint_4 step=1);
   void Realloc(uint_4 ndim, uint_4 * siz, uint_4 step=1, bool force=false);
@@ -122,5 +127,5 @@
   //! Add \b x to all elements
   inline  TArray<T>&  operator += (T x)            { return Add(x); }
-  virtual TArray<T>&  Sub(T x);
+  virtual TArray<T>&  Sub(T x, bool fginv=false);
   //! Substract \b x to all elements
   inline  TArray<T>&  operator -= (T x)            { return Sub(x); }
@@ -128,9 +133,7 @@
   //! Multiply all elements by \b x
   inline  TArray<T>&  operator *= (T x)            { return Mul(x); }
-  virtual TArray<T>&  Div(T x);
+  virtual TArray<T>&  Div(T x, bool fginv=false);
   //! Divide all elements by \b x
   inline  TArray<T>&  operator /= (T x)            { return Div(x); }
-  virtual TArray<T>&  SubInv(T x);  //   A ---> x-A
-  virtual TArray<T>&  DivInv(T x);  //   A ---> x/A
 
 // A += -=  (ajoute, soustrait element par element les deux tableaux )
@@ -138,10 +141,10 @@
   //! Operator TArray += TArray
   inline  TArray<T>&  operator += (const TArray<T>& a)  { return AddElt(a); }
-  virtual TArray<T>&  SubElt(const TArray<T>& a);
+  virtual TArray<T>&  SubElt(const TArray<T>& a, bool fginv=false);
   //! Operator TArray -= TArray
   inline  TArray<T>&  operator -= (const TArray<T>& a)  { return SubElt(a); }
 // Multiplication, division element par element les deux tableaux 
   virtual TArray<T>&  MulElt(const TArray<T>& a);
-  virtual TArray<T>&  DivElt(const TArray<T>& a);
+  virtual TArray<T>&  DivElt(const TArray<T>& a, bool fginv=false);
 // Recopie des valeurs, element par element
   virtual TArray<T>&  CopyElt(const TArray<T>& a);
@@ -159,8 +162,4 @@
 
 protected:
-  // partage les donnees si "a" temporaire, clone sinon.
-  void CloneOrShare(const TArray<T>& a);
-  // Share: partage les donnees de "a"
-  void Share(const TArray<T>& a);
 
   NDataBlock<T> mNDBlock; //!< Block for datas
@@ -180,35 +179,48 @@
   \brief Operator TArray = TArray + constant */
 template <class T> inline TArray<T> operator + (const TArray<T>& a, T b)
-    {TArray<T> result(a); result.SetTemp(true); result.Add(b); return result;}
+    {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); 
+    result.Add(b); return result;}
 
 /*! \ingroup TArray \fn operator+(T,const TArray<T>&)
   \brief Operator TArray = constant + TArray */
 template <class T> inline TArray<T> operator + (T b,const TArray<T>& a)
-    {TArray<T> result(a); result.SetTemp(true); result.Add(b); return result;}
+    {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); 
+    result.Add(b); return result;}
 
 /*! \ingroup TArray \fn operator-(const TArray<T>&,T)
   \brief Operator TArray = TArray - constant */
 template <class T> inline TArray<T> operator - (const TArray<T>& a, T b)
-    {TArray<T> result(a); result.SetTemp(true); result.Sub(b); return result;}
+    {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); 
+    result.Sub(b); return result;}
 
 /*! \ingroup TArray \fn operator-(T,const TArray<T>&)
   \brief Operator TArray = constant - TArray */
 template <class T> inline TArray<T> operator - (T b,const TArray<T>& a)
-    {TArray<T> result(a); result.SetTemp(true); result.SubInv(b); return result;}
+    {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); 
+    result.Sub(b,true); return result;}
 
 /*! \ingroup TArray \fn operator*(const TArray<T>&,T)
   \brief Operator TArray = TArray * constant */
 template <class T> inline TArray<T> operator * (const TArray<T>& a, T b)
-    {TArray<T> result(a); result.SetTemp(true); result.Mul(b); return result;}
+    {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); 
+    result.Mul(b); return result;}
 
 /*! \ingroup TArray \fn operator*(T,const TArray<T>&)
   \brief Operator TArray = constant * TArray */
 template <class T> inline TArray<T> operator * (T b,const TArray<T>& a)
-    {TArray<T> result(a); result.SetTemp(true); result.Mul(b); return result;}
+    {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); 
+    result.Mul(b); return result;}
 
 /*! \ingroup TArray \fn operator/(const TArray<T>&,T)
   \brief Operator TArray = TArray / constant */
 template <class T> inline TArray<T> operator / (const TArray<T>& a, T b)
-    {TArray<T> result(a); result.SetTemp(true); result.DivInv(b); return result;}
+    {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); 
+    result.Div(b); return result;}
+
+/*! \ingroup TArray \fn operator/(T,const TArray<T>&)
+  \brief Operator TArray = constant / TArray  */
+template <class T> inline TArray<T> operator / (T b, const TArray<T>& a)
+    {TArray<T> result; result.CloneOrShare(a); result.SetTemp(true); 
+    result.Div(b, true); return result;}
 
 ////////////////////////////////////////////////////////////////
@@ -219,5 +231,8 @@
 template <class T>
 inline TArray<T> operator + (const TArray<T>& a,const TArray<T>& b)
-    {TArray<T> result(a); result.SetTemp(true); result.AddElt(b); return result;}
+    { TArray<T> result; result.SetTemp(true); 
+    if (b.IsTemp())  { result.Share(b); result.AddElt(a); }
+    else { result.CloneOrShare(a); result.AddElt(b); }
+    return result; }
 
 /*! \ingroup TArray \fn operator-(const TArray<T>&,const TArray<T>&)
@@ -225,5 +240,8 @@
 template <class T>
 inline TArray<T> operator - (const TArray<T>& a,const TArray<T>& b)
-    {TArray<T> result(a); result.SetTemp(true); result.SubElt(b); return result;}
+    { TArray<T> result; result.SetTemp(true); 
+    if (b.IsTemp())  { result.Share(b); result.SubElt(a, true); }
+    else { result.CloneOrShare(a); result.SubElt(b); }
+    return result; }
 
 
