Changeset 1113 in Sophya for trunk/SophyaLib/TArray
- Timestamp:
- Jul 28, 2000, 6:46:25 PM (25 years ago)
- Location:
- trunk/SophyaLib/TArray
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/tarray.cc
r1103 r1113 838 838 if (NbDimensions() < 1) 839 839 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 863 template <class T> 864 T TArray<T>::SumX2() const 865 { 866 if (NbDimensions() < 1) 867 throw RangeCheckError("TArray<T>::SumX2() - Not Allocated Array ! "); 840 868 T ret=0; 841 869 const T * pe; … … 845 873 uint_8 maxx = totsize_*step; 846 874 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]; 848 876 } 849 877 else { // Non regular data spacing ... … … 854 882 for(j=0; j<naxa; j++) { 855 883 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] ; 857 885 } 858 886 } … … 860 888 } 861 889 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 */ 894 template <class T> 895 void 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 915 void 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 920 void 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 } 863 924 864 925 // ---------------------------------------------------- -
trunk/SophyaLib/TArray/tarray.h
r1103 r1113 161 161 virtual T Sum() const ; 162 162 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 ; 163 167 164 168 // Impression, I/O, ...
Note:
See TracChangeset
for help on using the changeset viewer.