22 #include <odindata/data.h>
23 #include <odindata/utils.h>
56 ComplexData(
const TinyVector<int,N_rank>& dimvec) :
Data<STD_complex,N_rank>(dimvec) {(*this)=STD_complex(0.0);}
65 ComplexData(
int extent1,
int extent2) :
Data<STD_complex,N_rank>(extent1,extent2) {}
66 ComplexData(
int extent1,
int extent2,
int extent3) :
Data<STD_complex,N_rank>(extent1,extent2,extent3) {}
67 ComplexData(
int extent1,
int extent2,
int extent3,
int extent4) :
Data<STD_complex,N_rank>(extent1,extent2,extent3,extent4) {}
68 ComplexData(
int extent1,
int extent2,
int extent3,
int extent4,
int extent5) :
Data<STD_complex,N_rank>(extent1,extent2,extent3,extent4,extent5) {}
87 #ifdef BLITZ_REPLACEMENT
92 ComplexData(
const Array<STD_complex,M_rank>& a) :
Data<STD_complex,N_rank>(a) {}
97 template<
class T_expr>
98 ComplexData(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr) :
Data<STD_complex,N_rank>(expr) {}
119 #ifdef BLITZ_REPLACEMENT
125 void reference(
const RectView<Array<STD_complex,M_rank>&,STD_complex,M_rank>& rhs) {
127 Array<STD_complex,N_rank>::reference(rhs);
133 template<
class T_expr>
155 void fft(
bool forward=
true,
bool cyclic_shift=
true);
164 void partial_fft(
const TinyVector<bool,N_rank>& do_fft,
bool forward=
true,
bool cyclic_shift=
true);
198 template <
int N_rank>
202 TinyVector<bool,N_rank> do_fft=
true;
211 struct GslFftWorkSpace;
217 void fft1d(
double* complex_data,
bool forward_fft);
225 template <
int N_rank>
229 TinyVector<int,N_rank> myshape(Array<STD_complex,N_rank>::shape());
235 for(
int irank=0; irank<N_rank; irank++) {
240 TinyVector<int,N_rank> indexvec;
241 for(
int irank=0; irank<N_rank; irank++) {
245 TinyVector<int,N_rank> ortho_shape(myshape);
246 ortho_shape(irank)=1;
248 int oneline_size=myshape(irank);
249 double *complex_data=
new double[2*oneline_size];
251 GslFft gslfft(oneline_size);
254 unsigned long n_ortho=product(ortho_shape);
255 ODINLOG(odinlog,normalDebug) <<
"oneline_size/irank/n_ortho=" << oneline_size <<
"/" << irank <<
"/" << n_ortho << STD_endl;
257 for(
unsigned long iortho=0; iortho<n_ortho; iortho++) {
258 indexvec=index2extent<N_rank>(ortho_shape,iortho);
260 for(
int j=0; j<oneline_size; j++) {
262 complex_data[2*j]= (*this)(indexvec).
real();
263 complex_data[2*j+1]=(*this)(indexvec).
imag();
266 gslfft.fft1d(complex_data, forward);
268 for(
int j=0; j<oneline_size; j++) {
270 float scale=1.0/sqrt(
double(oneline_size));
271 (*this)(indexvec)=scale*STD_complex(complex_data[2*j],complex_data[2*j+1]);
275 delete[] complex_data;
281 for(
int irank=0; irank<N_rank; irank++) {
283 ODINLOG(odinlog,normalDebug) <<
"Cyclic shift in dim=" << irank << STD_endl;
296 template <
int N_rank>
300 TinyVector<int, N_rank> index;
301 TinyVector<float, N_rank> findex;
302 for(
unsigned int i=0; i<Array<STD_complex,N_rank>::numElements(); i++) {
304 for(
int irank=0; irank<N_rank; irank++) findex(irank)=index(irank);
305 (*this)(index)*=expc(float2imag(-2.0*PII*sum(rel_offset*findex)));
311 template <
int N_rank>
315 unsigned int totalsize=Array<STD_complex,N_rank>::numElements();
316 TinyVector<int, N_rank> index;
318 for(
unsigned int i=0; i<totalsize; i++) {
321 for(
int idim=0; idim<N_rank; idim++) {
322 im+=-2.0*PII*(shiftvec(idim)*float(index(idim))/Array<STD_complex,N_rank>::extent(idim));
324 STD_complex
phase(0,im);
325 (*this)(index)*=exp(
phase);
337 template <
int N_rank>
342 TinyVector<int,N_rank> myshape(indata.shape());
345 TinyVector<int,N_rank> ortho_shape(myshape);
346 ortho_shape(N_rank-1)=1;
348 int nlast=myshape(N_rank-1);
352 TinyVector<int,N_rank> indexvec;
354 for(
int iortho=0; iortho<product(ortho_shape); iortho++) {
355 indexvec=index2extent<N_rank>(ortho_shape,iortho);
357 for(ilast=0; ilast<nlast; ilast++) {
358 indexvec(N_rank-1)=ilast;
359 phasevec(ilast)=
phase(indata(indexvec));
362 for(ilast=0; ilast<nlast; ilast++) {
363 indexvec(N_rank-1)=ilast;
364 result(indexvec)=unwrapped(ilast);
void partial_fft(const TinyVector< bool, N_rank > &do_fft, bool forward=true, bool cyclic_shift=true)
void modulate_offset(const TinyVector< float, N_rank > &rel_offset)
Data< float, N_rank > phasemap() const
ComplexData(const ComplexData< N_rank > &cd)
ComplexData(BZ_ETPARM(_bz_ArrayExpr< T_expr >) expr)
ComplexData< N_rank > & operator=(const ComplexData< N_rank > &d)
ComplexData(const TinyVector< int, N_rank > &dimvec)
void shift_subpixel(const TinyVector< float, N_rank > &shiftvec)
void fft(bool forward=true, bool cyclic_shift=true)
ComplexData(const Data< STD_complex, N_rank > &a)
Data< T, N_rank > & operator=(const Data< T, N_rank > &d)
void shift(unsigned int shift_dim, int shift)
TinyVector< int, N_rank > create_index(unsigned long index) const
Data< float, 1 > unwrap_phase(const Data< float, 1 > &phase, int startindex=0)
fvector phase(const cvector &cv)
fvector real(const cvector &cv)
fvector imag(const cvector &cv)