Changeset 3332 in Sophya for trunk/SophyaLib/TArray/tarray.cc
- Timestamp:
- Oct 3, 2007, 3:04:34 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/tarray.cc
r3234 r3332 160 160 string exmsg = "TArray<T>::TArray(int_4, sa_size_t *, NDataBlock<T> & ... )"; 161 161 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)) { 163 163 exmsg += " DataBlock.Size() < ComputeTotalSize(...) " ; 164 164 throw( ParmError(exmsg) ); … … 1395 1395 //! Returns the sum of all array elements squared (Sum_k((*this)(k)*(*this)(k)). 1396 1396 template <class T> 1397 T TArray<T>::Sum X2() const1398 { 1399 if (NbDimensions() < 1) 1400 throw RangeCheckError("TArray<T>::Sum X2() - Not Allocated Array ! ");1397 T TArray<T>::SumSq() const 1398 { 1399 if (NbDimensions() < 1) 1400 throw RangeCheckError("TArray<T>::SumSq() - Not Allocated Array ! "); 1401 1401 T ret=0; 1402 1402 const T * pe; … … 1420 1420 return ret; 1421 1421 } 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 */ 1429 template <class T> 1430 T TArray<T>::Norm2() const 1431 { 1432 return SumSq(); 1433 } 1434 1435 1436 // Fonction auxiliaire pour specialisation de la methode Norm2() pour tableaux complexes 1437 template <class T> 1438 complex<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 --- 1466 DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ 1467 complex<r_4> TArray< complex<r_4> >::Norm2() const 1468 { 1469 return _ComputeComplexNorm_Private_(*this); 1470 } 1471 DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ 1472 complex<r_8> TArray< complex<r_8> >::Norm2() const 1473 { 1474 return _ComputeComplexNorm_Private_(*this); 1475 } 1476 //------------------- 1422 1477 1423 1478 //! Return the minimum and the maximum values of the array elements
Note:
See TracChangeset
for help on using the changeset viewer.