Skip to content

Abstract FFT interface - #2093

Merged
mrocklin merged 28 commits into
dask:masterfrom
jakirkham:abstract_fft_interface
Mar 21, 2017
Merged

mrocklin merged 28 commits into
dask:masterfrom
jakirkham:abstract_fft_interface

Conversation

@jakirkham

Copy link
Copy Markdown
Member

Fixes #2092

Provides wrappers for things that implement the standard FFT interface like that of NumPy. Recasts the existing FFT interface with these wrappers. Also adds some tests that exercise this wrapping with NumPy and SciPy.

Change `_fft_wrap` to delay function specification. The goal being one
can create custom wrappers for different external FFT implementations.
This both keeps Dask flexible in the area of FFTs without necessarily
adding many implementations.
Create public API FFT wrapper functions and make use of them to wrap the
exist NumPy FFTPACK interface used by Dask. Also provide some brief
explanation of how this API works in the docstrings.
Even though we are already doing this wrapping internally in Dask and
implicitly testing. We should make sure explicitly that it works in case
the implementation in Dask changes in the future.
As another exercise of the wrappers, test wrapping SciPy's FFTPACK to
make sure our wrappers apply just as well to it.
Comment thread dask/array/fft.py Outdated
takes a function that behaves like ``numpy.fft.ihfft``.
"""

return _fft_wrap(np.complex_, _ihfft_out_chunks)(fft_func)

@jcrist jcrist Mar 16, 2017 •

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.

Perhaps instead of defining a new wrapper for each type, define a single function that dispatches on the type? Something like:

ifft = fft_wrapper(npfft.ifft, kind='ifft')  # Could maybe use a better keyword name
hfft = fft_wrapper(npfft.hfft, kind='hfft')
...

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.

I'm 50/50 on it. What's the disadvantage of the current form?

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.

Just a lot of functions. I'm slightly in favor of a smaller public interface and a more concise implementation. Not a big deal though, current way is fine as well.

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.

Well, I'm planning to add the 2-D and N-D versions of these too. So as long as we don't think that this will make the function too long with such a big branch that is fine. Though some linting tools may balk at this.

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'm also in favor of fewer functions here if we can manage it. It makes it easier to maintain and change in the future if need arises.

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.

Ok.

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.

Done.

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

ifft = ifft_wrapper(spfft.ifft)
assert_eq(ifft(darr), spfft.ifft(nparr))
assert_eq(ifft(darr2, axis=0), spfft.ifft(nparr, axis=0))

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.

As SciPy doesn't have hfft or ihfft, we can't wrap those.

Also they implement rfft and irfft, but how they handle the data is a bit strange. Instead of returning or taking complex values all of these functions return real values that split the imaginary part from the real part. So wrapping them would be kind of a pain as we would have to massage the data back into the expected form in the wrapper.

ref: https://docs.scipy.org/doc/scipy-0.19.0/reference/generated/scipy.fftpack.rfft.html

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.

Perhaps it doesn't matter as long as fft_wrap ensures that the dask.array version is consistent with whatever function it is passed. We don't need to test against numpy, we just need to test against the function that we were given.

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.

So I think it is worth testing that the computation is correct. Otherwise we have no idea whether the wrapper is behaving correctly from the test side.

@jakirkham

Copy link
Copy Markdown
Member Author

Given you wrote the original implementation, @cowlicks, it would be good to hear your feedback on this.

Comment thread dask/array/tests/test_fft.py Outdated
assert not same_keys(fft(darr, 5), fft(darr, 13))


def test_wrap_numpy():

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.

Can we refactor this to use pytest.mark.parametrize? This might make it easier to extend in the future.

@pytest.mark.parametrize('module', [np.fft, scipy.fft])
@pytest.mark.parametrize('funcname', ['fft', 'ifft', 'rfft', ...])
def test_wrapper(module, funcname):
    try:
        func = getattr(module, funcname)
    except AttributeError:
        pytest.mark.skip()
    dfft = fft_wrapper(module, funcname)
    assert_eq(fft(nparr), dfft(darr))

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.

Also I have a slight preference to use names like x and dx rather than nparr. These names were probably from before, but this refactor might be a nice chance to rename them.

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.

Can we refactor this to use pytest.mark.parametrize?

Probably to some extent. Though I don't think we can lump everything into one test. Please see this note.

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.

Is the PyFFTW library consistent with the numpy interface?

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.

These other variables were already defined and use in the other tests. I used them to be consistent and to ensure the wrappers were doing the correct thing. I would like to keep this change focused on the task at hand.

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 don't know what the legality is when you're testing against other code.

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.

IANAL. That said, my understanding was as long as the GPL dependencies are optional and are not shipped with the distribution, this should not effect licensing. This SO answer seems pertinent.

Note: FFTW is GPL 2.

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.

That being said, if you would rather steer clear, I'm ok with that. It is part of the reason I designed these to be user accessible wrappers as opposed to discussing optional FFTW support. 😄

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.

Have parameterized the tests. Have not done anything with pyFFTW. We can save that for a follow-up PR.

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.

FWIW here is a PR ( #2105 ) that tests against pyFFTW. Though feel free to accept or decline the patch as you see fit.

Comment thread dask/array/fft.py Outdated
return map_blocks(partial(fft_func, n=n, axis=axis), a, dtype=dtype,
chunks=chunks)
return map_blocks(partial(fft_func, n=n, axis=axis), a, dtype=dtype,
chunks=chunks)

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 is useful to avoid partial. map_blocks can accept keyword arguments, I recommend the following:

map_blocks(fft_func, a, n=n, axis=axis, dtype=dtype, chunks=chunks)

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 line was already here. I have merely indented it. While there may be improvements that can be made to this function, I'd like to keep this change compact.

@cowlicks

Copy link
Copy Markdown
Member

👋 @jakirkham I haven't touched dask in a while, so I'll defer to @mrocklin and @jcrist cheers!

Instead of having a variety `*fft_wrapper` functions, simply provide one
`fft_wrapper` function that takes a specification as to the kind of FFT
function that is being wrapped.
@jakirkham
jakirkham force-pushed the abstract_fft_interface branch 2 times, most recently from 07ac953 to f675878 Compare March 17, 2017 15:33
@jakirkham

Copy link
Copy Markdown
Member Author

Ok, I think I have addressed the concerns raised with this patch. Would appreciate another review.

Comment thread dask/array/fft.py Outdated
elif kind == "hfft":
return _fft_wrap(np.float_, _hfft_out_chunks)(fft_func)
elif kind == "ihfft":
return _fft_wrap(np.complex_, _ihfft_out_chunks)(fft_func)

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.

Would be nice to raise a ValueError in case the kind is unknown.

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.

In the spirit of keeping code as data when possible, I recommend creating a dict like

{'fft': _fft_out_chunks,
 'ifft': _fft_out_chunk, # also should this be ifft?
 ....
}

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.

I recommend creating a dict like

We could do that. So a different dict for type too?

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.

Would be nice to raise a ValueError in case the kind is unknown.

Handled and added a test.

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.

I recommend creating a dict

Also done. Made a dict with the parameters so they can be passed as kwargs.

Comment thread dask/array/tests/test_fft.py Outdated
try:
func = getattr(fft_mod, funcname)
except AttributeError:
raise SkipTest()

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.

Use pytest.skip('fft method missing') # or a better message here instead of raising SkipTest

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.

Ok, not super familiar with pytest. So thanks for the pointer. Will update.

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.

Done.

@jcrist

jcrist commented Mar 17, 2017

Copy link
Copy Markdown
Member

Other than my comments above, this looks good to me. Thanks for the fix @jakirkham.

Comment thread dask/array/fft.py Outdated
def func(a, n=None, axis=-1):
if len(a.chunks[axis]) != 1:
raise ValueError(chunk_error % (axis, a.chunks[axis]))
def _fft_wrap(dtype, out_chunk_fn):

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.

Can we auto-detect the dtype by calling the function on a length zero array? Actually, we may be able to just ignore the dtype argument altogether and let map_blocks take care of this (it will call the function on a length one array of the input array's dtype?

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 know the dtype ahead of time, I don't see a good reason not to provide that information statically if it's cheap to do.

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.

OK

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.

I do like your idea about detecting type better, @mrocklin. Let me give that some more thought.

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.

In the past, I have not seen a great way to go from float* to complex* that preserves precision (e.g. float32 to complex64). So have wound up handling this myself. I think from complex* to float* this should be easier (e.g. take real of 0 or similar), but the other way around ends up being kind of ugly.

To cutdown on the amount of boilerplate in the tests, use
`pytest.mark.parametrize` so as to cycle through many different
combinations. This should keep the code small while allowing us to try
various combinations of NumPy and SciPy FFT functions with the wrappers.
@jakirkham
jakirkham force-pushed the abstract_fft_interface branch from f675878 to c1b8f41 Compare March 17, 2017 19:33
If an unknown kind is provided to `fft_wrapper`, raise a `ValueError`
explaining that this happened.
To simplify passing parameters to the wrapper, create a dictionary that
has all of the parameters for each supported kind so that they can be
easily passed through.
Explain the function's expected API more clearly. Also note the
supported kinds of functions that can be wrapped and how they should be
specified.
@jakirkham
jakirkham force-pushed the abstract_fft_interface branch from 3711e60 to 68538ab Compare March 17, 2017 19:56
Combine the remaining NumPy tests into the single parameterized test for
FFT wrappers. Also as SciPy's FFTPACK implements `rfft` and `irfft` in
ways that are not compatible with NumPy's API, skip testing the wrapping
of the functions and note why they are skipped. Should keep testing
relatively straightforward.
@jakirkham

Copy link
Copy Markdown
Member Author

Thanks for the follow-up comments. I think I have addressed everything raised. Would appreciate another look.

Comment thread dask/array/fft.py Outdated
"dtype": np.complex_,
"out_chunk_fn" : _ihfft_out_chunks
},
}

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.

The intent behind the data comment is to keep this data outside of functions. That way it can be used by other functions as well.

dtypes = {'fft: ...}
funcs = {'fft': ...

def func(name, ...):
    dtype = dtypes[name]
    chunk_func = funcs[name]

Comment thread dask/array/tests/test_fft.py Outdated
"`%s` function `%s` doesn't support the NumPy API." % (
modname, funcname
)
)

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.

Would the AttributeError check above nt cover this?

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.

No because as noted in this comment rfft and irfft do exist in SciPy, but they format data in a totally different way than NumPy's rfft and irfft. So we have to massage it into a usable format if we want to test wrapping this function. Not sure it is worth it IMHO.

Determines the unknown `dtype` based on using a dummy array of the same
`dtype` as that of the array provided. That way, we are sure it should
match the result's `dtype` accurately based on the type we are provided.
Seems the closure doesn't bind the argument from the outer scope
function. So hack around this issue by storing it to a variable that is
local to the outer function and then copy it over to the inner function.
Despite being quite ugly, this does seem to work correctly.
To make sure types are properly handled throughout, try converting the
data to single and double precision before proceeding.
Was using `assert_eq`, which is geared for arrays. So fixed this to do a
simple equal comparison in an `assert`.
Just to make sure the correct shape is computed for the Dask array, add
a test that verifies that the shape of the Dask after the FFT matches
that of the actual result.
Comment thread dask/array/tests/test_fft.py Outdated

wfunc = fft_wrap(func)
assert wfunc(darrc).dtype == func(nparrc).dtype
assert wfunc(darrc).shape == func(nparrc).shape

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.

The assert_eq function already does this (or if it doesn't, then this fix should go there)

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.

Ok, well I just noticed that this caused a failure as I'm seeing shape mismatches with *rfft on SciPy. This actually doesn't surprise me as SciPy's functions preserve the original array's shape (up to n). However, NumPy's *rffts don't.

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.

OK, so I guess this gets back to your original question about if we should support scipy rfft functions, and, if not, how to exclude them. It seems like the current chunk_fn for rfft is specific to numpy. Do we always ask the user to provide a chunk function of their own?

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.

So I looked at the comparison code and it is checking the shapes, but only after computing the dask arrays. The problem is the shape of the dask is wrong, but the shape of the computed result is correct. Can add a PR to compare these too. Though testing that case may prove tricky.

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.

PR ( #2101 ) should fix assert_eq to test the shapes before computation, but it looks like it will expose some existing issues. Not sure if I will have time to fix them all though.

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.

Ah sorry GitHub hid your previous comment. Well one thing to consider (and this might be the right way to fix it) is SciPy and NumPy provide different return types (real or complex). So the chunking function could take the return type as an argument and infer what to do.

Pass around the expected result type of the functions to all of the
chunking operations. Use this information to determine the proper chunk
sizes particularly for functions like `rfft` and `irfft`, which differ
between NumPy and SciPy. However this comes with one caveat, `irfft`
will be dispatched according to whether the data is complex (NumPy) or
real (SciPy).
Comment thread dask/array/fft.py Outdated
if issubclass(np.dtype(rtype).type, numbers.Real):
chunks[axis] = (n,)
else:
chunks[axis] = (n // 2 + 1,)

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.

Is this code tailored exactly to the numpy and scipy conventions or is there something deeper going on here?

If we're just reverse engineering the scipy conventions into these functions then it might be better to just include these as separate functions.

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.

SciPy's rfft always returns a real array. NumPy's rfft always returns a complex array. These are documented as such in their respective APIs. So this isn't mysterious. We are just leveraging these known differences.

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.

Is it reasonable for someone to come in with a new fft module and it return a complex dtype but not follow scipy's shape scheme? My question is "are we using dtype to infer which module this is coming from?" If so then we should probably just condition on the module itself rather than back out which module is being used based on what is happening to the dtype.

Taking a step back, is there a way to better handle the shape business here? This all seems somewhat convoluted.

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.

I guess, but why? If someone did this, it sort of raises the question of did they understand the purpose of SciPy's API at all. The point was to guarantee real values, keep the same shape, and make it easy to invert later. Making all of the values complex makes the array twice as large, but does not add any value as the imaginary parts will all be zero.

That all said, I can't exactly disagree with you. Trying to handle the SciPy *rfft functions is pretty messy and TBH am really not sold on their benefit. They have a few neat tricks, but nothing that really justifies to me why I would want to look at my data in that way instead of an array of complex values.

In short, I'm coming back to the viewpoint that I had when I last looked at this Friday. Namely let's not bother to support the SciPy *rfft functions. If someone wants to try later, we have made their job much easier with work done in this PR. Plus we have already opened the door to people wanting the other SciPy FFT functions or using pyFFTW, which is going to help anyone wanting some extra speed to get it easily with Dask.

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 don't actually care about this specific situation of complex dtypes. My question was intended to reinforce this main point:

My question is "are we using dtype to infer which module this is coming from?" If so then we should probably just condition on the module itself rather than back out which module is being used based on what is happening to the dtype

I'm ok not supporting scipy functions. But we need to actively err here, not just avoid testing them.

Generally the goal of this PR appears to be "allow people to come in with their own fft modules". I guess that the scipy case shows that we can't assume that the "chunk" functions are general.

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.

Ok, let's move towards erroring out if people use SciPy's *rfft functions then.

FWIW other people think SciPy's *rfft behavior here is weird and are trying to get rid of it.

xref: scipy/scipy#2487

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.

Have added a ValueError for those specific SciPy functions and added tests that cover it. Also have reverted all of the special dtype handling code.

Comment thread dask/array/fft.py Outdated
if issubclass(a.dtype.type, numbers.Real):
chunks[axis] = (n,)
else:
chunks[axis] = (2 * (n - 1),)

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.

Though if there was one that felt funny, this might be it. We are relying on the type to be the correct type for the irfft function we are working with. So if the input array is real, we assume we are dealing with SciPy's irfft. However, if the input array is complex, we are assuming we are dealing with NumPy's irfft. However, NumPy's irfft can take real values in addition to complex ones; whereas, SciPy's irfft can only take real values. I'm not sure if I like it much. It might be ok if documented, but it does allow the user to make a potentially painful mistake.

@jakirkham

Copy link
Copy Markdown
Member Author

Alright, I think this is ready for another look. Please let me know your thoughts.

Comment thread dask/array/tests/test_fft.py Outdated
if modname == "scipy.fftpack":
if "rfft" in funcname:
with pytest.raises(ValueError):
wfunc = fft_wrap(func)

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.

These two if statements should be merged into one line. Currently you don't test any of the scipy functions except rfft

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.

Yep, sorry, have merged the ifs.

@jakirkham
jakirkham force-pushed the abstract_fft_interface branch from bcca5af to 45c74a0 Compare March 21, 2017 14:09
@jakirkham
jakirkham force-pushed the abstract_fft_interface branch from 45c74a0 to b7141eb Compare March 21, 2017 14:21
@jakirkham

Copy link
Copy Markdown
Member Author

Made the last tweak and this is now passing. Please let me know if there is anything else.

@mrocklin
mrocklin merged commit 53bba35 into dask:master Mar 21, 2017
@mrocklin

Copy link
Copy Markdown
Member

Thanks for following through on this @jakirkham . Merged.

@jakirkham

Copy link
Copy Markdown
Member Author

Thanks for all the feedback and help getting this together.

@jakirkham
jakirkham deleted the abstract_fft_interface branch March 21, 2017 16:53
Comment thread dask/array/fft.py
np_name = fft_func.__name__
if fft_func.__doc__ is not None:
func.__doc__ = (fft_preamble % (np_name, np_name)) + fft_func.__doc__
func.__name__ = np_name

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.

Missed fixing the docstring for these wrappers to note that these functions could from different locations. Change was made in PR ( #2110 ).


if modname == "scipy.fftpack" and "rfft" in funcname:
with pytest.raises(ValueError):
wfunc = fft_wrap(func)

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.

Forgot that this wfunc wasn't doing anything here. So added PR ( #2114 ) to drop the variable assignment since it is unneeded.

@Jeitan

Jeitan commented Mar 27, 2017 •

Copy link
Copy Markdown

I just ran across this and I have a question from a user's perspective, not being familiar with the guts.... but it looks like the scipy FFTs wrapped here are going to use numpy ffts? If so I'd like to point a couple things out:

I am often taking FFTs of large datasets, and I have observed that the fft implementations out of scipy.fftpack are significantly better at memory handling than the ones out of numpy.fft. I've profiled them to very small timesteps and I can catch the numpy FFT with as much as 8 or 16x the memory of the original array (mid-computation), whereas the scipy FFT only uses something like 2 or 4x. Also, the numpy fft doesn't appear to give back all the memory after it is done.

I would very much like to get all my FFTS from one place (I currently have to use the rfftn from numpy, for example), but I don't want to lose wherever the memory advantages of scipy.fftpack are coming from.

@jakirkham

Copy link
Copy Markdown
Member Author

I think you are misunderstanding the change, @Jeitan, which is totally understandable as it is in the guts of the library as you say.

Before what happened was Dask wrapped up NumPy's 1-D FFT API and let one use that with Dask Arrays. However there was no easy way to sub in an alternative library like SciPy's FFTPACK or pyFFTW to use with Dask. The functions used to do the wrapping were part of the internal or private API. All we did here was clean up the main wrapping function and expose it in the public API. Dask otherwise still provides the same functions as it did before. This allows you to wrap other FFT functions too as long as they conform to the NumPy API. So you could easily wrap SciPy's FFTPACK (with the exception of rfft and irfft).* In fact we actually test wrapping these SciPy functions in Dask.

In short, this change should make it easier to explore FFTs from other libraries (like SciPy's) not harder. If you find that to be otherwise, would be curious to hear more about how and why.

* SciPy's FFTPACK functions largely conform to the NumPy API with the notable exceptions of rfft and irfft, which do not. There is a lot of history behind this and some discussion about removing/fixing these differences. ( scipy/scipy#2487 ). One might be able to wrap the SciPy [i]rfft functions using some tricks in a wrapper function and then use them with Dask.

@Jeitan

Jeitan commented Mar 28, 2017

Copy link
Copy Markdown

Ahhhhh, I see @jakirkham, thank you for the explanation! Yes I've been following the rfft discussion, to see how that all unfolds (again as an interested user rather than a dev). I appreciate all the hard work that happens here, looking forward to scipy 1.0!

@sinhrks sinhrks added this to the 0.14.1 milestone Mar 30, 2017
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.

6 participants