C++ main module for emicrom Package  1.0
MATH_MultiLevelsToeplitzMatrix.h
Go to the documentation of this file.
1 #ifndef MATH_MultiLevelsToeplitzMatrix_H
2 #define MATH_MultiLevelsToeplitzMatrix_H
3 
4 #include "CORE_Object.h"
5 
6 #include "CORE_Array.h"
7 #include "CORE_Run.h"
8 
9 #include "FFTW_FFT.h"
10 
12 
56 
59 
60 public:
61 
62 
63  // ATTRIBUTES
64 public:
65  static const tFlag CANONICAL_SPACE=0;
66  static const tFlag SPECTRAL_SPACE=1;
67 
68 private:
69 
70  //state of the matrix
72 
73 
74  //number of values in the canonical space
76 
77 
78  //the number of levels
80 
81  //the number of rows or column of the matrix
83 
84 
85 
86 
87  // ASSOCIATIONS
88 
89 
90  //the leaf matrix storage
91  SP::MATH_LeafBlockMatrixStorage mStorage;
92 
93  //values of the toeplitz matrix
94  SP::FFTW_FFT mFFT;
95 
96 
97 
98 protected:
99 
100  // METHOD
101 
102  // CONSTRUCTORS
103 
107 
108 
109 
110  // DESTRUCTORS
111 
112 
115  virtual ~MATH_MultiLevelsToeplitzMatrix(void);
116 
117 
118 public:
122  virtual SP::MATH_MultiLevelsToeplitzMatrix NewInstance() const=0;
123 
124 
125 
126 
127  //OPERATORS
128 protected:
133  inline tFFTWComplex & operator[](const tUIndex& k) {
134  return (*mFFT.get())[k];
135  };
140  inline const tFFTWComplex & operator[](const tUIndex& k) const {
141  return (*mFFT.get())[k];
142  };
143 
144 public:
150  inline const tFFTWComplex& operator()(const tUIndex& i,const tUIndex& j) const {
151  if (mSpace!=CANONICAL_SPACE) throw CORE_Exception("emicrom/math",
152  "MATH_MultiLevelsToeplitzMatrix()",
153  "the space is not the CANONICAL SPACE");
154  return (*mFFT.get())[getIndex(i,j)];
155  };
156 
162  inline tFFTWComplex & operator()(const tUIndex& i,const tUIndex& j) {
163  if (mSpace!=CANONICAL_SPACE) throw CORE_Exception("emicrom/math",
164  "MATH_MultiLevelsToeplitzMatrix()",
165  "the space is not the CANONICAL SPACE");
166  return (*mFFT.get())[getIndex(i,j)];
167  };
168 
169 
170 
171 
172 
175  virtual void copy(const MATH_MultiLevelsToeplitzMatrix& mat);
176 
177 
178  // SET methods
181  virtual void clear();
182 
183 protected:
189  inline void setSpace(const tFlag& space) {
190  mSpace=space;
191  };
192 
193 
196  inline void setStorage(SP::MATH_LeafBlockMatrixStorage storage) {
197  mStorage=storage;
198  }
199 
200 public:
201 
205  virtual void setLeafBlockDimension(const tUIndex& n) {
206  mStorage->setDimension(n);
207  }
208 
218  virtual void setLevels(const tUSInt& levelsNumber,const tUIndex levels[],const tUIndex& nD) {
220  setLevels(levelsNumber,levels);
221  }
222 
237  void setLevels(const tUSInt& levelsNumber,const tUIndex levels[]);
238 
239 
240 
241 
242 
243 
244 protected:
245 
249  inline void setDFT(SP::FFTW_FFT dft) {
250  mFFT=dft;
251  if (dft.get()==null) throw CORE_Exception("emicrom/math/toeplitz",
252  "MATH_MultiLevelsToeplitzMatrix::setDFT(null)",
253  "impossible to set the Discrete Fourier Transform: FFTW_ClassFactory not added in general class factory");
254  }
255 
256  // GET method
257 
258 public:
267  virtual tULLInt getMemorySize() const {
268  return (mFFT.get()==null)?0:mFFT->getMemorySize();
269  }
270 
271 protected:
272 
276  inline const FFTW_FFT& getDFT() const {
277  return *mFFT.get();
278  }
282  inline FFTW_FFT& getDFT() {
283  return *mFFT.get();
284  }
285 
286 
287 
288 public:
293  inline tReal getRealValue(const tUIndex& i,const tUIndex& j) const {
294  return (*this)(i,j)[0];
295  }
296 
297 
301  inline const tUIndex& getDimension() const {
302  return mDimension;
303  };
307  inline const tUIndex& getRowsNumber() const {
308  return mDimension;
309  };
313  inline const tUIndex& getColumnsNumber() const {
314  return mDimension;
315  };
316 
317 
318 public:
319 
320 
325  return mFFT->getArray();
326  };
330  inline const FFTW_ComplexArray& getValues() const {
331  return mFFT->getArray();
332  };
338  inline const tFFTWComplex* getLeafBlockValues(const tIndex indices[]) const {
339  return &getValues()[getToeplitzBlockIndex(mLevels.getSize(),&mLevels[0],indices)*mStorage->getSize()];
340 
341  }
347  inline tFFTWComplex* getLeafBlockValues(const tIndex indices[]) {
348  return &getValues()[getToeplitzBlockIndex(mLevels.getSize(),&mLevels[0],indices)*mStorage->getSize()];
349 
350  }
351 
355  inline const CORE_UIndexArray& getLevels() const {
356  return mLevels;
357  };
358 
361  inline tUSInt getLevelsNumber() const {
362  return mLevels.getSize();
363  }
364 
365 
366 
370  inline const tUIndex& getCanonicalSpaceSize() const {
371  return mCanonicalSpaceSize;
372  }
373 
374 
378  inline tUIndex getLeafBlockSize() const {
379  return mStorage->getSize();
380  }
384  inline const tUIndex& getLeafBlockDimension() const {
385  return mStorage->getDimension();
386  }
390  inline tUIndex getBlocksNumber() const {
391  return mCanonicalSpaceSize/getLeafBlockSize();
392  }
398  inline const tUIndex& getBlocksNumberPerRow(const tUSInt& l) const {
399  return mLevels[l-1];
400  }
401 
406  inline tUIndex getBlocksNumber(const tUIndex& l) const {
407  return 2*mLevels[l-1]-1;
408  }
409 
410 
411 
412 public:
418  inline const tFlag& getSpace() const {
419  return mSpace;
420  }
421 
425  inline const MATH_LeafBlockMatrixStorage& getStorage() const {
426  return *mStorage.get();
427  }
432  return *mStorage.get();
433  }
434 
440  inline tUIndex getIndex(const tUIndex& i,const tUIndex& j) const {
441  tUIndex nValues=0;
442  return getIndex(i,j,mLevels.getSize(),getRowsNumber(),nValues);
443 
444  };
445 
453  tUIndex getToeplitzBlockIndex(const tUSInt& nLevels,const tUIndex N[],const tIndex I[]) const;
459  inline tUIndex getToeplitzBlockIndex(const tIndex I[]) const {
460  if (mLevels.getSize()==0) return 0;
461  return getToeplitzBlockIndex(mLevels.getSize(),&mLevels[0],I);
462  }
463 
464 private:
472  tUIndex getIndex(const tUIndex& i,
473  const tUIndex& j,
474  const tUSInt& level,
475  const tUIndex& nRows,
476  tUIndex& nValues) const;
477 protected:
478 
489  inline tUIndex getBlockIndex(const tUIndex& ib,const tUIndex& jb,const tUIndex& N) const {
490  //\f$ {T_{-N+1},...,T_{-1},T_0,T_1,.....T_{N-1} \f$
491  return ib-jb+N-1;
492 
493  }
494 
495 
496 
497 
498 
499 public:
500 
501  //product in spectral space methods
502  //==================================
503 
509  void projection(const tFlag& space) {
510  if (space==getSpace()) return;
511 
512  switch(space) {
513  case SPECTRAL_SPACE:
514  diagonalize();
515  break;
516  case CANONICAL_SPACE:
517  recover();
518  break;
519  }
520  setSpace(space);
521  }
522 
523 protected:
527  virtual void diagonalize()=0;
528 
529 
533  virtual void recover()=0;
534 
535 public:
544  virtual void vectorProduct(const CORE_RealArray& X,
545  CORE_RealArray& Y) const {
546  Y.setSize(X.getSize());
547  vectorProduct(X.getSize(),&X[0],&Y[0]);
548  }
558  virtual void vectorProduct(const tUIndex& N,
559  const tReal* X,
560  tReal* Y) const=0;
561 
564  virtual tString toString() const;
565 
566 
567 };
568 #endif
const tFFTWComplex * getLeafBlockValues(const tIndex indices[]) const
get the values of the leaf block
Definition: MATH_MultiLevelsToeplitzMatrix.h:338
const tUIndex & getSize() const
return the size of the array for reading
Definition: CORE_Array.h:1018
const CORE_UIndexArray & getLevels() const
get the level of the matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:355
FFTW_FFT & getDFT()
get the FFT class
Definition: MATH_MultiLevelsToeplitzMatrix.h:282
tUIndex getToeplitzBlockIndex(const tIndex I[]) const
get the block index corresponding to indices
Definition: MATH_MultiLevelsToeplitzMatrix.h:459
const tUIndex & getLeafBlockDimension() const
return the dimension of the leaf block matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:384
const tUIndex & getRowsNumber() const
get the dimension of the matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:307
SP_OBJECT(MATH_MultiLevelsToeplitzMatrix)
void setStorage(SP::MATH_LeafBlockMatrixStorage storage)
set the storage of the matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:196
tReal getRealValue(const tUIndex &i, const tUIndex &j) const
get the real value at row i and column j
Definition: MATH_MultiLevelsToeplitzMatrix.h:293
MATH_LeafBlockMatrixStorage & getStorage()
get the storage of the leaf matrices
Definition: MATH_MultiLevelsToeplitzMatrix.h:431
virtual tString toString() const
return string
Definition: MATH_MultiLevelsToeplitzMatrix.cpp:192
tFFTWComplex * getLeafBlockValues(const tIndex indices[])
get the values of the leaf block
Definition: MATH_MultiLevelsToeplitzMatrix.h:347
void setDFT(SP::FFTW_FFT dft)
set the DFT class
Definition: MATH_MultiLevelsToeplitzMatrix.h:249
const tUIndex & getCanonicalSpaceSize() const
get canonical space size
Definition: MATH_MultiLevelsToeplitzMatrix.h:370
const tUIndex & getBlocksNumberPerRow(const tUSInt &l) const
get the blocks number per row or column at the level
Definition: MATH_MultiLevelsToeplitzMatrix.h:398
tUIndex getLeafBlockSize() const
return the size of the leaf block matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:378
virtual void setLeafBlockDimension(const tUIndex &n)
set the dimension of leaf block
Definition: MATH_MultiLevelsToeplitzMatrix.h:205
static const tFlag CANONICAL_SPACE
Definition: MATH_MultiLevelsToeplitzMatrix.h:65
SP::FFTW_FFT mFFT
Definition: MATH_MultiLevelsToeplitzMatrix.h:94
virtual void clear()
clear the multi level toeplitz matrix
Definition: MATH_MultiLevelsToeplitzMatrix.cpp:20
void projection(const tFlag &space)
make the projection in the space
Definition: MATH_MultiLevelsToeplitzMatrix.h:509
tUIndex mCanonicalSpaceSize
Definition: MATH_MultiLevelsToeplitzMatrix.h:75
This class manages the execution of Fast Fourier Transform. several fast Fourier Transforms may be ap...
Definition: FFTW_FFT.h:28
DEFINE_SPTR(MATH_MultiLevelsToeplitzMatrix)
virtual ~MATH_MultiLevelsToeplitzMatrix(void)
destroy a multi level toeplitz matrix
Definition: MATH_MultiLevelsToeplitzMatrix.cpp:17
This class is multi levels toeplitz matrix. The matrix at level k is composed by toeplitz block matr...
Definition: MATH_MultiLevelsToeplitzMatrix.h:57
#define tUSInt
Definition: types.h:28
const tFFTWComplex & operator[](const tUIndex &k) const
get the value at index k
Definition: MATH_MultiLevelsToeplitzMatrix.h:140
#define tFFTWComplex
Definition: fftw_types.h:65
tUIndex getBlocksNumber(const tUIndex &l) const
get the blocks number at the level
Definition: MATH_MultiLevelsToeplitzMatrix.h:406
void setSize(const tUIndex &n)
set the size
Definition: CORE_Array.h:292
virtual void copy(const MATH_MultiLevelsToeplitzMatrix &mat)
copy the instance
Definition: MATH_MultiLevelsToeplitzMatrix.cpp:29
#define null
Definition: types.h:144
virtual void setLevels(const tUSInt &levelsNumber, const tUIndex levels[], const tUIndex &nD)
set the levels of the matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:218
static const tFlag SPECTRAL_SPACE
Definition: MATH_MultiLevelsToeplitzMatrix.h:66
tFFTWComplex & operator[](const tUIndex &k)
get the value at index k
Definition: MATH_MultiLevelsToeplitzMatrix.h:133
tUIndex mDimension
Definition: MATH_MultiLevelsToeplitzMatrix.h:82
virtual tULLInt getMemorySize() const
return the memory size in byte
Definition: MATH_MultiLevelsToeplitzMatrix.h:267
const tUIndex & getDimension() const
get the dimension of the matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:301
tFlag mSpace
Definition: MATH_MultiLevelsToeplitzMatrix.h:71
Definition: MATH_LeafBlockMatrixStorage.h:22
#define tIndex
Definition: types.h:129
const FFTW_FFT & getDFT() const
get the FFT class
Definition: MATH_MultiLevelsToeplitzMatrix.h:276
const FFTW_ComplexArray & getValues() const
get the values of the matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:330
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
virtual void recover()=0
projection of the matrix in the CANONICAL SPACE
CORE_UIndexArray mLevels
Definition: MATH_MultiLevelsToeplitzMatrix.h:79
virtual void vectorProduct(const CORE_RealArray &X, CORE_RealArray &Y) const
do the vector product of the circular matrix C with Y by an FFT method
Definition: MATH_MultiLevelsToeplitzMatrix.h:544
const MATH_LeafBlockMatrixStorage & getStorage() const
get the storage of the leaf matrices
Definition: MATH_MultiLevelsToeplitzMatrix.h:425
const tFFTWComplex & operator()(const tUIndex &i, const tUIndex &j) const
get the value of the matrix at row i and column j
Definition: MATH_MultiLevelsToeplitzMatrix.h:150
This class describes FFT complex array based on fft_complex structure.
Definition: FFTW_ComplexArray.h:17
#define tUIndex
Definition: types.h:126
abstract base class for most classes.
Definition: CORE_Object.h:53
tUSInt getLevelsNumber() const
get the number of levels of the matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:361
tUIndex getBlocksNumber() const
get the blocks number
Definition: MATH_MultiLevelsToeplitzMatrix.h:390
const tUIndex & getColumnsNumber() const
get the dimension of the matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:313
#define tString
Definition: types.h:135
const tFlag & getSpace() const
get the space of the matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:418
tUIndex getToeplitzBlockIndex(const tUSInt &nLevels, const tUIndex N[], const tIndex I[]) const
get the block index corresponding to indices
Definition: MATH_MultiLevelsToeplitzMatrix.cpp:99
virtual SP::MATH_MultiLevelsToeplitzMatrix NewInstance() const =0
new instance
virtual void diagonalize()=0
diagonalize the matrix projection of the matrix in the SPECTRAL_SPACE
SP::MATH_LeafBlockMatrixStorage mStorage
Definition: MATH_MultiLevelsToeplitzMatrix.h:91
tUIndex getIndex(const tUIndex &i, const tUIndex &j) const
return the index in values of the matrix value at row i and column j
Definition: MATH_MultiLevelsToeplitzMatrix.h:440
tFFTWComplex & operator()(const tUIndex &i, const tUIndex &j)
get the value of the matrix at row i and column j
Definition: MATH_MultiLevelsToeplitzMatrix.h:162
#define tULLInt
Definition: types.h:45
FFTW_ComplexArray & getValues()
get the values of the matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:324
MATH_MultiLevelsToeplitzMatrix(void)
create a multi level toeplitz matrix
Definition: MATH_MultiLevelsToeplitzMatrix.cpp:8
#define tReal
Definition: types.h:118
void setSpace(const tFlag &space)
set the space of the multi level block matrix
Definition: MATH_MultiLevelsToeplitzMatrix.h:189
tUIndex getBlockIndex(const tUIndex &ib, const tUIndex &jb, const tUIndex &N) const
get the index of the block in the block list
Definition: MATH_MultiLevelsToeplitzMatrix.h:489
#define tFlag
Definition: types.h:74