Changeset 1113 in Sophya for trunk/SophyaLib


Ignore:
Timestamp:
Jul 28, 2000, 6:46:25 PM (25 years ago)
Author:
ansari
Message:

Ajout Methodes TArray::MinMax() et TArray::SumX2() - Reza 28/7/2000

Location:
trunk/SophyaLib/TArray
Files:
2 edited

Legend:

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

    r1103 r1113  
    838838  if (NbDimensions() < 1)
    839839    throw RangeCheckError("TArray<T>::Product()  - Not Allocated Array ! ");
     840  T ret=(T)1;
     841  const T * pe;
     842  uint_8 j,k;
     843  if (AvgStep() > 0)   {  // regularly spaced elements
     844    uint_8 step = AvgStep();
     845    uint_8 maxx = totsize_*step;
     846    pe = Data();
     847    for(k=0; k<maxx; k+=step )  ret *= pe[k];
     848  }
     849  else {    // Non regular data spacing ...
     850    uint_4 ka = MaxSizeKA();
     851    uint_8 step = Step(ka);
     852    uint_8 gpas = Size(ka)*step;
     853    uint_8 naxa = Size()/Size(ka);
     854    for(j=0; j<naxa; j++)  {
     855      pe = mNDBlock.Begin()+Offset(ka,j);
     856      for(k=0; k<gpas; k+=step)  ret *= pe[k] ;
     857    }
     858  }
     859  return ret;
     860}
     861
     862//! Returns the sum of all elements squared (Sum
     863template <class T>
     864T TArray<T>::SumX2() const
     865{
     866  if (NbDimensions() < 1)
     867    throw RangeCheckError("TArray<T>::SumX2()  - Not Allocated Array ! ");
    840868  T ret=0;
    841869  const T * pe;
     
    845873    uint_8 maxx = totsize_*step;
    846874    pe = Data();
    847     for(k=0; k<maxx; k+=step )  ret *= pe[k];
     875    for(k=0; k<maxx; k+=step )  ret += pe[k]*pe[k];
    848876  }
    849877  else {    // Non regular data spacing ...
     
    854882    for(j=0; j<naxa; j++)  {
    855883      pe = mNDBlock.Begin()+Offset(ka,j);
    856       for(k=0; k<gpas; k+=step)  ret *= pe[k] ;
     884      for(k=0; k<gpas; k+=step)  ret += pe[k]*pe[k] ;
    857885    }
    858886  }
     
    860888}
    861889
    862 
     890//! Return the minimum and the maximum values of the array elements
     891/*!
     892  This method generates an exception (\c MathExc) if called for complex arrays
     893*/
     894template <class T>
     895void TArray<T>::MinMax(T& min, T& max) const
     896{
     897  const T * pe;
     898  uint_8 j,k;
     899  uint_4 ka = MaxSizeKA();
     900  uint_8 step = Step(ka);
     901  uint_8 gpas = Size(ka)*step;
     902  uint_8 naxa = Size()/Size(ka);
     903  min = (*this)[0];
     904  max = (*this)[0];
     905  for(j=0; j<naxa; j++)  {
     906    pe = mNDBlock.Begin()+Offset(ka,j);
     907    for(k=0; k<gpas; k+=step) {
     908      if (pe[k]<min)  min = pe[k];
     909      else if (pe[k]>max)  max = pe[k];     
     910    }
     911  }
     912  return;
     913}
     914
     915void TArray< complex<r_4> >::MinMax(complex<r_4>& min, complex<r_4>& max) const
     916{
     917  throw MathExc("TArray< complex<r_4> >::MinMax(...) - No order in complex");
     918}
     919
     920void TArray< complex<r_8> >::MinMax(complex<r_8>& min, complex<r_8>& max) const
     921{
     922  throw MathExc("TArray< complex<r_4> >::MinMax(...) - No order in complex");
     923}
    863924
    864925// ----------------------------------------------------
  • trunk/SophyaLib/TArray/tarray.h

    r1103 r1113  
    161161  virtual T Sum() const ;
    162162  virtual T Product() const ;
     163// Somme du carre des elements
     164  virtual T SumX2() const;
     165// Valeur min et max des elements
     166  virtual void MinMax(T& min, T& max) const ;
    163167
    164168// Impression, I/O, ...
Note: See TracChangeset for help on using the changeset viewer.