-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix binding logic in @overload_glue
.
#7996
Conversation
Updates the binding logic to accommodate calling `@overload_glue` wrapped functions with named arguments. Fixes numba#7982
377b3ff
to
0e5aece
Compare
@overload_glue
.
@@ -1254,7 +1254,7 @@ class NumbaCArray(CallableTemplate): | |||
def generic(self): | |||
func_name = self.key.__name__ | |||
|
|||
def typer(ptr, shape, dtype=types.none): | |||
def typer(ptr, shape, dtype=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change needs some thinking about. I think the default now matches what an @overload
would implement, but I'm not sure if this is correct WRT @overload_glue
. There's also the question of whether the subsequent type check needs to be a is_nonelike()
type check for the case of a types.none
appearing, not sure if this is actually possible yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... that's a problem. It will be a types.none
when called with c_arr = numba.carray(arr, (3,), dtype=None)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following will fail:
import ctypes
import numba
import numpy as np
@numba.cfunc(numba.types.void(
numba.types.CPointer(numba.types.double)
))
def func(arr: np.ndarray) -> None:
c_arr = numba.carray(arr, (3,), dtype=None)
c_arr[-1] = 1
my_arr = np.array([1, 2, 3], dtype=np.float_).ctypes.data_as(ctypes.POINTER(ctypes.c_double))
func(my_arr)
The OverloadSelector cannot find the impl:
File "/path/to/numba/numba/core/base.py", line 44, in find
out = self._find(sig)
File "/path/to/numba/numba/core/base.py", line 53, in _find
raise errors.NumbaNotImplementedError(f'{self}, {sig}')
numba.core.errors.NumbaNotImplementedError: <numba.core.base.OverloadSelector object at 0x7ff7d85c3310>, (float64*, UniTuple(Literal[int](3) x 1), none)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From OOB chat, time would be better spent translating this to @overload
than trying to fix this edge case in @overload_glue
, added this as issue: #8009
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch looks good in general. Just one nitpick on the change to use generator for the varnames. Why not just a simple sequence (list/tuple)?
As title.
numba/core/overload_glue.py
Outdated
"""This generates a function based on the argnames generated by the | ||
varnames_gen generator, the "body_func" is the function that'll |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""This generates a function based on the argnames generated by the | |
varnames_gen generator, the "body_func" is the function that'll | |
"""This generates a function based on the argnames provided by | |
varnames, the "body_func" is the function that'll |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed these and the side-effects of fixing these in 2e833f7
Rename variable and fix code/docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch!
Updates the binding logic to accommodate calling
@overload_glue
wrapped functions with named arguments.
Fixes #7982