This code fails:
import numpy as np
from numba import jit
import scipy.special as sp
@jit(nopython=True)
def f(a):
return sp.xlogy(a, a)
a = np.array([1,2,0,1], dtype=float)
f(a)
It gives the following error
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'xlogy' of type Module(<module 'scipy.special' from '/home/yair/.local/lib/python3.8/site-packages/scipy/special/__init__.py'>)
However, I believe it should work, becuase it says here that xlogy
could be overloaded. An answer from 2015 says this could not be done (for some other function) but maybe I thought it changed.
Of course, I can implement it myself but it would be nice to use a known solution.
EDIT:
Per Andras Deak's suggestion below, I tried using numba-scipy
. I cannot get it to work and was hoping for some usage example. Here are my attempts - they all fail, see errors below:
import numpy as np
from numba import jit
import numba_scipy
import scipy as sp
from scipy import special as spc
@jit(nopython=True)
def f1(a):
return numba_scipy.special.xlogy(a,a)
@jit(nopython=True)
def f2(a):
return numba_scipy.xlogy(a,a)
@jit(nopython=True)
def f3(a):
return sp.special.xlogy(a,a)
@jit(nopython=True)
def f4(a):
return spc.xlogy(a,a)
a = np.array([0,1,2])
try:
f1(a)
except Exception as e:
print('f1 fails')
print(e)
try:
f2(a)
except Exception as e:
print('f2 fails')
print(e)
try:
f3(a)
except Exception as e:
print('f3 fails')
print(e)
try:
f4(a)
except Exception as e:
print('f4 fails')
print(e)
Complete error message:
/home/yair/.local/lib/python3.8/site-packages/numba/core/dispatcher.py:238: UserWarning: Numba extension module 'numba_scipy' failed to load due to 'ValueError(No function '__pyx_fuse_0pdtr' found in __pyx_capi__ of 'scipy.special.cython_special')'.
entrypoints.init_all()
f1 fails
Failed in nopython mode pipeline (step: nopython rewrites)
module 'numba_scipy' has no attribute 'special'
f2 fails
Failed in nopython mode pipeline (step: nopython rewrites)
module 'numba_scipy' has no attribute 'xlogy'
f3 fails
Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'xlogy' of type Module(<module 'scipy.special' from '/home/yair/.local/lib/python3.8/site-packages/scipy/special/__init__.py'>)
File "example.py", line 19:
def f3(a):
return sp.special.xlogy(a,a)
^
During: typing of get attribute at example.py (19)
File "example.py", line 19:
def f3(a):
return sp.special.xlogy(a,a)
^
f4 fails
Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'xlogy' of type Module(<module 'scipy.special' from '/home/yair/.local/lib/python3.8/site-packages/scipy/special/__init__.py'>)
File "example.py", line 23:
def f4(a):
return spc.xlogy(a,a)
^
During: typing of get attribute at example.py (23)
File "example.py", line 23:
def f4(a):
return spc.xlogy(a,a)
^