Code Monkey home page Code Monkey logo

numba-scipy's Introduction

Numba

Gitter

Discourse

Zenodo DOI

PyPI

A Just-In-Time Compiler for Numerical Functions in Python

Numba is an open source, NumPy-aware optimizing compiler for Python sponsored by Anaconda, Inc. It uses the LLVM compiler project to generate machine code from Python syntax.

Numba can compile a large subset of numerically-focused Python, including many NumPy functions. Additionally, Numba has support for automatic parallelization of loops, generation of GPU-accelerated code, and creation of ufuncs and C callbacks.

For more information about Numba, see the Numba homepage: https://numba.pydata.org and the online documentation: https://numba.readthedocs.io/en/stable/index.html

Installation

Please follow the instructions:

https://numba.readthedocs.io/en/stable/user/installing.html

Demo

Please have a look and the demo notebooks via the mybinder service:

https://mybinder.org/v2/gh/numba/numba-examples/master?filepath=notebooks

Contact

Numba has a discourse forum for discussions:

numba-scipy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

numba-scipy's Issues

Casting for special functions

Currently numba_scipy.special does no casting for special function arguments like the special ufuncs do. A basic example is:

>>> import numba
>>> import numpy as np
>>> import scipy.special as sc
>>> import numba_scipy.special
>>> @numba.njit
... def gammaln(x):
...     return sc.gammaln(x)
...
>>> sc.gammaln(1.0)
0.0
>>> sc.gammaln(np.float32(1.0))
0.0
>>> gammaln(1.0)
0.0
>>> gammaln(np.float32(1.0))
Traceback (most recent call last):
...

(Note that most functions in special don't have specific float32 signatures, they just cast to float64 and then cast back.)

This issue is to discuss: how should we handle the casting?

For numba_special I had a branch that handled this in the following way:

  • When generating overloads, look for an exact signature match
  • If that fails, use numpy.can_cast to see if the arguments can be safely upcast to an available kernel
  • Generate a casting function and compose it with the kernel

It works but is maybe a little messy. Is there a better way to handle this?

Benchmark

Hello,

Is there any benchmark for comparing numba-scipy with scipy?
I want to see where numba-scipy is in terms of performance.

Thanks,

Supporting complex airy

Hi, so I've attempted to use the code from here to implement a njit compatible complex airy function, but it ended up crashing my kernel. Any idea what the problem is? Or maybe it's possible to have numba-scipy support airy officially?

To clarify, the complex airy function itself crashes my kernel i.e.:
numba_airy_complex128(1)

user manual empty

Hi, first this extension to Numba looks very interesting and I am very keen to try it out so thanks for this!

Second, is there any simple examples that you could post on how to use this package? The user manual doesn't appear to have anything in it [1]

Also with this work with GPUs using numba.cuda ?

[1] https://numba-scipy.readthedocs.io/en/latest/user/index.html

Thanks!

scipy.ndimage (.distance_transform_edt) support?

Hey, I'm using numba to speed up my project and the only slow function is the one with scipy.ndimage.distance_transform_edt inside, Which numba 0.54.1 doesn't support... sadly I'm stuck with this version atm cause of dependency issues with the numba package and Python 3.9.7 I get from Anaconda (+ gdal depending packages). So I decided to search for a faster implementation but couldn't find any.

Now I'm thinking about making a faster implementation on my own which works for numba.
This numba-scipy package does only support scipy.special as far as I can see?
The documentation of the normal numba package says scipy speed up through np.linalg.* support, but I guess the newest version 0.55.1 doesn't support scipy.ndimage either? (didn't find its mentioned in the numba documentation supported list)
If I manage to implement and create an overload I'd like to share it here. Or is this the wrong package and the overload should go into the normal numba package?

Thanks for your help and numba (support) :)

Automatically create PRs that bump the SciPy version.

It would be great if we could create a workflow that bumps the SciPy versions for new releases. Such a workflow could be a cron job that runs at a reasonable interval; executes a simple script to read the latest version numbers for SciPy, check that it's newer, and make the modifications; and creates a PR with the changes using something like create-pull-request.

For discussion: numba_scipy.stats

hi everyone!

this is meant as a way to gather feedback on the current status of numba_scipy.stats. I'm pinging people that have expressed interest in numba_scipy.stats and/or are involved in numba and scipy. I'd like to share what I've learned so far, and hopefully you'll share your perspective on this.

Since last year I've been looking into scipy.stats with a view of getting numba-scipy.stats started. I created a prototype in #16. It's viable, but the experience has led me to question the cost/benefit tradeoff of following that path.

