I have this view problem with plan_fft!,
Part of the code is below:
L = (128,16,16);
pad = 2;
data = rand(ComplexF32,128,16,16);
FFT_buffer = zeros(ComplexF32,128,32,32);
FFT_buffer[:,1:L,1:L] .= data;
I want to apply 1D FFT along second dimension in FFT_buffer, because I know half of the data in the second and third dimension are zero.
Therefore, I have created a FFTPlan to do 1D FFT along second dimension as below:
FFTPlan = plan_fft!(rand(ComplexF32,L,L,L.pad),2,flags=FFTW.MEASURE); # for size 12816*32
FFTPlan * view(FFT_buffer,:,1:L,:); # this doesn’t work
=> ERROR: ArgumentError: FFTW plan applied to wrong-strides array
FFTPlan * FFT_buffer[:,1:L,:] # this works but then it doesn’t update FFT_buffer file.
I have to do this to get it working
FFT_buffer[:,1:L,:] .= FFTPlan * FFT_buffer[:,1:L,:] ;
But then I am allocating the memory by doing this as shown below:
@time FFT_buffer[:,1:L,:] .= FFTPlan * FFT_buffer[:,1:L,:] ;
0.000603 seconds (22 allocations: 512.750 KiB)
I don’t want to reallocate memory again. I already have done the allocation in FFT_buffer file, I want to avoid any memory allocation now.
I could have avoided if view(FFT_buffer,:,1:L, had worked.
Does anyone have any idea how to avoid memory allocation here and use view in FFT_buffer to do such operation?
This is the part of my code, and it runs in the loop for many many iterations, that’s why I want to avoid this memory allocation.