C++ main module for emicrom Package  1.0
FFTW_ComplexArray.h
Go to the documentation of this file.
1 #ifndef FFTW_ComplexArray_H
2 #define FFTW_ComplexArray_H
3 
4 
5 #include "FFTW_Object.h"
6 #include "CORE_Array.h"
7 
8 #include "FFTW_Complex.h"
9 
17 class FFTW_ComplexArray : public virtual FFTW_Object {
19  // ATTRIBUTES
20 
21 
22 private:
23 
24  //values of the warray
26 
27  //size of the array
29 
30  //memory size of the array
32 
33  //inidate if the values has been allocated within this class
35 
36 
37  // ASSOCIATIONS
38 
39 
40 public:
41  // METHODS
42 
43  // CONSTRUCTORS
44 
46  FFTW_ComplexArray(void);
47 
49  FFTW_ComplexArray(const tUIndex& n);
50 
51 
52 
53  // DESTRUCTORS
54 
55 
58  virtual ~FFTW_ComplexArray(void);
59 
60 public:
64  static inline SP::FFTW_ComplexArray New() {
65  SP::FFTW_ComplexArray p(new FFTW_ComplexArray(),
67  p->setThis(p);
68  return p;
69  };
70 
71 
72  //operators
73  //=========
74 
79  inline tFFTWComplex& operator[](const tUIndex & i) {
80  if (i>=mCapacity)
81  throw CORE_Exception("math/fftw",
82  "FFTW_ComplexArray["+CORE_Integer::toString(i)+"]",
83  "index out of bounds [0,"+CORE_Integer::toString(mCapacity)+"[");
84  return mValues[i];
85  };
86 
91  inline const tFFTWComplex& operator[](const tUIndex & i) const {
92  if (i>=mCapacity)
93  throw CORE_Exception("math/fftw",
94  "FFTW_ComplexArray["+CORE_Integer::toString(i)+"]",
95  "index out of bounds [0,"+CORE_Integer::toString(mCapacity)+"[");
96  return mValues[i];
97  };
98 
107  inline tFFTWReal& operator()(const tUIndex & i,const tUSInt& j) {
108  if (j>=2)
109  throw CORE_Exception("math/fftw",
110  "FFTW_Complex("+CORE_Integer::toString(i)+","+CORE_Integer::toString(j)+")",
111  "index out of bounds [0,1]");
112  return (*this)[i][j];
113  };
114 
122  inline const tFFTWReal& operator()(const tUIndex & i,const tUSInt& j) const {
123  if (j>=2)
124  throw CORE_Exception("math/fftw",
125  "FFTW_Complex("+CORE_Integer::toString(i)+","+CORE_Integer::toString(j)+")",
126  "index out of bounds [0,1]");
127  return (*this)[i][j];
128  };
134  //cout << " complex array = operator \n";
135  copy(s);
136  return (*this);
137  };
142  //cout << " complex array = operator \n";
143  copy(s);
144  return (*this);
145  };
146 
152  copy(s);
153  return (*this);
154  };
160  copy(s);
161  return (*this);
162  };
168  copy(s);
169  return (*this);
170  };
171 
177  initArray(s);
178  return (*this);
179  };
185  initArray(s);
186  return (*this);
187  };
188 
194  multiply(s);
195  return (*this);
196  };
202  multiply(s);
203  return (*this);
204  }
205 
206 
213  multiply(s);
214  return (*this);
215  };
216 
220  if (s==0) throw CORE_Exception("math/fftw","FFTW_ComplexArray/=","division by 0");
221  multiply(1/s);
222  return (*this);
223  };
224 
230  add(s);
231  return (*this);
232  };
238  add(s);
239  return (*this);
240  };
246  add(s);
247  return (*this);
248  };
249 
255  add(-s);
256  return (*this);
257  };
258 
259  //Builder of array
260  //================
261 private:
262 
265  void desallocate();
266 
271  void allocate(const tUIndex& cap);
272 
273 public:
276  inline void clear() {
277 
278  desallocate();
279  mSize=0;
280  mCapacity=0;
281  mValues=null;
282  mIsPrivateAllocated=false;
283  }
284 
288  inline void setSize(const tUIndex& n) {
289  if (n>mCapacity) allocate(n);
290  mSize=n;
291  }
292 
295  void fitToSize();
296 
297 public:
298  //copy method
299  //===========
300 
304  void copy(const FFTW_ComplexArray& f);
305 
309  void copy(const CORE_ComplexArray& f);
310 
315  template<class T>
316  void copy(const complex<T>* f,const tUIndex& n);
317 
318 
322  void copy(const CORE_RealArray& f);
323 
327  void copy(const CORE_DoubleArray& f);
328 
332  void copy(const CORE_FloatArray& f);
333 
334 
335  // init methods
336 
340  void initArray(const tReal& f);
341 
345  void initArray(const tFFTWComplex& f);
346 
347 
348  //set methods
349  //===========
350 
356  inline void setValue(const tUIndex& index,const tFFTWReal& x,const tFFTWReal& y) {
357  tFFTWComplex &c=mValues[index];
358  c[0]=x;
359  c[1]=y;
360  }
361 
369  desallocate();
370  mValues=array;
371  mSize=n;
372  mCapacity=n;
373  mIsPrivateAllocated=false;
374  return true;
375  }
376 
377 
378  // GET methods
379 
388  virtual tULLInt getMemorySize() const {
389  return sizeof(tFFTWComplex)*mSize;
390  }
394  inline const tFFTWComplex* getValues() const {
395  return mValues;
396  }
401  return mValues;
402  }
406  inline const tUIndex& getSize() const {
407  return mSize;
408  }
412  inline const tUIndex& getCapacity() const {
413  return mCapacity;
414  }
415 
416 
422  inline void swap(const tUIndex& i,const tUIndex& j) {
423  std::swap(mValues[i][0],mValues[j][0]);
424  std::swap(mValues[i][1],mValues[j][1]);
425  }
426 
427  //arithmetic methods
428  //===================
432  void multiply(const tFFTWReal& s);
436  void multiply(const tFFTWComplex& s);
437 
441  void multiply(const FFTW_ComplexArray& s);
442 
446  void add(const tFFTWReal& s);
447 
451  void add(const tFFTWComplex& s);
452 
456  void add(const FFTW_ComplexArray& s);
457 
458 
466  static void MatrixVectorProduct(const tFFTWReal& alpha,
467  const tUIndex& N,const tFFTWComplex* A,
468  const tFFTWComplex* X,
469  tFFTWComplex* Y);
470 
471 
472 
473  //euclidian methods
474  //=================
475 
480  tFFTWReal norm2() const;
481 
486  inline tFFTWReal norm() const {
487  return sqrt(norm2());
488  }
489 
490 
496  tFFTWReal distance2(const FFTW_ComplexArray& x) const;
497 
498 
504  inline tFFTWReal distance(const FFTW_ComplexArray& x) const {
505  return sqrt(distance2(x));
506  }
507 
508 
513  tFFTWReal fabs(tUIndex& i) const;
514 
520  tFFTWReal fabs(const FFTW_ComplexArray& x,tUIndex& i) const;
521 
522 
523 
527  virtual tString toString() const;
528 
529 };
530 
531 #include "FFTW_ComplexArray.hpp"
532 
533 #endif
void allocate(const tUIndex &cap)
allocate the memory if the array
Definition: FFTW_ComplexArray.cpp:38
void copy(const FFTW_ComplexArray &f)
copy the complex array
Definition: FFTW_ComplexArray.cpp:180
DEFINE_SPTR(FFTW_ComplexArray)
FFTW_ComplexArray & operator-=(const tFFTWReal &s)
sub s to the array
Definition: FFTW_ComplexArray.h:254
const tFFTWReal & operator()(const tUIndex &i, const tUSInt &j) const
get the value for reading only
Definition: FFTW_ComplexArray.h:122
const tFFTWComplex & operator[](const tUIndex &i) const
get the value for reading only
Definition: FFTW_ComplexArray.h:91
FFTW_ComplexArray & operator+=(const tFFTWComplex &s)
add s to the array
Definition: FFTW_ComplexArray.h:237
const tUIndex & getCapacity() const
get the capacity
Definition: FFTW_ComplexArray.h:412
FFTW_ComplexArray & operator+=(const FFTW_ComplexArray &s)
add s to the array
Definition: FFTW_ComplexArray.h:245
FFTW_ComplexArray & operator+=(const tFFTWReal &s)
add s to the array
Definition: FFTW_ComplexArray.h:229
tBoolean mIsPrivateAllocated
Definition: FFTW_ComplexArray.h:34
void multiply(const tFFTWReal &s)
multiply the real part of the elements of the array by the scalar s
Definition: FFTW_ComplexArray.cpp:329
FFTW_ComplexArray & operator/=(const tFFTWReal &s)
divide operator
Definition: FFTW_ComplexArray.h:219
tFFTWReal & operator()(const tUIndex &i, const tUSInt &j)
get the value for reading & writing
Definition: FFTW_ComplexArray.h:107
#define tUSInt
Definition: types.h:28
FFTW_ComplexArray & operator=(const FFTW_ComplexArray &s)
copy the values of the complex array
Definition: FFTW_ComplexArray.h:133
#define tBoolean
Definition: types.h:139
virtual ~FFTW_ComplexArray(void)
destroy an FFT complex array
Definition: FFTW_ComplexArray.cpp:22
#define tFFTWComplex
Definition: fftw_types.h:65
FFTW_ComplexArray & operator=(const CORE_DoubleArray &s)
copy only the real part to s
Definition: FFTW_ComplexArray.h:159
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:106
FFTW_ComplexArray(void)
create a FFT complex array
Definition: FFTW_ComplexArray.cpp:5
#define null
Definition: types.h:144
tBoolean setValuesByReference(const tUIndex &n, tFFTWComplex *array)
set the the values by reference
Definition: FFTW_ComplexArray.h:368
SP_OBJECT(FFTW_ComplexArray)
virtual tULLInt getMemorySize() const
return the memory size in byte
Definition: FFTW_ComplexArray.h:388
FFTW_ComplexArray & operator=(const tFFTWComplex &s)
init uniform value
Definition: FFTW_ComplexArray.h:184
FFTW_ComplexArray & operator=(const CORE_RealArray &s)
copy only the real part to s
Definition: FFTW_ComplexArray.h:151
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
void setValue(const tUIndex &index, const tFFTWReal &x, const tFFTWReal &y)
set the value at index
Definition: FFTW_ComplexArray.h:356
const tUIndex & getSize() const
get the size
Definition: FFTW_ComplexArray.h:406
void clear()
clear the vector
Definition: FFTW_ComplexArray.h:276
this class describes an array
Definition: CORE_Array.h:19
const tFFTWComplex * getValues() const
get values for reading only
Definition: FFTW_ComplexArray.h:394
tFFTWComplex & operator[](const tUIndex &i)
get the value for reading & writing
Definition: FFTW_ComplexArray.h:79
This class describes FFT complex array based on fft_complex structure.
Definition: FFTW_ComplexArray.h:17
This class is the base class of FFTW objects.
Definition: FFTW_Object.h:19
#define tUIndex
Definition: types.h:126
static SP::FFTW_ComplexArray New()
return a FFTW_ComplexArray shared pointer
Definition: FFTW_ComplexArray.h:64
void setSize(const tUIndex &n)
set size of the array
Definition: FFTW_ComplexArray.h:288
FFTW_ComplexArray & operator=(const CORE_FloatArray &s)
copy only the real part to s
Definition: FFTW_ComplexArray.h:167
tFFTWReal distance2(const FFTW_ComplexArray &x) const
compute the square of distance of this to x
Definition: FFTW_ComplexArray.cpp:596
tFFTWComplex * mValues
Definition: FFTW_ComplexArray.h:25
FFTW_ComplexArray & operator*=(const FFTW_ComplexArray &s)
make the product term by term
Definition: FFTW_ComplexArray.h:212
#define tString
Definition: types.h:135
tFFTWComplex * getValues()
get values for reading or writing
Definition: FFTW_ComplexArray.h:400
tUIndex mSize
Definition: FFTW_ComplexArray.h:28
tFFTWReal distance(const FFTW_ComplexArray &x) const
compute the distance of this to x
Definition: FFTW_ComplexArray.h:504
tFFTWReal fabs(tUIndex &i) const
compute the index of the array where the module is max
Definition: FFTW_ComplexArray.cpp:682
static void MatrixVectorProduct(const tFFTWReal &alpha, const tUIndex &N, const tFFTWComplex *A, const tFFTWComplex *X, tFFTWComplex *Y)
matrix vector product Z:=alpha.Z+A*X
Definition: FFTW_ComplexArray.cpp:418
FFTW_ComplexArray & operator=(const tFFTWReal &s)
init uniform value
Definition: FFTW_ComplexArray.h:176
tUIndex mCapacity
Definition: FFTW_ComplexArray.h:31
tFFTWReal norm() const
compute the norm
Definition: FFTW_ComplexArray.h:486
void initArray(const tReal &f)
init uniform value of f
Definition: FFTW_ComplexArray.cpp:126
#define tULLInt
Definition: types.h:45
virtual tString toString() const
to string
Definition: FFTW_ComplexArray.cpp:815
#define tFFTWReal
Definition: fftw_types.h:66
void desallocate()
desallocate the memory
Definition: FFTW_ComplexArray.cpp:27
#define tReal
Definition: types.h:118
void fitToSize()
set the capacityto size
Definition: FFTW_ComplexArray.cpp:118
void swap(const tUIndex &i, const tUIndex &j)
swap the lines i & j
Definition: FFTW_ComplexArray.h:422
FFTW_ComplexArray & operator*=(const tFFTWComplex &s)
multiply the array by s
Definition: FFTW_ComplexArray.h:201
FFTW_ComplexArray & operator*=(const tFFTWReal &s)
multiply the array by s
Definition: FFTW_ComplexArray.h:193
FFTW_ComplexArray & operator=(const CORE_ComplexArray &s)
copy the values of the tComplex array
Definition: FFTW_ComplexArray.h:141
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141
void add(const tFFTWReal &s)
add scalar s to the real part of the elements of the array
Definition: FFTW_ComplexArray.cpp:487
tFFTWReal norm2() const
compute the square of norm
Definition: FFTW_ComplexArray.cpp:572