The main technical complication with scipy.stats is that is not function based, but object based. It relies on several of Python's OO features like inheritance and operator overloading. Numba has great support for function-based libraries (or method based, when the number of objects is limited) like Numpy. However, the support for classes (via jitclasses) is more limited and experimental. Outside of jitclasses, the only other option is to use the extending module, with the added effort that it implies.

The consequence of the above is that it will not be possible to fully imitate the behaviour of scipy.stats. At least not in the medium term, and not without a lot of work.

Even if jitclasses worked exactly as python classes, scipy.stats has more than a hundred distributions, each of them with more than 10 methods. If we followed the way of how numba supports numpy, we are talking about 1000+ methods to re-write. In some cases there will be performance improvements, but in some cases there won't.

Look at the following example:

from scipy.stats import norm
from numba import njit

def foo():
    k = 20000
    x = np.zeros(k)
    for m in range(100):
        x += norm.rvs(m, 1, size= 20000)
    return x

foo_jit = njit(foo)

@njit
def bar():
    k = 20000
    x = np.zeros(k)
    for m in range(100):
        with nb.objmode(y='float64[:]'):
            y = norm.rvs(m, 1, size= 20000)
        x += y
    return x

%timeit foo() #66 ms ± 277 µs

foo_jit()
%timeit foo_jit() #73.7 ms ± 214 µs

bar()
%timeit bar() #65.8 ms ± 208 µs

There's no performance improvement at all, because most of the work is already done in C. This will be the case in many scipy.stats functions.

To summarize, I see a few ways forward, each with pros and cons:

  • jitclass based solution

    • pros: easy for people to contribute (not much more than being competent with python and having used numba before)
    • cons: won't replicate scipy's behaviour, will regularly find jitclass' limitations and will have to find workarounds, will require 1000s of man-hours to build. All that effort does not build anything new, just a copy of existing scipy features.
  • low-level numba extension (http://numba.pydata.org/numba-doc/latest/extending/low-level.html)

    • pros: should be able to reproduce all or most behaviour
    • cons: harder to work with: would increase the effort required and limit the number of contributors. All that effort does not build anything new, just a copy of existing scipy features.
  • objmode approach = no jitted solution

    • pros: all existing features are immediately supported.
    • cons: all currently slow methods remain slow. added overhead of entering objmode, both in runtime and in boilerplate code. This last point might be made lighter by these: numba/numba#5461 and numba/numba#3282

I personally lean towards option 3 at the moment. I might write some custom code that calls special functions if I really need performance. But I'm not feeling very attracted to the idea of re-implementing such a large module as scipy.stats.

It would be great to hear your perspective on this.

cc: @gioxc88 @francoislauger @stnatter @remidebette @rileymcdowell @person142 @stuartarchibald

Error with the latest scipy

numba raised an exception with the latest version of scipy and numpy when numba-scipy is installed.
I installed all the packages from pypi, and ran the following script on Windows 10 x64 with Python 3.7.5.

Test code:

import numba as nb
import numpy
import numba_scipy
import scipy

@nb.jit
def testfunc():
    return 1.0

print("numpy: ", numpy.__version__)
print("scipy: ", scipy.__version__)
print("numba_scipy: ", numba_scipy.__version__)
print(testfunc())

With old numpy and scipy:

numpy:  1.17.4
scipy:  1.3.3
numba_scipy:  0.2.0
1.0

With the latest numpy and scipy:

numpy:  1.18.1
scipy:  1.4.1
numba_scipy:  0.2.0
Traceback (most recent call last):
  File "numbatest.py", line 13, in <module>
    print(testfunc())
  File "C:\Python37\lib\site-packages\numba\dispatcher.py", line 420, in _compile_for_args
    raise e
  File "C:\Python37\lib\site-packages\numba\dispatcher.py", line 353, in _compile_for_args
    return self.compile(tuple(argtypes))
  File "C:\Python37\lib\site-packages\numba\compiler_lock.py", line 32, in _acquire_compile_lock
    return func(*args, **kwargs)
  File "C:\Python37\lib\site-packages\numba\dispatcher.py", line 768, in compile
    cres = self._compiler.compile(args, return_type)
  File "C:\Python37\lib\site-packages\numba\dispatcher.py", line 77, in compile
    status, retval = self._compile_cached(args, return_type)
  File "C:\Python37\lib\site-packages\numba\dispatcher.py", line 91, in _compile_cached
    retval = self._compile_core(args, return_type)
  File "C:\Python37\lib\site-packages\numba\dispatcher.py", line 109, in _compile_core
    pipeline_class=self.pipeline_class)
  File "C:\Python37\lib\site-packages\numba\compiler.py", line 550, in compile_extra
    args, return_type, flags, locals)
  File "C:\Python37\lib\site-packages\numba\compiler.py", line 281, in __init__
    targetctx.refresh()
  File "C:\Python37\lib\site-packages\numba\targets\base.py", line 281, in refresh
    self.load_additional_registries()
  File "C:\Python37\lib\site-packages\numba\targets\cpu.py", line 80, in load_additional_registries
    numba.entrypoints.init_all()
  File "C:\Python37\lib\site-packages\numba\entrypoints.py", line 24, in init_all
    func()
  File "C:\Python37\lib\site-packages\numba_scipy\__init__.py", line 12, in _init_extension
    from . import special
  File "C:\Python37\lib\site-packages\numba_scipy\special\__init__.py", line 1, in <module>
    from . import overloads as _overloads
  File "C:\Python37\lib\site-packages\numba_scipy\special\overloads.py", line 4, in <module>
    from . import signatures
  File "C:\Python37\lib\site-packages\numba_scipy\special\signatures.py", line 376, in <module>
    ('pdtr', numba.types.float64, numba.types.float64): ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double, ctypes.c_double)(get_cython_function_address('scipy.special.cython_special', '__pyx_fuse_0pdtr')),
  File "C:\Python37\lib\site-packages\numba\extending.py", line 405, in get_cython_function_address
    return _import_cython_function(module_name, function_name)
