numba / numba

NumPy aware dynamic Python compiler using LLVM
https://numba.pydata.org/
BSD 2-Clause "Simplified" License
9.96k stars 1.13k forks source link

unsupported keyword arguments when calling Function(<ufunc 'add'>) #3602

Open luciotorre opened 5 years ago

luciotorre commented 5 years ago

When running the following code:

In [1]: import numpy as np                                                                                                                                                                    
In [2]: import numba                                                                                                                                                                          
In [3]: ls = np.linspace(0, 1000, 1000)                                                                                                                                                       
In [4]: @numba.jit(nopython=True, fastmath=True)  
   ...: def test():  
   ...:     np.add(ls, 1024, out=ls)  

I get an error: unsupported keyword arguments when calling Function(<ufunc 'add'>)

Which may it is just a missing feature, but the error also says:

File "<ipython-input-5-71496563ec4b>", line 3:
def test(): 
    np.add(ls, 1024, out=ls) 
    ^

[1] During: lowering "$0.7 = call $0.2($0.3, $const0.4, func=$0.2, args=[Var($0.3, <ipython-input-5-71496563ec4b> (3)), Var($const0.4, <ipython-input-5-71496563ec4b> (3))], kws=[('out', Var($0.5, <ipython-input-5-71496563ec4b> (3)))], vararg=None)" at <ipython-input-5-71496563ec4b> (3)
-------------------------------------------------------------------------------
This should not have happened, a problem has occurred in Numba's internals.

Please report the error message and traceback, along with a minimal reproducer
at: https://github.com/numba/numba/issues/new

If more help is needed please feel free to speak to the Numba core developers
directly at: https://gitter.im/numba/numba

Thanks in advance for your help in improving Numba!

So i complied :)

stuartarchibald commented 5 years ago

Thanks for the report. I think the problem here is that the keyword arg is rejected, and this should have been caught before trying to lower the function. The function itself has support in the implementation to handle the array supplied in out, it just cannot be declared as such, for example:

import numpy as np
import numba

ls = np.linspace(0, 10, 10)
@numba.jit(nopython=True, fastmath=True)
def test():
    z = np.zeros_like(ls)
    np.add(ls, 1024, z)
    return z

print(test())