Skip to content

Import functions directly from the NumPy FFT interface - #165

Merged
hgomersall merged 2 commits into
pyFFTW:masterfrom
jakirkham:fix_dask_imports
Apr 20, 2017
Merged

hgomersall merged 2 commits into
pyFFTW:masterfrom
jakirkham:fix_dask_imports

Conversation

@jakirkham

Copy link
Copy Markdown
Member

Instead of importing the NumPy FFT module interface, import functions from that interface and then wrap those functions. This avoids things leaking in from the NumPy FFT interface into the Dask FFT interface.

Instead of importing the NumPy FFT module interface, import functions
from that interface and then wrap those functions. This avoids things
leaking in from the NumPy FFT interface into the Dask FFT interface.
@jakirkham

Copy link
Copy Markdown
Member Author

Thoughts on this, @hgomersall?

@hgomersall

Copy link
Copy Markdown
Collaborator

Sorry, I've been really busy this last week.

What's the point of this? I'm not a big fan of overwriting the namespace like you do. What was wrong with the previous way?

@jakirkham

Copy link
Copy Markdown
Member Author

Because we shouldn't have numpy_fft available in dask_fft.

@jakirkham

Copy link
Copy Markdown
Member Author

I'm not a big fan of overwriting the namespace like you do.

Also I don't follow this. How are we overwriting the namespace? We are only importing select functions from numpy_fft instead of importing the whole module. What is wrong with doing it this way?

Comment thread pyfftw/interfaces/dask_fft.py Outdated

from . import numpy_fft
from .numpy_fft import (
fft,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here dask_fft.fft is the same as numpy_fft.fft

Comment thread pyfftw/interfaces/dask_fft.py Outdated
irfft = fft_wrap(numpy_fft.irfft)
hfft = fft_wrap(numpy_fft.hfft)
ihfft = fft_wrap(numpy_fft.ihfft)
fft = fft_wrap(fft)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here it changes.

@jakirkham

Copy link
Copy Markdown
Member Author

Sure, that is intentional. This is not in any way different from how Python decorators work.

Though maybe I'm not understanding your concern. Could you please clarify what problem you see this causing?

@hgomersall

Copy link
Copy Markdown
Collaborator

It's a bit hypothetical, but imported code could change on the fly (particularly if we consider threads). It's not quite how decorators work - they don't put anything in the namespace until after the decorator returns (or rather, the object put into the namespace always has the correct getter associated with it).

@hgomersall

Copy link
Copy Markdown
Collaborator

Actually, I don't know how what I said could happen. It's probably safe :) I'm not keen on the style though because it's not clear that the import fft is different to the one in the ultimate module namespace.

@hgomersall

Copy link
Copy Markdown
Collaborator

I'd prefer it I think if you kept the existing implementation. You could "protect" numpy_fft by importing it with an underscore: from . import numpy_fft as _numpy_fft. That would mean it wouldn't import with import * nor come up with tab completion in ipython.

@hgomersall

Copy link
Copy Markdown
Collaborator

poke (cheekily, given by slow response time).

To satisfy some concerns about code clarity and also ensure external
modules are not exposed in the public API of the Dask interface, simply
import `numpy_fft` as `_numpy_fft` so that it stays relatively hidden.
@hgomersall

Copy link
Copy Markdown
Collaborator

Great, thanks! I'll merge after successful tests.

@jakirkham

Copy link
Copy Markdown
Member Author

Thanks @hgomersall. Wasn't going to ping you until it passed, but I guess it just did.

@hgomersall
hgomersall merged commit dd3ec16 into pyFFTW:master Apr 20, 2017
@jakirkham
jakirkham deleted the fix_dask_imports branch March 12, 2018 21:20
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.

2 participants