ValueError: No function '__pyx_fuse_0pdtr' found in __pyx_capi__ of 'scipy.special.cython_special'

ValueError: No function '__pyx_fuse_0pdtr' found in __pyx_capi__ of 'scipy.special.cython_special'

Hi I am trying to use numba and I am using numba-scipy as a wrapper for scipy special functions. Below is my code:

import numpy as np
from scipy import integrate
from scipy.special import erf
from scipy.special import j0
import time
import numba as nb

q = np.linspace(0.03, 1.0, 1000)

start = time.time()

#error_model="numpy" -> Don't check for division by zero
@nb.njit(error_model="numpy",fastmath=True)
def f(t, z, q):
    return t * 0.5 * (erf((t - z) / 3) - 1) * j0(q * t) * (1 / (np.sqrt(2 * np.pi) * 2)) * np.exp(
        -0.5 * ((z - 40) / 2) ** 2)

def lower_inner(z):
    return 10.

def upper_inner(z):
    return 60.


y = np.empty(len(q))
for n in range(len(q)):
    y[n] = integrate.dblquad(f, 0, 50, lower_inner, upper_inner,args=(q[n],))[0]

end = time.time()
print(end - start)

I am getting the following error

ValueError: No function '__pyx_fuse_0pdtr' found in __pyx_capi__ of 'scipy.special.cython_special'

scipy.special.jv not found?

It would take some work to produce a minimal example, but maybe this will suffice?

import numpy as np
from scipy import constants
from numba import jit
import numba_scipy
import scipy.special as sp
...
@jit(nopython=True)
def circular_patch(a, h, L_op, er, theta, phi):
    # effective radius
    ae = a * np.sqrt(1 + (2 * h / (np.pi * a * er)) * (np.log(0.5 * np.pi * a / h) + 1.7726))
    k0 = 2 * np.pi / L_op
    sin_theta = np.sin(theta)
    bfn0 = sp.jv(0, k0 * ae * sin_theta)
    bfn2 = sp.jv(2, k0 * ae * sin_theta)
    Jp_02 = bfn0 - bfn2
    J_02 = bfn0 + bfn2

    # ((k0 * ae * exp(-1i*k0*r))/(2*r)) is a constant wrt theta & phi , so is
    # not included below.
    E_theta = np.abs(-1j * (np.cos(phi) * Jp_02))
    E_phi = np.abs(1j * (np.cos(theta) * np.sin(phi) * J_02))
    magEF = np.sqrt(E_theta * E_theta + E_phi * E_phi)

    return magEF
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<ufunc 'jv'>) found for signature:
 
 >>> jv(Literal[int](0), array(float64, 2d, C))
 
There are 2 candidate implementations:
   - Of which 2 did not match due to:
   Overload of function 'jv': File: numba_scipy/special/overloads.py: Line 9.
     With argument(s): '(int64, array(float64, 2d, C))':
    No match.

During: resolving callee type: Function(<ufunc 'jv'>)
During: typing of call at /home/nbecker/s-band/patch4.py (75)


File "patch4.py", line 75:
def circular_patch(a, h, L_op, er, theta, phi):
    <source elided>
    sin_theta = np.sin(theta)
    bfn0 = sp.jv(0, k0 * ae * sin_theta)
    ^

Did I use numba_scipy incorrectly?
I installed from git as:
pip install git+https://github.com/numba/numba-scipy.git
(normal pip install failed on python3.11 as others have reported before)

I have tried both sp.jv (0,...) and sp.jn (0,...) and both gave similar error.

triangular solver

Feature request

Hi,

