InPlace FFT Plan and view

Welcome AmarjeetK,
let me try to help. I think what you want is this:

using FFTW

L = (128,16,16);
pad = 2;

data = rand(ComplexF32,128,16,16);
FFT_buffer = zeros(ComplexF32,128,32,32);

FFT_buffer[:,1:L[2],1:L[3]] .= data;
FFT_buffer_copy = deepcopy(FFT_buffer);

FFT_bufferview=view(FFT_buffer,1:L[1],1:L[2],1:L[3]*pad)
FFTPlan = plan_fft!(FFT_bufferview,2,flags=FFTW.MEASURE);

@time FFTPlan*FFT_bufferview #gives 0 allocations (on the second evaluation)

FFT_buffer==FFT_buffer_copy #gives false, as FFT_buffer is mutated

If you don’t like the view syntax, you can also use the macro

@views X[1:n,1:m,1:l] .= XXX
#is equivalent to
view(X,1:n,1:m,1:l) .= XXX

I hope this is what you wanted! Also, check out Please read: make it easier to help you - #103 to see how you can highlight code snippets :wink:

1 Like