Skip to content
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

how to properly import cupyx submodules #8336

Open
ev-br opened this issue May 23, 2024 · 2 comments
Open

how to properly import cupyx submodules #8336

ev-br opened this issue May 23, 2024 · 2 comments
Labels
cat:enhancement Improvements to existing features prio:medium

Comments

@ev-br
Copy link
Contributor

ev-br commented May 23, 2024

Description

Are cupyx.scipy submodules meant to be available if

  • the top-level cupyx name is imported
  • the cupyx.scipy name is imported
  • the cupyx.scipy.<submodule> name is imported

The latter seems to be the case ATM (with special being, uhm, special, see below), and the question is what's the actual API ?

The origin of the question is scipy/scipy#20772 where we're having to programmatically importlib.import_module(f"cupyx.scipy{submodule}").

To Reproduce

In [1]: import cupyx
   ...: getattr(cupyx.scipy.special, 'gammainc', None)
Out[1]: <ufunc 'cupyx_scipy_gammainc'>

In [2]: import cupyx
   ...: getattr(cupyx.scipy.signal, 'convolve', None)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 2
      1 import cupyx
----> 2 getattr(cupyx.scipy.signal, 'convolve', None)

AttributeError: module 'cupyx.scipy' has no attribute 'signal'

In [3]: import cupyx
   ...: getattr(cupyx.scipy.linalg, 'solve', None)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 2
      1 import cupyx
----> 2 getattr(cupyx.scipy.linalg, 'solve', None)

AttributeError: module 'cupyx.scipy' has no attribute 'linalg'

In [4]: import cupyx
   ...: getattr(cupyx.scipy.ndimage, 'correlate', None)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 2
      1 import cupyx
----> 2 getattr(cupyx.scipy.ndimage, 'correlate', None)

AttributeError: module 'cupyx.scipy' has no attribute 'ndimage'

Installation

None

Environment

# Paste the output here

Additional Information

Of course this is not a bug report. Am asking here not on gitter mainly to have a public record to refer to going forward.

@ev-br ev-br added the cat:bug Bugs label May 23, 2024
@kmaehashi
Copy link
Member

Ideally I think it's nice to mimic the behavior of SciPy at this point too. IIRC import scipy will allow access to all submodules while actual module loading is performed lazily?

@kmaehashi kmaehashi added cat:enhancement Improvements to existing features and removed cat:bug Bugs labels May 24, 2024
@lucascolley
Copy link

IIRC import scipy will allow access to all submodules while actual module loading is performed lazily?

yep 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat:enhancement Improvements to existing features prio:medium
Projects
None yet
Development

No branches or pull requests

3 participants