I would like to be able to solve symmetric positive-definite linear systems in Numba using Cholesky factorization. While the Cholesky factorization is implemented, there is no triangular solver! It would be wonderful if a triangular solver could be implemented so that I can take advantage of the Cholesky function. Thanks.

Sam

Numba_special support for scipy.linalg ?

Hi!

Similarly to the OP in this thread I would like to speed up some functions (where some matrix exponentions and matrix logarithms are taken) with numba. I followed the discussion about numba for scipy. Nevertheless, I didn't find whether numba_scipy supports functions like scipy.linalg.exp, sciply.linalg.logm or scipy.lingalg.sqrtm. As there is no expm alternative in numpy, I suppose that this might be one of the core-functions of a scipy extension of numba(?)

But since I haven't found any (and when I try it it doesn't work) I expect that there is no way of using numba if logm, sqrtm and expm appear in the funcions I wanted to speed up?

Thank you!

Sparse and Stats Support

Hey there

I am needing to include the following functions:

  • sparse.eye
  • sparse.linalg.spsolve
  • sparse.lil_matrix
  • stats.zscore

And I am a little confused about how to do this with your library! There is something to do with Cython? Can I please get some pointers on how I can get started migrating these functions?

Cheers

Support for scipy.spatial.distance.cdist(mtA, mtB, 'cosine)

I am trying to speed up the cdist function from scipy.

I have the following


from scipy.spatial.distance import cdist
from numba import njit

@njit
def cosine_similarity(listA,listB): 
    dist = 1 - cdist(listA,listB, 'cosine')
    return dist

But when I run the cosine_similarity function I get the error

numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name 'cdist': Cannot determine Numba type of <class 'function'>

I assume it's still not supported? Or am I doing something wrong?

Example for calling special.beta() is not working? How to call scipy.special.ndtr?

Hello, I am trying to follow the example in Numba 0.46.0 Release Demo, but it does not seem to work:

from numba import jit, njit, config, __version__, errors
from numba.extending import overload
import numba
import numpy as np
assert tuple(int(x) for x in __version__.split('.')[:2]) >= (0, 46)

from scipy import special

@njit
def call_scipy_in_jitted_code():
    return special.beta(1.2, 3.4)
    
call_scipy_in_jitted_code()

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'beta' of type Module(<module 'scipy.special' from '/anaconda3-2020.07-Linux-x86_64/envs/py36dspf/lib/python3.6/site-packages/scipy/special/__init__.py'>)

File "<ipython-input-2-6f63370e200c>", line 5:
def call_scipy_in_jitted_code():
    return special.beta(1.2, 3.4)

I am using

  • numba 0.51.2
  • numba_scipy 0.2.0

What I actually really would like to achieve is to call scipy.special.ndtr. I've found an example on how to do it at:support for scipy.special functions : feature request:

_dble = ctypes.c_double

addr = numba.extending.get_cython_function_address("scipy.special.cython_special", "__pyx_fuse_1ndtr")
functype = ctypes.CFUNCTYPE(_dble, _dble)
ndtr_float64_fn = functype(addr)

@numba.njit()
def call_ndtr(v):
    return ndtr_float64_fn(v)

call_ndtr(0.1)
0.539827837277029

This works for a single value, but it does not work for an array as input:

call_ndtr(np.array([0.1,0.2]))

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function ExternalFunctionPointer((float64,) -> float64) found for signature:
 
 >>> ExternalFunctionPointer(array(float64, 1d, C))
 
There are 2 candidate implementations:
  - Of which 2 did not match due to:
...

How can I make this work for either case, no matter if I call it on a single value or an array?

Thanks a lot!
Christian

P.S.: by the way: how do I find the correct symbol __pyx_fuse_1ndtr or __pyx_fuse_0ndtr? I see that in ./special/cython_special.cpython-36m-x86_64-linux-gnu.so there are both symbols defined?

Release 0.3.0

  • merge changelog #60
  • create release0.3 branch
  • create 0.3.0 tag on branch
  • push branch and tag
  • Check that Github Actions created and uploaded PyPi release
  • Check that Github Actions create a conda package
  • Ensure conda package in correct channel (numba/label/main)
  • Create Discourse announcement
  • Create Twitter announcement
  • Tag next dev release on master and open changelog for 0.4.*

Sparse matrices?

@stuartarchibald, I saw on the numba gitter you were working on a scipy.sparse implementation here. I would really like to be able to use sparse matrices in compiled code, and have been implementing a bit of this myself, though primarily aiming at indexing into out-of-core sparse matrices. pydata/sparse has looked like an interesting target for this, but is missing the CSC and CSR formats.

I'd be keen to hear your perspective. What are your plans for sparse matrices here? How do you see this fitting in with pydata/sparse?

CI is using an old numba version

Some of the machines are installing v0.47. The version does not seem to be hard-coded, so somehow conda must be returning that version instead of v0.49.

From the Linux py37_np115_sp11_32bit test,

2020-04-24T14:05:44.9160422Z ncurses                   6.1                  he6710b0_1  
2020-04-24T14:05:44.9160993Z numba                     0.47.0          np1.11py3.7h04863e7_g4eb9cf875_0    numba
2020-04-24T14:05:44.9162983Z numba-scipy               0.1.0.dev0+91.gb5f6c6f           <pip>

which leads to ModuleNotFoundError: No module named 'numba.core'

cc @stuartarchibald

Is the current release broken against current scipy/numba?

I can't get the package to work in the most basic scenario. To be on the safe side I also tried the example from a numba 0.46 demo notebook linked in another issue:

from numba import njit
from scipy import special

@njit
def call_scipy_in_jitted_code():
    print("special.beta(1.2, 3.4)", special.beta(1.2, 3.4))
    print("special.j0(5.6)       ", special.j0(5.6))
    
call_scipy_in_jitted_code()

The result is an error as if numba-scipy wasn't even installed:

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'beta' of type Module(<module 'scipy.special' from '/home/user/virtualenvs/py3.8_main/lib/python3.8/site-packages/scipy/special/__init__.py'>)

File "<ipython-input-1-995b33e9a9f1>", line 6:
def call_scipy_in_jitted_code():
    print("special.beta(1.2, 3.4)", special.beta(1.2, 3.4))
    ^

During: typing of get attribute at <ipython-input-1-995b33e9a9f1> (6)

File "<ipython-input-1-995b33e9a9f1>", line 6:
def call_scipy_in_jitted_code():
    print("special.beta(1.2, 3.4)", special.beta(1.2, 3.4))
    ^

The relevant part of my pip freeze in the virtualenv:

$ pip freeze |grep -E 'numba|scipy'
numba==0.51.0
numba-scipy==0.2.0
scipy==1.5.2

Am I doing anything wrong?

Upgrading Scipy dependency to >1.7.3

Hi,

Since the most recent numba supports numpy 1.23 is there any chance the scipy dependency can be bumped to a newer version so that numba-scipy can be installed alongside numpy 1.23? Scipy 1.7.3 has a numpy version limit of <1.23.

I've had a bit of a look to see if there seems to be a reason not to. A plain pytest works fine with a few warnings and with pytest -Werror the following three tests fail with the warning numba_scipy/tests/test_special.py:55: DeprecationWarning: non-integer arg n is deprecated, removed in SciPy 1.7.x:

FAILED numba_scipy/tests/test_special.py::test_function[bdtr-specialization125] 
FAILED numba_scipy/tests/test_special.py::test_function[bdtrc-specialization127] 
FAILED numba_scipy/tests/test_special.py::test_function[bdtri-specialization129] 

Seemingly as the typing is pulled directly from scipy it is not something numba-scipy can control but even on the most recent scipy (1.9.1) all functions seem to still work with float arguments (although they pump out the same warning). If the functions are used with an int where appropriate both wrapped with numba and without the output seem the same and have no warnings.

Is there anything I am missing to stop bumping the scipy version?

I'm happy to open a PR to bump the version if there isn't. Thanks very much for your work on numba-scipy

current status of SciPy special

I'm unclear on what the status is for scipy.special at the moment.

Many of my reps rely on scipy >1.4 and it has trouble building on some systems now which break a lot of existing code that relied on this. I see the activity to update to newer python, but will this work soon? I've tried some of the branches but it seems I still cannot import things like gammaincc

thanks.

Implement array-valued signatures

As of #54 the simplest scalar calls to jitted special functions should work.

However there's no support yet for array-valued inputs:

import numpy as np
from numba import njit
from scipy import special

x = np.linspace(-10, 10, 1000)

@njit
def jitted_j0(x):
    res = special.j0(x[0])  # works after PR #54
    # res = special.j0(x)  # breaks
    return res

print(jitted_j0(x))

This is not obviously a shortcoming, since looping in jitted functions should be alright. So this is just a mild suggestion to consider adding support for array-valued signatures. (This should probably be preceded with some benchmarks to see whether this would help anything performance-wise.)

Error using numba-scipy extension to calculate cdist in python

I'd like to speed up the cdist between two numpy.ndarray using numba as follows:

import numpy as np
from numba import njit, jit
from scipy.spatial.distance import cdist
import time
    
@njit
def dist_scipy(a, b):
	d = cdist(a, b, 'euclidean')
	d = np.transpose(d)
	sorted_d = np.sort(d)
	sorted_ind = np.argsort(d)
	return sorted_d, sorted_ind

def get_a_b(r=10**4,c=10** 1):
	a = np.random.uniform(-1, 1, (r, c)).astype('f')
	b = np.random.uniform(-1, 1, (r, c)).astype('f')
	return a,b

if __name__ == "__main__":
    a, b = get_a_b()
    st_t = time.time()
    dist_scipy(a,b)
    print('it took {} s'.format(time.time()-st_t))

After $ pip install numba-scipy, I get the following error:

Traceback (most recent call last):
  File "stackoverflow_Q.py", line 31, in <module>
    dist_scipy(a,b)
  File "/usr/local/lib/python2.7/dist-packages/numba/dispatcher.py", line 420, in _compile_for_args
    raise e
  File "/usr/local/lib/python2.7/dist-packages/numba_scipy/special/overloads.py", line 12
    f = signatures.name_and_types_to_pointer[(name, *signature)]
                                                    ^
SyntaxError: invalid syntax

Pip installation broken

When performing pip install numba-scipy on a clean enviroment, the installation fails with a very long error ending in:

.
.
.
      INFO: CCompilerOpt.cache_flush[863] : write cache to path -> /tmp/pip-install-g8a5sb7r/scipy_146ee8793f624beeb0b89a9ff607c49a/build/temp.linux-x86_64-3.11/ccompiler_opt_cache_clib.py
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for scipy
Failed to build scipy
ERROR: Could not build wheels for scipy, which is required to install pyproject.toml-based projects

python version is 3.11.6

Release 0.3.1

jv special function not defined

We come from Issue #55.

I am using v0.0.3 and the following script.

from numba import jit, njit, config, __version__, errors
from numba.extending import overload
import numba
import numpy as np

from scipy import special


@njit
def call_scipy_in_jitted_code():
    print("special.beta(1.2, 3.4)", special.beta(1.2, 3.4))
    print("special.jv(5.6, 1)       ", special.jv(5.6, 1))


call_scipy_in_jitted_code()

With the following error:

Traceback (most recent call last):
  File "D:\_\_\_\scratch.py", line 15, in <module>
    call_scipy_in_jitted_code()
  File "C:\anaconda3\envs\numba_scipy\lib\site-packages\numba\core\dispatcher.py", line 420, in _compile_for_args
    error_rewrite(e, 'typing')
  File "C:\anaconda3\envs\numba_scipy\lib\site-packages\numba\core\dispatcher.py", line 361, 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 'jv'>) found for signature:

 >>> jv(float64, Literal[int](1))

