-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Determine current fft backend in use (for specified inputs) #14758
Comments
Interesting, I don't think this has been requested before (Cc @hameerabbasi, @peterbell10 in case I missed it).
Is there a reason you want your library's choice depend on the user choice, rather than always using pyfftw if it's installed? Is it not always faster, or is it about deterministic behavior (which should not depend on optional installed packages), or ... ? |
The point is to have deterministic behavior. |
I'm interested... Why not just set the backend to Use |
I don't want to add a dependency on pyfftw (in particular because they still don't have py39 wheels available, but that's a bit of a side point). |
Even if we were able to return an object with your proposed Forgive the questions, I'm just wondering if there's a way to solve your use-case without extending |
I don't need a dependency on pyfftw; I can check e.g. backend = get_backend(inputs) # whatever API we decide on
backend_name = getattr(backend, "__name__", None)
if backend_name == "pyfftw.interfaces.scipy_fft":
import pyfftw # OK, we know pyfftw is indeed available, so we can import it
enable_pyfftw_specific_path()
elif backend_name == "<whatever>":
import whatever
enable_whatever_specific_path()
elif ...:
...
elif backend == "scipy": # fallback
enable_scipy_specific_path()
else: # some unknown backend, may or may not emit warning
warnings.warn("Don't know this backend, falling back to scipy.fft")
enable_scipy_specific_path() |
Ah, in that case, I would add multimethods and register them with the correct backend instead of actually playing around with backends in this manner. See the cc @peterbell10 do we have a common registration mechanism that was added to SciPy's backends? |
I have a few concerns with that approach:
|
Not really in any hurry, but @rgommers' recent email on array type dispatch seems like a good opportunity to re-raise this? |
Ah yes, thanks for pointing this out @anntzer. We should address this and the other open issues related to the |
@anntzer I'm in the process of releasing wheels for 3.9 and 3.10. If you need examples, there are many in the Quansight-Labs/unumpy repo. |
There is a separate issue about improving the docs for the That's still separate from @anntzer's third point here:
|
def get_backend(func, *args, **kwargs):
dispatchables = func.arg_extractor(*args, **kwargs)
return _uarray.determine_backend(func.domain, dispatchables, True) One major problem though is that SciPy's backend doesn't implement |
Thanks for the suggestion. However, unless I am mistaken(?), no released version of scipy currently includes |
I tried this with the just released scipy 1.8.0rc1, but I get
(both when the active backend is the default scipy.fft, and when it is pyfftw) |
Is your feature request related to a problem? Please describe.
I would like a way to know which backend (e.g. scipy's own fft or pyfftw.interfaces.scipy_fft) would be used when e.g.
scipy.fft.fft(some_specified_object)
is called. (See below for a proposed API.)The reason is that I would like my library to use the explicit pyfftw class-based API iff the end user has configured the pyfftw backend on scipy (via
scipy.fft.set_backend
or a variant thereof), thus reusing the configuration on scipy and avoiding a separate configuration knob on my library.Describe the solution you'd like.
A possible API would be something like
scipy.fft.fft.get_backend(*args, **kwargs)
returning the backend thatscipy.fft.fft(*args, **kwargs)
would dispatch to (as an object compatible withset_backend
, so either "scipy" or pyfftw.interfaces.scipy_fft, in the case above).Describe alternatives you've considered.
No response
Additional context (e.g. screenshots, GIFs)
No response
The text was updated successfully, but these errors were encountered: