Skip to content

Add dask.array.fft - #522

Merged
mrocklin merged 18 commits into
dask:masterfrom
cowlicks:gh-405
Aug 6, 2015
Merged

mrocklin merged 18 commits into
dask:masterfrom
cowlicks:gh-405

Conversation

@cowlicks

@cowlicks cowlicks commented Aug 4, 2015

Copy link
Copy Markdown
Member

This adds dask.array.fft and dask.array.ifft, which only work along axes that are not chunked.

Some potential todo's:

If these seem pressing or mildly important, I'll do them.

Docstrings are mostly copied from numpy.

Also note that I wrote the tests in the idiomatic unittest way. I have been more fond of unittest lately since its invocation time is so much faster than py.test. And it is in the stdlib.

Partially closes #405

@mrocklin

mrocklin commented Aug 4, 2015

Copy link
Copy Markdown
Member

Note that nosetests supports bare function testing and spins up quite quickly.

Comment thread dask/array/fft.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should point users to rechunk or ask them to specify chunks differently when they create their array, perhaps giving a small example. The phrase "indexing along an axis" isn't immediately clear to me. I would stay away from using FFT as a verb. Crafting this error message is probably one of the more important parts of this PR. Given that it will be used fairly often we might want to construct it separately.

@mrocklin

mrocklin commented Aug 4, 2015

Copy link
Copy Markdown
Member

I'll say that these don't seem pressing but have come up enough to be mildly important. Given how cheap it seems to be to wrap things it might be worth going ahead with the rest of the module.

@cowlicks

cowlicks commented Aug 5, 2015

Copy link
Copy Markdown
Member Author

This now includes all the 1D FFT's from NumPy. However real and hermitian FFTs can mutate the size of the output, I'm working on accounting for this.

@cowlicks

cowlicks commented Aug 5, 2015

Copy link
Copy Markdown
Member Author

I need to add info about the n kwarg to the docstrings.

@cowlicks

cowlicks commented Aug 5, 2015

Copy link
Copy Markdown
Member Author

Ready for review.

Comment thread dask/array/tests/test_fft.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For brevity's sake I wonder if these can be made more compact. This might make it a bit easier to visually check

assert eq(fft(self.darr), npfft.fft(self.nparr))
assert eq(fft(self.darr2, axis=0), npfft.fft(self.nparr, axis=0))

@mrocklin

mrocklin commented Aug 5, 2015

Copy link
Copy Markdown
Member

The general approach looks good. I suggest trying to reduce the amount of boiler plate in the following ways.

  1. Use the docstrings of the numpy methods directly, e.g.
def fftx(...):
    """ a few small words about chunking

    The main docstring follows below
    """ + np.fft.fftx.__doc__
    ...

This helps reduce the amount of boiler plate and also stops us from having to include the NumPy license in our codebase.

  1. I'm a bit hesitant about using unittest.TestCase objects. It's a different style than what is found throughout the rest of the library. You've brought up the concern about pytest adding a bit of testing overhead. Are you able to write the tests in bare function way that is compatible with both pytest and nosetests? Nose is much simpler than pytest and doesn't have the same overhead. This might also make some of the other dask developers happy.
  2. I gave an example of squishing down the tests inline. This would make it easier to review.

@jcrist

jcrist commented Aug 5, 2015

Copy link
Copy Markdown
Member

This might also make some of the other dask developers happy.

I really don't like classes for test cases, and would vastly prefer keeping the same style as pytest/nosetest. Thoroughly agree with Matt above.

@shoyer

shoyer commented Aug 5, 2015

Copy link
Copy Markdown
Member

stops us from having to include the NumPy license in our codebase

That ship has already sailed, I'm afraid:
https://github.com/ContinuumIO/dask/blob/master/dask/array/chunk.py#L174-L203

@cowlicks

cowlicks commented Aug 5, 2015

Copy link
Copy Markdown
Member Author

In-lined tests, switched to bare tests, and replaced copied docs with fft.__doc__ methods. Anything else?

Comment thread dask/array/__init__.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like numpy doesn't import this

In [13]: np.fft
Out[13]: <module 'numpy.fft' from '/home/mrocklin/Software/anaconda/lib/python2.7/site-packages/numpy/fft/__init__.pyc'>

In [14]: da.fft
Out[14]: <function dask.array.fft.fft>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the modules name is fft.py, renaming suggestions? NumPy uses fftpack.py.

fft_module.py? fft_.py?

I also forgot to import the other functions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we left this import line off wouldn't da.fft just be a module from which we could then call da.fft.fft?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed that works. Done.

Comment thread dask/array/fft.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if its possible to manage this with just a single preamble that warned about chunking. We could then leave all of the function specific stuff to the numpy docstring.

@cowlicks

cowlicks commented Aug 5, 2015

Copy link
Copy Markdown
Member Author

Travis-CI failed because one of NumPy's doctests. Fun.

@mrocklin

mrocklin commented Aug 5, 2015

Copy link
Copy Markdown
Member

Ugh.

@cowlicks

cowlicks commented Aug 6, 2015

Copy link
Copy Markdown
Member Author

Consolidated the docstrings. And doctests in fft.py are now ignored. Thanks for the comments, they cut this PR down from 510 LOC to 235. Let me know if there is anything else.

@mrocklin

mrocklin commented Aug 6, 2015

Copy link
Copy Markdown
Member

One last bit, I think you need to add fft to this line in dask/array/__init__.py

from . import random, linalg, ghost, learn, fft

This makes it so that the following works

In [1]: import dask.array as da

In [2]: da.fft.
da.fft.absolute_import  da.fft.hfft             da.fft.map_blocks
da.fft.chunk_error      da.fft.ifft             da.fft.np
da.fft.fft              da.fft.ihfft            da.fft.npfft
da.fft.fft_preamble     da.fft.irfft            da.fft.rfft

In [2]: da.fft.hfft
Out[2]: <function dask.array.fft.hfft>

@mrocklin

mrocklin commented Aug 6, 2015

Copy link
Copy Markdown
Member

after that I'm +1

@cowlicks

cowlicks commented Aug 6, 2015

Copy link
Copy Markdown
Member Author

@mrocklin done

mrocklin added a commit that referenced this pull request Aug 6, 2015
@mrocklin
mrocklin merged commit 43804a7 into dask:master Aug 6, 2015
phofl pushed a commit to phofl/dask that referenced this pull request Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement numpy.fft functionality

4 participants