There are 2 candidate implementations:
  - Of which 2 did not match due to:
  Overload of function 'jv': File: numba_scipy\special\overloads.py: Line 9.
    With argument(s): '(float64, int64)':
   No match.

During: resolving callee type: Function(<ufunc 'jv'>)
During: typing of call at D:\_\_\_\scratch.py (12)


File "_\_\_.py", line 12:
def call_scipy_in_jitted_code():
    <source elided>
    print("special.beta(1.2, 3.4)", special.beta(1.2, 3.4))
    print("special.jv(5.6, 1)       ", special.jv(5.6, 1))
    ^

The code will work for j0, but not for jv.

Supporting scipy.linalg in nopython mode?

Hi,

From my tests and while looking at the docs, it seems scipy.linalg module is not supported in nopython mode.

However, scipy.linalg.expm is the only implementation of matrix exponentiation in scipy and numpy, as far as I know, and having not supported can be blocking for some applications.

For now, I worked around it by isolating the part of my code that needed scipy.linalg.expm and wrapping the rest in a JIT with nopythonmode, but this may not be always possible.

Thanks!

Using interpolate.splev

Hi,

when using scipy.interpolate.splev, I get the following error:

Unknown attribute 'splev' of type Module(<module 'scipy.interpolate' from '/home/user/venv/numba/lib/python3.6/site-packages/scipy/interpolate/__init__.py'>)

