Changeset 2938 in Sophya for trunk/SophyaLib/TArray/tarray.cc


Ignore:
Timestamp:
Apr 24, 2006, 4:25:14 PM (19 years ago)
Author:
ansari
Message:

Ajout operateur && et / (MulElt DivElt) pour TArray (.h) et partage (Share) lors des operations Add/Mul/Sub/DivCst et Add/Mul/Sub/DivElt (.cc) - Reza 24/4/2006

File:
1 edited

Legend:

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

    r2927 r2938  
    598598/*!
    599599Add a constant to the source array \b this and store the result in \b res (res = *this+x). 
    600 If not initially allocated, the output array \b res is automatically
     600
     601If not initially allocated, and if the source array (this) is not flagged as
     602temporary, the output array \b res is automatically
    601603resized as a packed array with the same sizes as the source (this) array.
     604If \b res is not allocated and (this) is temporary, data is shared between \b res and this.
     605
    602606Returns a reference to the output array \b res.
     607
    603608\param x : constant to add to the array elements
    604609\param res : Output array containing the result (res=this+x).
     
    609614  if (NbDimensions() < 1)
    610615    throw RangeCheckError("TArray<T>::AddCst(T,res)  - Not allocated source array ");
    611   if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     616  if (res.NbDimensions() < 1)  {
     617    if ( IsTemp() )  res.Share(*this);
     618    else res.SetSize(*this, true, false);
     619  }
    612620  bool smo;
    613621  if (!CompareSizes(res, smo))
     
    640648/*!
    641649Subtract a constant from the source array \b this and store the result in \b res (res = *this-x). 
    642 If not initially allocated, the output array \b res is automatically
     650
     651If not initially allocated, and if the source array (this) is not flagged as
     652temporary, the output array \b res is automatically
    643653resized as a packed array with the same sizes as the source (this) array.
     654If \b res is not allocated and (this) is temporary, data is shared between \b res and this.
     655
    644656Returns a reference to the output array \b res.
     657
    645658\param x : constant to subtract from the array elements
    646659\param res : Output array containing the result (res=this+x or res=x-this).
     
    652665  if (NbDimensions() < 1)
    653666    throw RangeCheckError("TArray<T>::SubCst(T,res)  - Not allocated source array ");
    654   if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     667  if (res.NbDimensions() < 1)  {
     668    if ( IsTemp() )  res.Share(*this);
     669    else res.SetSize(*this, true, false);
     670  }
    655671  bool smo;
    656672  if (!CompareSizes(res, smo))
     
    689705/*!
    690706Multiply the source array \b this by a constant \b x and store the result in \b res (res = *this*x). 
    691 If not initially allocated, the output array \b res is automatically
     707
     708If not initially allocated, and if the source array (this) is not flagged as
     709temporary, the output array \b res is automatically
    692710resized as a packed array with the same sizes as the source (this) array.
     711If \b res is not allocated and (this) is temporary, data is shared between \b res and this.
     712
    693713Returns a reference to the output array \b res.
     714
    694715\param x : Array elements are multiplied by x
    695716\param res : Output array containing the result (res=this*x).
     
    700721  if (NbDimensions() < 1)
    701722    throw RangeCheckError("TArray<T>::MulCst(T,res)  - Not allocated source array ");
    702   if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     723  if (res.NbDimensions() < 1)  {
     724    if ( IsTemp() )  res.Share(*this);
     725    else res.SetSize(*this, true, false);
     726  }
    703727  bool smo;
    704728  if (!CompareSizes(res, smo))
     
    731755/*!
    732756Divide the source array \b this by a constant \b x and store the result in \b res (res = *this/x). 
    733 If not initially allocated, the output array \b res is automatically
     757
     758If not initially allocated, and if the source array (this) is not flagged as
     759temporary, the output array \b res is automatically
    734760resized as a packed array with the same sizes as the source (this) array.
     761If \b res is not allocated and (this) is temporary, data is shared between \b res and this.
     762
    735763Returns a reference to the output array \b res.
     764
    736765\param x : Array elements are divied by x
    737766\param res : Output array containing the result (res=(*this)/x or res=x/(*this)).
     
    745774  if (!fginv && (x == (T) 0) )
    746775    throw MathExc("TArray<T>::DivCst(T,res)  - Divide by zero ! ");
    747   if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     776  if (res.NbDimensions() < 1)  {
     777    if ( IsTemp() )  res.Share(*this);
     778    else res.SetSize(*this, true, false);
     779  }
    748780  bool smo;
    749781  if (!CompareSizes(res, smo))
     
    782814//! Stores the opposite of the source array in \b res (res=-(*this)).
    783815/*!
    784 If not initially allocated, the output array \b res is automatically
     816If not initially allocated, and if the source array (this) is not flagged as
     817temporary, the output array \b res is automatically
    785818resized as a packed array with the same sizes as the source (this) array.
     819If \b res is not allocated and (this) is temporary, data is shared between \b res and this.
     820
    786821Returns a reference to the output array \b res.
    787822*/
     
    791826  if (NbDimensions() < 1)
    792827    throw RangeCheckError("TArray<T>::NegateElt(res)  - Not allocated source array ");
    793   if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     828  if (res.NbDimensions() < 1)  {
     829    if ( IsTemp() )  res.Share(*this);
     830    else res.SetSize(*this, true, false);
     831  }
    794832  bool smo;
    795833  if (!CompareSizes(res, smo))
     
    826864and store the result in \b res (res = *this+a). The source and argument arrays (this, a)
    827865should have the same sizes.
    828 If not initially allocated, the output array \b res is automatically
     866
     867If not initially allocated, and if none of the source arrays is flagged as
     868temporary, the output array \b res is automatically
    829869resized as a packed array with the same sizes as the source (this) array.
     870If \b res is not allocated and one of the source array is temporary,
     871data is shared between \b res and the temporary source array.
     872
    830873Returns a reference to the output array \b res.
     874
    831875\param a : Array to be added to the source array.
    832876\param res : Output array containing the result (res=this+a).
     
    840884  if (!CompareSizes(a, smoa))
    841885    throw(SzMismatchError("TArray<T>::AddElt(...) SizeMismatch(this,a)")) ;
    842   if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     886  if (res.NbDimensions() < 1)  {
     887    if ( IsTemp() )  res.Share(*this);
     888    else if ( a.IsTemp() ) res.Share(a);
     889    else res.SetSize(*this, true, false);
     890  }
    843891  bool smor;
    844892  if (!CompareSizes(res, smor))
     
    892940and the store result in \b res (res = *this-a or res=a-(*this)).
    893941The source and argument arrays (this, a) should have the same sizes.
    894 If not initially allocated, the output array \b res is automatically
     942
     943If not initially allocated, and if none of the source arrays is flagged as
     944temporary, the output array \b res is automatically
    895945resized as a packed array with the same sizes as the source (this) array.
     946If \b res is not allocated and one of the source array is temporary,
     947data is shared between \b res and the temporary source array.
     948
    896949Returns a reference to the output array \b res.
     950
    897951\param a : Array to be added to the source array.
    898952\param res : Output array containing the result (res=*this+x).
     
    908962  if (!CompareSizes(a, smoa))
    909963    throw(SzMismatchError("TArray<T>::SubElt(...) SizeMismatch(this,a)")) ;
    910   if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     964  if (res.NbDimensions() < 1)  {
     965    if ( IsTemp() )  res.Share(*this);
     966    else if ( a.IsTemp() ) res.Share(a);
     967    else res.SetSize(*this, true, false);
     968  }
    911969  bool smor;
    912970  if (!CompareSizes(res, smor))
     
    9661024and store the result in \b res (res = *this*a). The source and argument arrays (this, a)
    9671025should have the same sizes.
    968 If not initially allocated, the output array \b res is automatically
     1026
     1027If not initially allocated, and if none of the source arrays is flagged as
     1028temporary, the output array \b res is automatically
    9691029resized as a packed array with the same sizes as the source (this) array.
     1030If \b res is not allocated and one of the source array is temporary,
     1031data is shared between \b res and the temporary source array.
     1032
    9701033Returns a reference to the output array \b res.
     1034
    9711035\param a : Array to be added to the source array.
    9721036\param res : Output array containing the result (res=(*this)*a).
     
    9801044  if (!CompareSizes(a, smoa))
    9811045    throw(SzMismatchError("TArray<T>::MulElt(...) SizeMismatch(this,a)")) ;
    982   if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     1046  if (res.NbDimensions() < 1)  {
     1047    if ( IsTemp() )  res.Share(*this);
     1048    else if ( a.IsTemp() ) res.Share(a);
     1049    else res.SetSize(*this, true, false);
     1050  }
    9831051  bool smor;
    9841052  if (!CompareSizes(res, smor))
     
    10321100and store the result in \b res (res = *this/a). The source and argument arrays (this, a)
    10331101should have the same sizes.
    1034 If not initially allocated, the output array \b res is automatically
     1102
     1103If not initially allocated, and if none of the source arrays is flagged as
     1104temporary, the output array \b res is automatically
    10351105resized as a packed array with the same sizes as the source (this) array.
     1106If \b res is not allocated and one of the source array is temporary,
     1107data is shared between \b res and the temporary source array.
     1108
    10361109Returns a reference to the output array \b res.
     1110
    10371111\param a : Array to be added to the source array.
    10381112\param res : Output array containing the result (res=*this/a).
     
    10491123  if (!CompareSizes(a, smoa))
    10501124    throw(SzMismatchError("TArray<T>::DivElt(...) SizeMismatch(this,a)")) ;
    1051   if (res.NbDimensions() < 1)  res.SetSize(*this, true, false);
     1125  if (res.NbDimensions() < 1)  {
     1126    if ( IsTemp() )  res.Share(*this);
     1127    else if ( a.IsTemp() ) res.Share(a);
     1128    else res.SetSize(*this, true, false);
     1129  }
    10521130  bool smor;
    10531131  if (!CompareSizes(res, smor))
Note: See TracChangeset for help on using the changeset viewer.