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


Ignore:
Timestamp:
Oct 3, 2007, 3:04:34 PM (18 years ago)
Author:
ansari
Message:

1- Methode TArray::SumX2() renommee en ::SumSq()
2- Methode TArray::Norm2() appelle maintenant SumSq() - sauf pour les
tableaux complexes, ou on calcule Sum[el x conj(el)]=Sum[module2]
3- Nettoyage fichier sopemtx.cc (utilisation sa_size_t pour supprimer
les warnings g++

Reza , 02/10/2007

File:
1 edited

Legend:

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

    r3234 r3332  
    160160  string exmsg = "TArray<T>::TArray(int_4, sa_size_t *,  NDataBlock<T> & ... )";
    161161  if (!UpdateSizes(ndim, siz, step, offset, exmsg))  throw( ParmError(exmsg) );
    162   if (mNDBlock.Size() < ComputeTotalSize(ndim, siz, step, offset)) {
     162  if (mNDBlock.Size() < (size_t)ComputeTotalSize(ndim, siz, step, offset)) {
    163163    exmsg += " DataBlock.Size() < ComputeTotalSize(...) " ;
    164164    throw( ParmError(exmsg) );
     
    13951395//! Returns the sum of all array elements squared (Sum_k((*this)(k)*(*this)(k)).
    13961396template <class T>
    1397 T TArray<T>::SumX2() const
    1398 {
    1399   if (NbDimensions() < 1)
    1400     throw RangeCheckError("TArray<T>::SumX2()  - Not Allocated Array ! ");
     1397T TArray<T>::SumSq() const
     1398{
     1399  if (NbDimensions() < 1)
     1400    throw RangeCheckError("TArray<T>::SumSq()  - Not Allocated Array ! ");
    14011401  T ret=0;
    14021402  const T * pe;
     
    14201420  return ret;
    14211421}
     1422
     1423/*!
     1424\brief Returns the array norm squared, defined as  Sum_k [ el(k)* el(k) ]
     1425  For arrays with integer or real data, this method calls SumSq(), which computes
     1426  the sum of array elements squared. For complex arrays, it computes and returns
     1427  the sum of array elements module squared (= Sum_k [el(k)*conj(el(k))]
     1428*/
     1429template <class T>
     1430T TArray<T>::Norm2() const
     1431{
     1432  return SumSq();
     1433}
     1434
     1435
     1436// Fonction auxiliaire pour specialisation de la methode Norm2() pour tableaux complexes
     1437template <class T>
     1438complex<T>  _ComputeComplexNorm_Private_(TArray< complex<T> > const & ca)
     1439{
     1440  if (ca.NbDimensions() < 1)
     1441    throw RangeCheckError("TArray< complex<T> >::Norm2()  - Not Allocated Array ! ");
     1442  complex<T> ret= complex<T>(0., 0.);
     1443  const complex<T> * pe;
     1444  sa_size_t j,k;
     1445  if (ca.AvgStep() > 0)   {  // regularly spaced elements
     1446    sa_size_t step = ca.AvgStep();
     1447    sa_size_t maxx = ca.Size()*step;
     1448    pe = ca.Data();
     1449    for(k=0; k<maxx; k+=step )  ret += pe[k]*conj(pe[k]);
     1450  }
     1451  else {    // Non regular data spacing ...
     1452    int_4 ka = ca.MaxSizeKA();
     1453    sa_size_t step = ca.Step(ka);
     1454    sa_size_t gpas = ca.Size(ka)*step;
     1455    sa_size_t naxa = ca.Size()/ca.Size(ka);
     1456    for(j=0; j<naxa; j++)  {
     1457      pe = ca.DataBlock().Begin()+ca.Offset(ka,j);
     1458      for(k=0; k<gpas; k+=step)  ret += pe[k]*conj(pe[k]) ;
     1459    }
     1460  }
     1461  return ret;
     1462
     1463}
     1464
     1465// --- Specialisation de la methode Norm2() pour tableaux complexes ---
     1466DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
     1467complex<r_4> TArray< complex<r_4> >::Norm2() const
     1468{
     1469  return  _ComputeComplexNorm_Private_(*this);
     1470}
     1471DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
     1472complex<r_8> TArray< complex<r_8> >::Norm2() const
     1473{
     1474  return  _ComputeComplexNorm_Private_(*this);
     1475}
     1476//-------------------
    14221477
    14231478//! Return the minimum and the maximum values of the array elements
Note: See TracChangeset for help on using the changeset viewer.