Is it possible to integrate splev within numba-scipy?

Or does this error message mean I do not use numba-scipy correctly?

Thanks in advance!

Problem with installation

Hi,

I'm trying to install number_scipy on my Ubuntu machine. I have python 3 from newest anaconda.

To show this errors, I created a new, fresh environment:

pip install numba
pip install git+https://github.com/numba/numba-scipy.git#master

Succeed.

import numba
import numba_scipy as scp

Succeed. But....:

>>> scp
<module 'numba_scipy' from '/home/kking/env/lib/python3.7/site-packages/numba_scipy/__init__.py'>
>>> scp.__dict__

{'__name__': 'numba_scipy', '__doc__': None, '__package__': 'numba_scipy', '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7f6ead53cf98>, '__spec__': ModuleSpec(name='numba_scipy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f6ead53cf98>, origin='/home/kking/env/lib/python3.7/site-packages/numba_scipy/__init__.py', submodule_search_locations=['/home/kking/env/lib/python3.7/site-packages/numba_scipy']), '__path__': ['/home/kking/env/lib/python3.7/site-packages/numba_scipy'], '__file__': '/home/kking/env/lib/python3.7/site-packages/numba_scipy/__init__.py', '__cached__': '/home/kking/env/lib/python3.7/site-packages/numba_scipy/__pycache__/__init__.cpython-37.pyc', '__builtins__': {'__name__': 'builtins', '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", '__package__': '', '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>), '__build_class__': <built-in function __build_class__>, '__import__': <built-in function __import__>, 'abs': <built-in function abs>, 'all': <built-in function all>, 'any': <built-in function any>, 'ascii': <built-in function ascii>, 'bin': <built-in function bin>, 'breakpoint': <built-in function breakpoint>, 'callable': <built-in function callable>, 'chr': <built-in function chr>, 'compile': <built-in function compile>, 'delattr': <built-in function delattr>, 'dir': <built-in function dir>, 'divmod': <built-in function divmod>, 'eval': <built-in function eval>, 'exec': <built-in function exec>, 'format': <built-in function format>, 'getattr': <built-in function getattr>, 'globals': <built-in function globals>, 'hasattr': <built-in function hasattr>, 'hash': <built-in function hash>, 'hex': <built-in function hex>, 'id': <built-in function id>, 'input': <built-in function input>, 'isinstance': <built-in function isinstance>, 'issubclass': <built-in function issubclass>, 'iter': <built-in function iter>, 'len': <built-in function len>, 'locals': <built-in function locals>, 'max': <built-in function max>, 'min': <built-in function min>, 'next': <built-in function next>, 'oct': <built-in function oct>, 'ord': <built-in function ord>, 'pow': <built-in function pow>, 'print': <built-in function print>, 'repr': <built-in function repr>, 'round': <built-in function round>, 'setattr': <built-in function setattr>, 'sorted': <built-in function sorted>, 'sum': <built-in function sum>, 'vars': <built-in function vars>, 'None': None, 'Ellipsis': Ellipsis, 'NotImplemented': NotImplemented, 'False': False, 'True': True, 'bool': <class 'bool'>, 'memoryview': <class 'memoryview'>, 'bytearray': <class 'bytearray'>, 'bytes': <class 'bytes'>, 'classmethod': <class 'classmethod'>, 'complex': <class 'complex'>, 'dict': <class 'dict'>, 'enumerate': <class 'enumerate'>, 'filter': <class 'filter'>, 'float': <class 'float'>, 'frozenset': <class 'frozenset'>, 'property': <class 'property'>, 'int': <class 'int'>, 'list': <class 'list'>, 'map': <class 'map'>, 'object': <class 'object'>, 'range': <class 'range'>, 'reversed': <class 'reversed'>, 'set': <class 'set'>, 'slice': <class 'slice'>, 'staticmethod': <class 'staticmethod'>, 'str': <class 'str'>, 'super': <class 'super'>, 'tuple': <class 'tuple'>, 'type': <class 'type'>, 'zip': <class 'zip'>, '__debug__': True, 'BaseException': <class 'BaseException'>, 'Exception': <class 'Exception'>, 'TypeError': <class 'TypeError'>, 'StopAsyncIteration': <class 'StopAsyncIteration'>, 'StopIteration': <class 'StopIteration'>, 'GeneratorExit': <class 'GeneratorExit'>, 'SystemExit': <class 'SystemExit'>, 'KeyboardInterrupt': <class 'KeyboardInterrupt'>, 'ImportError': <class 'ImportError'>, 'ModuleNotFoundError': <class 'ModuleNotFoundError'>, 'OSError': <class 'OSError'>, 'EnvironmentError': <class 'OSError'>, 'IOError': <class 'OSError'>, 'EOFError': <class 'EOFError'>, 'RuntimeError': <class 'RuntimeError'>, 'RecursionError': <class 'RecursionError'>, 'NotImplementedError': <class 'NotImplementedError'>, 'NameError': <class 'NameError'>, 'UnboundLocalError': <class 'UnboundLocalError'>, 'AttributeError': <class 'AttributeError'>, 'SyntaxError': <class 'SyntaxError'>, 'IndentationError': <class 'IndentationError'>, 'TabError': <class 'TabError'>, 'LookupError': <class 'LookupError'>, 'IndexError': <class 'IndexError'>, 'KeyError': <class 'KeyError'>, 'ValueError': <class 'ValueError'>, 'UnicodeError': <class 'UnicodeError'>, 'UnicodeEncodeError': <class 'UnicodeEncodeError'>, 'UnicodeDecodeError': <class 'UnicodeDecodeError'>, 'UnicodeTranslateError': <class 'UnicodeTranslateError'>, 'AssertionError': <class 'AssertionError'>, 'ArithmeticError': <class 'ArithmeticError'>, 'FloatingPointError': <class 'FloatingPointError'>, 'OverflowError': <class 'OverflowError'>, 'ZeroDivisionError': <class 'ZeroDivisionError'>, 'SystemError': <class 'SystemError'>, 'ReferenceError': <class 'ReferenceError'>, 'MemoryError': <class 'MemoryError'>, 'BufferError': <class 'BufferError'>, 'Warning': <class 'Warning'>, 'UserWarning': <class 'UserWarning'>, 'DeprecationWarning': <class 'DeprecationWarning'>, 'PendingDeprecationWarning': <class 'PendingDeprecationWarning'>, 'SyntaxWarning': <class 'SyntaxWarning'>, 'RuntimeWarning': <class 'RuntimeWarning'>, 'FutureWarning': <class 'FutureWarning'>, 'ImportWarning': <class 'ImportWarning'>, 'UnicodeWarning': <class 'UnicodeWarning'>, 'BytesWarning': <class 'BytesWarning'>, 'ResourceWarning': <class 'ResourceWarning'>, 'ConnectionError': <class 'ConnectionError'>, 'BlockingIOError': <class 'BlockingIOError'>, 'BrokenPipeError': <class 'BrokenPipeError'>, 'ChildProcessError': <class 'ChildProcessError'>, 'ConnectionAbortedError': <class 'ConnectionAbortedError'>, 'ConnectionRefusedError': <class 'ConnectionRefusedError'>, 'ConnectionResetError': <class 'ConnectionResetError'>, 'FileExistsError': <class 'FileExistsError'>, 'FileNotFoundError': <class 'FileNotFoundError'>, 'IsADirectoryError': <class 'IsADirectoryError'>, 'NotADirectoryError': <class 'NotADirectoryError'>, 'InterruptedError': <class 'InterruptedError'>, 'PermissionError': <class 'PermissionError'>, 'ProcessLookupError': <class 'ProcessLookupError'>, 'TimeoutError': <class 'TimeoutError'>, 'open': <built-in function open>, 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'copyright': Copyright (c) 2001-2019 Python Software Foundation.
All Rights Reserved.

