Blame view

stim/math/fft.h 1.1 KB
 ```1 2 3 4 5``` `````` #ifndef STIM_FFT_H #define STIM_FFT_H namespace stim{ `````` `6` `````` /*template `````` ```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]; } } `````` ```16 17 18 19 20 21 22 23 24 25 26 27 28 29 30``` `````` }*/ template 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]; } } `````` ```31 32 33 34``` `````` } template void cpu_fftshift(T* out, T* in, size_t xdim, size_t ydim){ `````` `35` `````` circshift(out, in, xdim, ydim, std::floor(xdim/2), std::floor(ydim/2)); `````` ```36 37 38 39``` `````` } template void cpu_ifftshift(T* out, T* in, size_t xdim, size_t ydim){ `````` `40` `````` circshift(out, in, xdim, ydim, std::ceil(xdim/2), std::ceil(ydim/2)); `````` ```41 42 43 44 45 46``` `````` } } #endif ``````