Data.hxx

00001 // Copyright (C) 2003-2007, Vivien Mallet
00002 //
00003 // This file is part of SeldonData library, used for data processing.
00004 //
00005 // SeldonData is free software; you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation; either version 2 of the License, or (at your option)
00008 // any later version.
00009 //
00010 // SeldonData is distributed in the hope that it will be useful, but WITHOUT
00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 // more details.
00014 //
00015 // For more information, visit the SeldonData home page:
00016 //      http://vivienmallet.net/lib/seldondata/
00017 
00018 #ifndef FILE_SELDONDATA_DATA_HXX
00019 
00020 #include <iostream>
00021 using std::cout;
00022 using std::endl;
00023 
00024 namespace SeldonData
00025 {
00026 
00028   template<class T, int N, class TG = T>
00029   class Data
00030   {
00031 
00032   protected:
00034     Array<T, N> data_;
00036     Array<Grid<TG>*, 1> grids_;
00037 
00038   public:
00039 
00040     // Constructors.
00041 
00042     Data()  throw();
00043     Data(Grid<TG>& G0)  throw();
00044     Data(Grid<TG>& G0, Grid<TG>& G1)  throw();
00045     Data(Grid<TG>& G0, Grid<TG>& G1,
00046          Grid<TG>& G2)  throw();
00047     Data(Grid<TG>& G0, Grid<TG>& G1,
00048          Grid<TG>& G2, Grid<TG>& G3)  throw();
00049     Data(Grid<TG>& G0, Grid<TG>& G1,
00050          Grid<TG>& G2, Grid<TG>& G3,
00051          Grid<TG>& G4)  throw();
00052     Data(Grid<TG>& G0, Grid<TG>& G1,
00053          Grid<TG>& G2, Grid<TG>& G3,
00054          Grid<TG>& G4, Grid<TG>& G5)  throw();
00055     Data(Grid<TG>& G0, Grid<TG>& G1,
00056          Grid<TG>& G2, Grid<TG>& G3,
00057          Grid<TG>& G4, Grid<TG>& G5,
00058          Grid<TG>& G6)  throw();
00059     Data(Grid<TG>& G0, Grid<TG>& G1,
00060          Grid<TG>& G2, Grid<TG>& G3,
00061          Grid<TG>& G4, Grid<TG>& G5,
00062          Grid<TG>& G6, Grid<TG>& G7)  throw();
00063     Data(Grid<TG>& G0, Grid<TG>& G1,
00064          Grid<TG>& G2, Grid<TG>& G3,
00065          Grid<TG>& G4, Grid<TG>& G5,
00066          Grid<TG>& G6, Grid<TG>& G7,
00067          Grid<TG>& G8)  throw();
00068     Data(Grid<TG>& G0, Grid<TG>& G1,
00069          Grid<TG>& G2, Grid<TG>& G3,
00070          Grid<TG>& G4, Grid<TG>& G5,
00071          Grid<TG>& G6, Grid<TG>& G7,
00072          Grid<TG>& G8, Grid<TG>& G9)  throw();
00073     Data(int N0)  throw();
00074     Data(int N0, int N1)  throw();
00075     Data(int N0, int N1,
00076          int N2)  throw();
00077     Data(int N0, int N1,
00078          int N2, int N3)  throw();
00079     Data(int N0, int N1,
00080          int N2, int N3,
00081          int N4)  throw();
00082     Data(int N0, int N1,
00083          int N2, int N3,
00084          int N4, int N5)  throw();
00085     Data(int N0, int N1,
00086          int N2, int N3,
00087          int N4, int N5,
00088          int N6)  throw();
00089     Data(int N0, int N1,
00090          int N2, int N3,
00091          int N4, int N5,
00092          int N6, int N7)  throw();
00093     Data(int N0, int N1,
00094          int N2, int N3,
00095          int N4, int N5,
00096          int N6, int N7,
00097          int N8)  throw();
00098     Data(int N0, int N1,
00099          int N2, int N3,
00100          int N4, int N5,
00101          int N6, int N7,
00102          int N8, int N9)  throw();
00103     Data(const TinyVector<int, N>& shape) throw();
00104     Data(T* data, const TinyVector<int, N>& shape,
00105          preexistingMemoryPolicy policy = neverDeleteData) throw();
00106     template <class T0>
00107     Data(Data<T0, N, TG>& data)  throw();
00108 
00109     // Destructor.
00110 
00111     ~Data()  throw();
00112 
00113     // Methods.
00114 
00115     T& operator() (int i0);
00116     T& operator() (int i0, int i1);
00117     T& operator() (int i0, int i1, int i2);
00118     T& operator() (int i0, int i1, int i2,
00119                    int i3);
00120     T& operator() (int i0, int i1, int i2,
00121                    int i3, int i4);
00122     T& operator() (int i0, int i1, int i2,
00123                    int i3, int i4, int i5);
00124     T& operator() (int i0, int i1, int i2,
00125                    int i3, int i4, int i5,
00126                    int i6);
00127     T& operator() (int i0, int i1, int i2,
00128                    int i3, int i4, int i5,
00129                    int i6, int i7);
00130     T& operator() (int i0, int i1, int i2,
00131                    int i3, int i4, int i5,
00132                    int i6, int i7, int i8);
00133     T& operator() (int i0, int i1, int i2,
00134                    int i3, int i4, int i5,
00135                    int i6, int i7, int i8,
00136                    int i9);
00137 
00138     T operator() (int i0) const;
00139     T operator() (int i0, int i1) const;
00140     T operator() (int i0, int i1, int i2) const;
00141     T operator() (int i0, int i1, int i2,
00142                   int i3) const;
00143     T operator() (int i0, int i1, int i2,
00144                   int i3, int i4) const;
00145     T operator() (int i0, int i1, int i2,
00146                   int i3, int i4, int i5) const;
00147     T operator() (int i0, int i1, int i2,
00148                   int i3, int i4, int i5,
00149                   int i6) const;
00150     T operator() (int i0, int i1, int i2,
00151                   int i3, int i4, int i5,
00152                   int i6, int i7) const;
00153     T operator() (int i0, int i1, int i2,
00154                   int i3, int i4, int i5,
00155                   int i6, int i7, int i8) const;
00156     T operator() (int i0, int i1, int i2,
00157                   int i3, int i4, int i5,
00158                   int i6, int i7, int i8,
00159                   int i9) const;
00160 
00161     T& operator() (const Array<int, 1>& indices);
00162 
00163     T& Value(int i0, int i1 = -1,
00164              int i2 = -1, int i3 = -1,
00165              int i4 = -1, int i5 = -1,
00166              int i6 = -1, int i7 = -1,
00167              int i8 = -1, int i9 = -1);
00168 
00169     T Value(int i0, int i1 = -1,
00170             int i2 = -1, int i3 = -1,
00171             int i4 = -1, int i5 = -1,
00172             int i6 = -1, int i7 = -1,
00173             int i8 = -1, int i9 = -1) const;
00174 
00175     template <class T0>
00176     void Copy(Data<T0, N, TG>& data);
00177     template <class T0>
00178     void ReferenceCopy(Data<T0, N, TG>& data);
00179 
00180     int GetNbElements();
00181     int GetNbDim();
00182     int GetLength(int dim) const;
00183 
00184     Grid<TG>* GetGrid(int i);
00185     Grid<TG>& operator [] (int i);
00186     const Grid<TG>& operator [] (int i) const;
00187     Array<Grid<TG>*, 1>& GetGrids();
00188 
00189     Array<T, N>& GetArray();
00190     Array<T, N>& operator() ();
00191     T* GetData();
00192     const T* GetData() const;
00193 
00194     template<class DTG, class R0>
00195     void SubData(Data<T, 1, DTG>&, R0 r0);
00196     template<class DTG, class R0, class R1>
00197     void SubData(Data<T, 2, DTG>&, R0 r0, R1 r1);
00198     template<class DTG, class R0, class R1, class R2>
00199     void SubData(Data<T, 3, DTG>&, R0 r0, R1 r1, R2 r2);
00200     template<class DTG, class R0, class R1, class R2,
00201              class R3>
00202     void SubData(Data<T, 4, DTG>&, R0 r0, R1 r1, R2 r2,
00203                  R3 r3);
00204     template<class DTG, class R0, class R1, class R2,
00205              class R3, class R4>
00206     void SubData(Data<T, 5, DTG>&, R0 r0, R1 r1, R2 r2,
00207                  R3 r3, R4 r4);
00208     template<class DTG, class R0, class R1, class R2,
00209              class R3, class R4, class R5>
00210     void SubData(Data<T, 6, DTG>&, R0 r0, R1 r1, R2 r2,
00211                  R3 r3, R4 r4, R5 r5);
00212     template<class DTG, class R0, class R1, class R2,
00213              class R3, class R4, class R5,
00214              class R6>
00215     void SubData(Data<T, 7, DTG>&, R0 r0, R1 r1, R2 r2,
00216                  R3 r3, R4 r4, R5 r5, R6 r6);
00217     template<class DTG, class R0, class R1, class R2,
00218              class R3, class R4, class R5,
00219              class R6, class R7>
00220     void SubData(Data<T, 8, DTG>&, R0 r0, R1 r1, R2 r2,
00221                  R3 r3, R4 r4, R5 r5, R6 r6,
00222                  R7 r7);
00223     template<class DTG, class R0, class R1, class R2,
00224              class R3, class R4, class R5,
00225              class R6, class R7, class R8>
00226     void SubData(Data<T, 9, DTG>&, R0 r0, R1 r1, R2 r2,
00227                  R3 r3, R4 r4, R5 r5, R6 r6,
00228                  R7 r7, R8 r8);
00229     template<class DTG, class R0, class R1, class R2,
00230              class R3, class R4, class R5,
00231              class R6, class R7, class R8, class R9>
00232     void SubData(Data<T, 10, DTG>&, R0 r0, R1 r1, R2 r2,
00233                  R3 r3, R4 r4, R5 r5, R6 r6,
00234                  R7 r7, R8 r8, R9 r9);
00235 
00236     void ResizeGrid();
00237     void ResizeGrid(Grid<TG>& G0);
00238     void ResizeGrid(Grid<TG>& G0, Grid<TG>& G1);
00239     void ResizeGrid(Grid<TG>& G0, Grid<TG>& G1,
00240                     Grid<TG>& G2);
00241     void ResizeGrid(Grid<TG>& G0, Grid<TG>& G1,
00242                     Grid<TG>& G2, Grid<TG>& G3);
00243     void ResizeGrid(Grid<TG>& G0, Grid<TG>& G1,
00244                     Grid<TG>& G2, Grid<TG>& G3,
00245                     Grid<TG>& G4);
00246     void ResizeGrid(Grid<TG>& G0, Grid<TG>& G1,
00247                     Grid<TG>& G2, Grid<TG>& G3,
00248                     Grid<TG>& G4, Grid<TG>& G5);
00249     void ResizeGrid(Grid<TG>& G0, Grid<TG>& G1,
00250                     Grid<TG>& G2, Grid<TG>& G3,
00251                     Grid<TG>& G4, Grid<TG>& G5,
00252                     Grid<TG>& G6);
00253     void ResizeGrid(Grid<TG>& G0, Grid<TG>& G1,
00254                     Grid<TG>& G2, Grid<TG>& G3,
00255                     Grid<TG>& G4, Grid<TG>& G5,
00256                     Grid<TG>& G6, Grid<TG>& G7);
00257     void ResizeGrid(Grid<TG>& G0, Grid<TG>& G1,
00258                     Grid<TG>& G2, Grid<TG>& G3,
00259                     Grid<TG>& G4, Grid<TG>& G5,
00260                     Grid<TG>& G6, Grid<TG>& G7,
00261                     Grid<TG>& G8);
00262     void ResizeGrid(Grid<TG>& G0, Grid<TG>& G1,
00263                     Grid<TG>& G2, Grid<TG>& G3,
00264                     Grid<TG>& G4, Grid<TG>& G5,
00265                     Grid<TG>& G6, Grid<TG>& G7,
00266                     Grid<TG>& G8, Grid<TG>& G9);
00267 
00268     void ResizeGrid(int N0);
00269     void ResizeGrid(int N0, int N1);
00270     void ResizeGrid(int N0, int N1,
00271                     int N2);
00272     void ResizeGrid(int N0, int N1,
00273                     int N2, int N3);
00274     void ResizeGrid(int N0, int N1,
00275                     int N2, int N3,
00276                     int N4);
00277     void ResizeGrid(int N0, int N1,
00278                     int N2, int N3,
00279                     int N4, int N5);
00280     void ResizeGrid(int N0, int N1,
00281                     int N2, int N3,
00282                     int N4, int N5,
00283                     int N6);
00284     void ResizeGrid(int N0, int N1,
00285                     int N2, int N3,
00286                     int N4, int N5,
00287                     int N6, int N7);
00288     void ResizeGrid(int N0, int N1,
00289                     int N2, int N3,
00290                     int N4, int N5,
00291                     int N6, int N7,
00292                     int N8);
00293     void ResizeGrid(int N0, int N1,
00294                     int N2, int N3,
00295                     int N4, int N5,
00296                     int N6, int N7,
00297                     int N8, int N9);
00298     
00299     void Resize();
00300     void Resize(Grid<TG>& G0);
00301     void Resize(Grid<TG>& G0, Grid<TG>& G1);
00302     void Resize(Grid<TG>& G0, Grid<TG>& G1,
00303                 Grid<TG>& G2);
00304     void Resize(Grid<TG>& G0, Grid<TG>& G1,
00305                 Grid<TG>& G2, Grid<TG>& G3);
00306     void Resize(Grid<TG>& G0, Grid<TG>& G1,
00307                 Grid<TG>& G2, Grid<TG>& G3,
00308                 Grid<TG>& G4);
00309     void Resize(Grid<TG>& G0, Grid<TG>& G1,
00310                 Grid<TG>& G2, Grid<TG>& G3,
00311                 Grid<TG>& G4, Grid<TG>& G5);
00312     void Resize(Grid<TG>& G0, Grid<TG>& G1,
00313                 Grid<TG>& G2, Grid<TG>& G3,
00314                 Grid<TG>& G4, Grid<TG>& G5,
00315                 Grid<TG>& G6);
00316     void Resize(Grid<TG>& G0, Grid<TG>& G1,
00317                 Grid<TG>& G2, Grid<TG>& G3,
00318                 Grid<TG>& G4, Grid<TG>& G5,
00319                 Grid<TG>& G6, Grid<TG>& G7);
00320     void Resize(Grid<TG>& G0, Grid<TG>& G1,
00321                 Grid<TG>& G2, Grid<TG>& G3,
00322                 Grid<TG>& G4, Grid<TG>& G5,
00323                 Grid<TG>& G6, Grid<TG>& G7,
00324                 Grid<TG>& G8);
00325     void Resize(Grid<TG>& G0, Grid<TG>& G1,
00326                 Grid<TG>& G2, Grid<TG>& G3,
00327                 Grid<TG>& G4, Grid<TG>& G5,
00328                 Grid<TG>& G6, Grid<TG>& G7,
00329                 Grid<TG>& G8, Grid<TG>& G9);
00330 
00331     void Resize(int N0);
00332     void Resize(int N0, int N1);
00333     void Resize(int N0, int N1,
00334                 int N2);
00335     void Resize(int N0, int N1,
00336                 int N2, int N3);
00337     void Resize(int N0, int N1,
00338                 int N2, int N3,
00339                 int N4);
00340     void Resize(int N0, int N1,
00341                 int N2, int N3,
00342                 int N4, int N5);
00343     void Resize(int N0, int N1,
00344                 int N2, int N3,
00345                 int N4, int N5,
00346                 int N6);
00347     void Resize(int N0, int N1,
00348                 int N2, int N3,
00349                 int N4, int N5,
00350                 int N6, int N7);
00351     void Resize(int N0, int N1,
00352                 int N2, int N3,
00353                 int N4, int N5,
00354                 int N6, int N7,
00355                 int N8);
00356     void Resize(int N0, int N1,
00357                 int N2, int N3,
00358                 int N4, int N5,
00359                 int N6, int N7,
00360                 int N8, int N9);
00361     
00362     void Resize(const TinyVector<int, N>& shape);
00363     
00364     // Calculus.
00365     void Mlt(T alpha);
00366     void Add(T alpha);
00367     void Apply(void function(T&));
00368     template <class F>
00369     void Apply(F& function);
00370     void Apply(T (function)(const T&));
00371     template <class T0, class TG0, class F>
00372     void Apply(Data<T0, N, TG0>&, F& function);
00373 
00374     T GetMax() const;
00375     T GetMaxAbs() const;
00376     T GetSignedMaxAbs() const;
00377     T GetMin() const;
00378 
00379     Array<int, 1> GetMaxIndex() const;
00380     Array<int, 1> GetMaxAbsIndex() const;
00381     Array<int, 1> GetMinIndex() const;
00382 
00383     T Sum() const;
00384     template <class Ts>
00385     void Sum(Ts& sum) const;
00386     T Mean() const;
00387     template <class Ts>
00388     void Mean(Ts& mean) const;
00389     T Variance() const;
00390     template <class Ts>
00391     void Variance(Ts& var) const;
00392     T StandardDeviation() const;
00393     template <class Ts>
00394     void StandardDeviation(Ts& std) const;
00395 
00396     T Norm1() const;
00397     T Norm2() const;
00398     T Norm(T p) const;
00399 
00400     void Fill();
00401     void Fill(T value);
00402 
00403     void SetZero();
00404     bool IsZero();
00405 
00406     void Threshold(T threshold_min, T threshold_max);
00407     void ThresholdAbs(T threshold);
00408     void ThresholdMin(T threshold);
00409     void ThresholdMax(T threshold);
00410 
00411     template <class T0, class TG0>
00412     T NGE_interpolation(Data<T0, N, TG0>& data, T limit = T(0));
00413     template <class T0, class TG0>
00414     T NGE(Data<T0, N, TG0>& data, T limit = T(0));
00415 
00416     template <class T0, class TG0>
00417     T Bias_interpolation(Data<T0, N, TG0>& data);
00418     template <class T0, class TG0>
00419     T Bias(Data<T0, N, TG0>& data);
00420 
00421     template <class T0, class TG0>
00422     T RMS_interpolation(Data<T0, N, TG0>& data);
00423     template <class T0, class TG0>
00424     T RMS(Data<T0, N, TG0>& data);
00425 
00426     template <class T0, class TG0>
00427     T RelativeRMS_interpolation(Data<T0, N, TG0>& data);
00428     template <class T0, class TG0>
00429     T RelativeRMS(Data<T0, N, TG0>& data);
00430 
00431     template <class T0, class TG0>
00432     T Corr_interpolation(Data<T0, N, TG0>& data);
00433     template <class T0, class TG0>
00434     T Corr(Data<T0, N, TG0>& data);
00435 
00436     template <class T0, class TG0>
00437     T ErrorLessThan_interpolation(Data<T0, N, TG0>& data, T threshold);
00438     template <class T0, class TG0>
00439     T ErrorLessThan(Data<T0, N, TG0>& data, T threshold);
00440 
00441     void ReverseData(int dim = 0);
00442     void SwitchDimensions(TinyVector<int, N> NewDim, Grid<TG>& G0);
00443     void SwitchDimensions(TinyVector<int, N> NewDim, Grid<TG>& G0,
00444                           Grid<TG>& G1);
00445     void SwitchDimensions(TinyVector<int, N> NewDim, Grid<TG>& G0,
00446                           Grid<TG>& G1, Grid<TG>& G2);
00447     void SwitchDimensions(TinyVector<int, N> NewDim, Grid<TG>& G0,
00448                           Grid<TG>& G1, Grid<TG>& G2,
00449                           Grid<TG>& G3);
00450     void SwitchDimensions(TinyVector<int, N> NewDim, Grid<TG>& G0,
00451                           Grid<TG>& G1, Grid<TG>& G2,
00452                           Grid<TG>& G3, Grid<TG>& G4);
00453     void SwitchDimensions(TinyVector<int, N> NewDim, Grid<TG>& G0,
00454                           Grid<TG>& G1, Grid<TG>& G2,
00455                           Grid<TG>& G3, Grid<TG>& G4,
00456                           Grid<TG>& G5);
00457     void SwitchDimensions(TinyVector<int, N> NewDim, Grid<TG>& G0,
00458                           Grid<TG>& G1, Grid<TG>& G2,
00459                           Grid<TG>& G3, Grid<TG>& G4,
00460                           Grid<TG>& G5, Grid<TG>& G6);
00461     void SwitchDimensions(TinyVector<int, N> NewDim, Grid<TG>& G0,
00462                           Grid<TG>& G1, Grid<TG>& G2,
00463                           Grid<TG>& G3, Grid<TG>& G4,
00464                           Grid<TG>& G5, Grid<TG>& G6,
00465                           Grid<TG>& G7);
00466     void SwitchDimensions(TinyVector<int, N> NewDim, Grid<TG>& G0,
00467                           Grid<TG>& G1, Grid<TG>& G2,
00468                           Grid<TG>& G3, Grid<TG>& G4,
00469                           Grid<TG>& G5, Grid<TG>& G6,
00470                           Grid<TG>& G7, Grid<TG>& G8);
00471     void SwitchDimensions(TinyVector<int, N> NewDim, Grid<TG>& G0,
00472                           Grid<TG>& G1, Grid<TG>& G2,
00473                           Grid<TG>& G3, Grid<TG>& G4,
00474                           Grid<TG>& G5, Grid<TG>& G6,
00475                           Grid<TG>& G7, Grid<TG>& G8,
00476                           Grid<TG>& G9);
00477 
00478     void ChangeCoords(FuncCoords_Base<TG>& f);
00479     void ChangeCoordsInPlace(Function_Base<TG>& f);
00480 
00481     void Print() const;
00482     void PrintInfo() const;
00483     string InfoString() const;
00484 
00485   private:
00486     void ClearGrids();
00487     void SetVariables();
00488 
00489   };
00490 
00491 
00492 }  // namespace Data.
00493 
00494 
00495 #define FILE_SELDONDATA_DATA_HXX
00496 #endif

Generated on Tue Nov 17 11:20:52 2009 for SeldonData by  doxygen 1.5.1