Blame view

stim/math/fft.h 1.1 KB
3a74ec6d   David Mayerich   added a new scala...
1
2
3
4
5
  #ifndef STIM_FFT_H
  #define STIM_FFT_H
  
  namespace stim{
  
963d0676   David Mayerich   bug fixes related...
6
  	/*template<class T>
3a74ec6d   David Mayerich   added a new scala...
7
8
9
10
11
12
13
14
15
  	void circshift(T *out, const T *in, size_t xdim, size_t ydim, size_t xshift, size_t yshift){
  		size_t i, j, ii, jj;
  		for (i =0; i < xdim; i++) {
  			ii = (i + xshift) % xdim;
  			for (j = 0; j < ydim; j++) {
  				jj = (j + yshift) % ydim;
  				out[ii * ydim + jj] = in[i * ydim + j];
  			}
  		}
963d0676   David Mayerich   bug fixes related...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  	}*/
  
  	template<typename T>
  	void circshift(T *out, const T *in, int xdim, int ydim, int xshift, int yshift)
  	{
  	 for (int i =0; i < xdim; i++) {
  	   int ii = (i + xshift) % xdim;
  	   if (ii<0) ii = xdim + ii;
  	   for (int j = 0; j < ydim; j++) {
  	     int jj = (j + yshift) % ydim;
  	     if (jj<0) jj = ydim + jj;
  	     //out[ii * ydim + jj] = in[i * ydim + j];
  	     out[jj * xdim + ii] = in[j * xdim + i];
  	   }
  	 }
3a74ec6d   David Mayerich   added a new scala...
31
32
33
34
  	}
  
  	template<typename T>
  	void cpu_fftshift(T* out, T* in, size_t xdim, size_t ydim){
963d0676   David Mayerich   bug fixes related...
35
  		circshift(out, in, xdim, ydim, std::floor(xdim/2), std::floor(ydim/2));
3a74ec6d   David Mayerich   added a new scala...
36
37
38
39
  	}
  
  	template<typename T>
  	void cpu_ifftshift(T* out, T* in, size_t xdim, size_t ydim){
963d0676   David Mayerich   bug fixes related...
40
  		circshift(out, in, xdim, ydim, std::ceil(xdim/2), std::ceil(ydim/2));
3a74ec6d   David Mayerich   added a new scala...
41
42
43
44
45
46
  	}
  
  
  }
  
  #endif