You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Based on discussion at the end of issue ( #405 ), it would be nice to be able to not only use fft, but also fft2 and even fftn. Further it would be nice to have ifft2 and ifftn. Perhaps the real and Hermitian equivalents of these would be valuable as well. Though they would have to be limited to cases where one does not chunk along dimensions where the FFT is performed, this still includes many useful cases. One example use case for this is image registration.
I agree that this would be useful. We would probably have to check chunk shape to ensure that we have single-chunk dimensions everywhere where we want to call the fft function. Other than that this should hopefully just be a map_blocks call.
Are you interested in contributing here @jakirkham ?
The current implementation is a bit convoluted, but the core is fairly straightforward:
chunk_error= ("Dask array only supports taking an FFT along an axis that \n""has a single chunk. An FFT operation was tried on axis %s \n""which has chunks %s. To change the array's chunks use ""dask.Array.rechunk.")
deffunc(a, n=None, axis=-1):
iflen(a.chunks[axis]) !=1:
raiseValueError(chunk_error% (axis, a.chunks[axis]))
chunks=out_chunk_fn(a, n, axis)
returnmap_blocks(partial(fft_func, n=n, axis=axis), a, dtype=dtype,
chunks=chunks)
Check that the chunks of the input array are easy to map over, raise an informative error otherwise. Then just map the appropriate numpy function across the numpy blocks of the dask array.
FYI, I think I have taken another approach to perform multi-dimensional FFT on xarray objects using dask in xscale.spectral.fft.
See in particular the _fft function that loops on dimensions to successively perform 1D FFT and rechunk the arrays.
You might also consider to add a dask version of fftshiftifftshift. I have already made something similar in xscale.spectral.fft (see _fftshift and _ifftshift) if you are interested in.
One of the nice things about the proposed approach is it allows one to trivially wrap the NumPy FFT functions without significantly increasing the burden on the Dask code itself. The details of the FFT implementation remain in NumPy and the details of wrapping and exposing them remain in Dask. This also makes it easy for one to use a different external library with the same API (e.g. pyFFTW) and wrap it.
Including wrapped versions of the fftshift and ifftshift functions are good ideas. These shouldn't be too difficult. However, I don't plan to tackle them in this issue or associated PR. Have opened issue ( #2124 ) to outline that suggestion and some things to keep in mind when including them.
Activity
mrocklin commentedon Feb 13, 2017
I agree that this would be useful. We would probably have to check chunk shape to ensure that we have single-chunk dimensions everywhere where we want to call the fft function. Other than that this should hopefully just be a map_blocks call.
Are you interested in contributing here @jakirkham ?
jakirkham commentedon Feb 13, 2017
Quite likely as I'm hoping to use it. 😄 Just a matter of when I have time to do so.
mrocklin commentedon Feb 13, 2017
The current implementation is a bit convoluted, but the core is fairly straightforward:
Check that the chunks of the input array are easy to map over, raise an informative error otherwise. Then just map the appropriate numpy function across the numpy blocks of the dask array.
[-]Multidimension FFTs[/-][+]Multidimensional FFTs[/+]jakirkham commentedon Mar 22, 2017
FWIW am working on something to do this. Hoping to have a PR at least by week's end if not sooner depending on other demands.
mrocklin commentedon Mar 22, 2017
jakirkham commentedon Mar 22, 2017
I guess getting it done sooner was possible. Please take a look at PR ( #2116 ) when you have a chance.
serazing commentedon Mar 23, 2017
FYI, I think I have taken another approach to perform multi-dimensional FFT on
xarrayobjects usingdaskin xscale.spectral.fft.See in particular the
_fftfunction that loops on dimensions to successively perform 1D FFT and rechunk the arrays.You might also consider to add a dask version of
fftshiftifftshift. I have already made something similar inxscale.spectral.fft(see_fftshiftand_ifftshift) if you are interested in.jakirkham commentedon Mar 27, 2017
Thanks for the feedback @serazing.
One of the nice things about the proposed approach is it allows one to trivially wrap the NumPy FFT functions without significantly increasing the burden on the Dask code itself. The details of the FFT implementation remain in NumPy and the details of wrapping and exposing them remain in Dask. This also makes it easy for one to use a different external library with the same API (e.g. pyFFTW) and wrap it.
Including wrapped versions of the
fftshiftandifftshiftfunctions are good ideas. These shouldn't be too difficult. However, I don't plan to tackle them in this issue or associated PR. Have opened issue ( #2124 ) to outline that suggestion and some things to keep in mind when including them.jakirkham commentedon May 10, 2017
FYI this has been addressed in PR ( #2321 ).