I am trying to use numpy from within jit optimized code of Numba but I am getting errors when I am trying to do standard numpy operations like numpy.ones_like, even though numba documentation mentions that the operation is supported.
Documentation link: Numba 0.46.
Edit: The method 'calc_method' works fine if I make a direct call to it, fails when used from within apply_chunks. So probably not an issue with Numba itself but how cudf.apply_chunks is being used.
Code:
import numba
from numba import jit
import pandas as pd
import numpy as np
print(numba.__version__)
@jit(nopython=True)
def calc_method(a,b):
a1 = np.float64(a)
b1 = np.float64(b)
abc = (a1, np.ones_like(b1))
abc_ht = np.hstack(abc)
return abc_ht
def calculate(cudf_df: cudf, size_of_row: int):
return cudf_df.apply_chunks(calc_method, incols=['a', 'b'], outcols=dict(), chunks=size_of_row)
df = pd.DataFrame({'a': [1, 2, 3, 4, 5, 6, 7, 8], 'b': [11, 12, 13, 14, 15, 16, 17, 18]})
cudf_df = cudf.DataFrame.from_pandas(df)
a, b = calculate(cudf_df, 4)
Error:
TypingError Traceback (most recent call last)
<ipython-input-38-ad56fb75bc4a> in <module>
----> 1 a, b = calculate(cudf_df, 4)
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<numba.cuda.compiler.DeviceFunctionTemplate object at 0x7fa78521b550>) with argument(s) of type(s): (array(int64, 1d, A), array(int64, 1d, A))
* parameterized
In definition 0:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Use of unsupported NumPy function 'numpy.ones_like' or unsupported use of the function.
File "<ipython-input-37-97f7d707ba81>", line 9:
def calc_method(a,b):
<source elided>
b1 = np.float64(b)
abc = (a1, np.ones_like(b1))
^
Can anyone tell me what am I doing wrong in the above example? Thanks in advance.
I also get a similar error for np.hstack
Note: This is a simplified example to reproduce the issue.