Copyright (c) 2000 BeOpen.com.
All Rights Reserved.

Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.

Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved., 'credits':     Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information., 'license': Type license() to see the full license text, 'help': Type help() for interactive help, or help(object) for help about object., '_': None}, '_version': <module 'numba_scipy._version' from '/home/kking/env/lib/python3.7/site-packages/numba_scipy/_version.py'>, '__version__': '0.1.0dev0+46.g2065ff5'}
>>> scp.special
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'numba_scipy' has no attribute 'special'

Do you have any ideas?


(env) (base) kking@kgpu01:~$ pip install numba_scipy
Requirement already satisfied: numba_scipy in ./env/lib/python3.7/site-packages (0.1.0.dev0+46.g2065ff5)
Requirement already satisfied: scipy>=0.16 in ./env/lib/python3.7/site-packages (from numba_scipy) (1.3.1)
Requirement already satisfied: numba>=0.45 in ./env/lib/python3.7/site-packages (from numba_scipy) (0.45.1)
Requirement already satisfied: numpy>=1.13.3 in ./env/lib/python3.7/site-packages (from scipy>=0.16->numba_scipy) (1.17.2)
Requirement already satisfied: llvmlite>=0.29.0dev0 in ./env/lib/python3.7/site-packages (from numba>=0.45->numba_scipy) (0.29.0)

(base) kking@kgpu01:~/env/lib/python3.7/site-packages$ tree ./numba_scipy
./numba_scipy
├── __init__.py
├── __pycache__
│   ├── __init__.cpython-37.pyc
│   └── _version.cpython-37.pyc
└── _version.py

(base) kking@kgpu01:~/env/lib/python3.7/site-packages$ tree ./numba_scipy-0.1.0.dev0+46.g2065ff5-py3.7.egg-info/
./numba_scipy-0.1.0.dev0+46.g2065ff5-py3.7.egg-info/
├── dependency_links.txt
├── installed-files.txt
├── not-zip-safe
├── PKG-INFO
├── requires.txt
├── SOURCES.txt
└── top_level.txt

0 directories, 7 file

How to use Numba for a spatial.cKDTree script ?

Hi all,

I am searching for a way to use Numba so that I can improve a KDTree processing script with scipy.
But it seems that it doesn't work when I apply the procedure from numba-scipy. I wonder if the spatial.cKDTree / spatial.KDTree is implemented within numba-scipy... Is it ?

Is there someone who could give me a hand on it ?
Or have I to compile my script with Cython ?

Thanks in advance,
Warm regards,
Hervé

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.