Skip to content

Multidimensional FFTs #1980

Closed
Closed

Description

@jakirkham

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.

Activity

  1. mrocklin commented on Feb 13, 2017

    @mrocklin
    Member

    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 ?

  2. jakirkham commented on Feb 13, 2017

    @jakirkham
    MemberAuthor

    Quite likely as I'm hoping to use it. 😄 Just a matter of when I have time to do so.

  3. mrocklin commented on Feb 13, 2017

    @mrocklin
    Member

    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.")
    
        def func(a, n=None, axis=-1):
            if len(a.chunks[axis]) != 1:
                raise ValueError(chunk_error % (axis, a.chunks[axis]))
    
            chunks = out_chunk_fn(a, n, axis)
    
            return map_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.

  4. changed the title [-]Multidimension FFTs[/-] [+]Multidimensional FFTs[/+] on Feb 13, 2017
  5. jakirkham commented on Mar 22, 2017

    @jakirkham
    MemberAuthor

    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.

  6. mrocklin commented on Mar 22, 2017

    @mrocklin
    Member
  7. jakirkham commented on Mar 22, 2017

    @jakirkham
    MemberAuthor

    I guess getting it done sooner was possible. Please take a look at PR ( #2116 ) when you have a chance.

  8. serazing commented on Mar 23, 2017

    @serazing

    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 fftshift ifftshift. I have already made something similar in xscale.spectral.fft (see _fftshift and _ifftshift) if you are interested in.

  9. jakirkham commented on Mar 27, 2017

    @jakirkham
    MemberAuthor

    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 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.

  10. jakirkham commented on May 10, 2017

    @jakirkham
    MemberAuthor

    You might also consider to add a dask version of fftshift ifftshift.

    FYI this has been addressed in PR ( #2321 ).

  11. added this to the 0.14.2 milestone on May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions