20 #include <tensor/fftw.h>
25 fftshift(
const CTensor& input,
int direction) {
27 CTensor output(input);
28 for (index dim = 0; dim < input.rank(); dim++) {
29 output = fftshift(output, dim, direction);
36 fftshift(
const CTensor& input, index dim,
int direction) {
37 assert(dim >= 0 && dim < input.rank());
46 for (index i = 0; i < dim; i++) {
51 for (index i = dim+1; i < size.size(); i++) {
58 CTensor output(before, size[dim], after);
59 const CTensor reshape_input =
reshape(input, output.dimensions());
62 index minfreq = size[dim]/2;
63 index Nhalf = size[dim]/2;
64 index end = size[dim]-1;
66 if (size[dim] % 2 == 1) {
67 minfreq = (size[dim]+1)/2;
68 Nhalf = (size[dim]-1)/2;
69 if (direction == FFTW_BACKWARD) {
76 output.at(range(), range(0,Nhalf-1), range()) = reshape_input(range(), range(minfreq,end), range());
77 output.at(range(), range(Nhalf, end), range()) = reshape_input(range(), range(0, minfreq-1), range());
83 fftshift(
const CTensor& input,
const Booleans& convert,
int direction) {
84 assert(input.rank() == convert.size());
86 CTensor output(input);
87 for (index dim = 0; dim < input.rank(); dim++) {
89 output = fftshift(output, dim, direction);
const RTensor reshape(const RTensor &t, const Indices &new_dims)
Return a RTensor with same data and given dimensions.
const Indices & dimensions() const
Return Tensor dimensions.