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

Add example #74

Open
erwanp opened this issue Dec 16, 2021 · 7 comments
Open

Add example #74

erwanp opened this issue Dec 16, 2021 · 7 comments
Labels
feature_request Request for a feature

Comments

@erwanp
Copy link

erwanp commented Dec 16, 2021

Could you add an example of use in the Readme or in the Docs https://numba-scipy.readthedocs.io/en/latest/user/index.html ,
the user-manual is currently empty

@esc esc added the feature_request Request for a feature label Dec 16, 2021
@esc
Copy link
Member

esc commented Dec 16, 2021

@erwanp thank you for submitting this. I have labeled it as a feature request. Pull-requests always welcome! 😇

@clarkedavida
Copy link

Please even a very simple example would be helpful! Can you maybe give a hint how to use this module? Does it come automatically with import numba? The following code doesn't work, and I can't tell why.

from numba import jit
import scipy.special as sp


@jit(nopython=True)
def integral(a,b):
    sp.beta(a,b)

@esc
Copy link
Member

esc commented Sep 13, 2023

Please even a very simple example would be helpful! Can you maybe give a hint how to use this module? Does it come automatically with import numba? The following code doesn't work, and I can't tell why.

from numba import jit
import scipy.special as sp


@jit(nopython=True)
def integral(a,b):
    sp.beta(a,b)

What error message do you get?

@clarkedavida
Copy link

>>> from numba import jit
>>> import scipy.special as sp
>>> @jit(nopython=True)
... def integral(a,b):
...     sp.beta(a,b)
... 
>>> integral(1,2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/david/.local/lib/python3.11/site-packages/numba/core/dispatcher.py", line 468, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/home/david/.local/lib/python3.11/site-packages/numba/core/dispatcher.py", line 409, in error_rewrite
    raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'beta' of type Module(<module 'scipy.special' from '/usr/lib/python3.11/site-packages/scipy/special/__init__.py'>)

File "<stdin>", line 3:
<source missing, REPL/exec in use?>

During: typing of get attribute at <stdin> (3)

File "<stdin>", line 3:
<source missing, REPL/exec in use?>

@esc
Copy link
Member

esc commented Sep 14, 2023

So, I tried to reproduce this and found two things. The error you are seeing is because numba-scipy is either not installed or not installed correctly. After pip install numba-scipy I get:

Traceback (most recent call last):
  File "/Users/esc/git/numba/issue_numba_scipy_74.py", line 9, in <module>
    integral(1, 2)
  File "/Users/esc/git/numba/numba/core/dispatcher.py", line 468, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/Users/esc/git/numba/numba/core/dispatcher.py", line 409, in error_rewrite
    raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<ufunc 'beta'>) found for signature:

 >>> beta(int64, int64)

There are 2 candidate implementations:
  - Of which 2 did not match due to:
  Overload of function 'beta': File: ../../miniconda3-arm64/envs/numba_3.10/lib/python3.10/site-packages/numba_scipy/special/overloads.py: Line 9.
    With argument(s): '(int64, int64)':
   No match.

During: resolving callee type: Function(<ufunc 'beta'>)
During: typing of call at /Users/esc/git/numba/issue_numba_scipy_74.py (7)


File "issue_numba_scipy_74.py", line 7:
def integral(a,b):
    sp.beta(a,b)

Which may be a bug in numba-scipy.

@clarkedavida
Copy link

clarkedavida commented Sep 14, 2023

OK you're correct, I somehow lost my numba-scipy installation... That's something I'll have to fix on my own.

Anyway do you think you could maybe give 1-2 short examples where numba-scipy works? I was originally interested in this to try to speed up double integrals of the form

scipy.integrate.quad( scipy.integrate.quad ( func, ... ) )

My strategy so far has been to Numba as much of func as I can, but for my use-case there are a couple instances where it would be convenient to just numba-scipy a scipy.integrate.

Thanks for taking some time to look into this, I appreciate it.

EDIT: Wait I'm just now noticing... Does numba-scipy actually work with the integrate module?

@esc
Copy link
Member

esc commented Sep 14, 2023

OK you're correct, I somehow lost my numba-scipy installation... That's something I'll have to fix on my own.

Anyway do you think you could maybe give 1-2 short examples where numba-scipy works? I was originally interested in this to try to speed up double integrals of the form

scipy.integrate.quad( scipy.integrate.quad ( func, ... ) )

My strategy so far has been to Numba as much of func as I can, but for my use-case there are a couple instances where it would be convenient to just numba-scipy a scipy.integrate.

Thanks for taking some time to look into this, I appreciate it.

EDIT: Wait I'm just now noticing... Does numba-scipy actually work with the integrate module?

No, I don't think so. The currently supported functions are listed on: https://numba-scipy.readthedocs.io/en/latest/reference/index.html -- this is the scope of the scipy functions that can be used within a Numba @njit decorated context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature_request Request for a feature
Projects
None yet
Development

No branches or pull requests

3 participants