Repository navigation
Remove @overload_glue for NumPy allocators. - #7999
Conversation
Turns these functions into true `@overloads`. * np.empty * np.empty_like * np.ones * np.ones_like * np.zeros * np.zeros_like also adds a `_zero_fill` method to the `types.Array` type to memset the array's memory region to zero, this is unchecked and for convenience only.
| @lower_getattr(types.Array, "imag") | ||
| def array_imag_part(context, builder, typ, value): | ||
| @intrinsic | ||
| def _force_readonly(tyctx, arr): |
There was a problem hiding this comment.
Move this to numba.np.unsafe.ndarray?
|
Note to reviewers: This patch is largely verbatim code motion, moving explicit typing templates into the typing part of |
|
|
||
| self.assertIn('No match', excstr) | ||
| msg = (f"If np.{self.pyfunc.__name__} dtype is a string it must be a " | ||
| "string constant.") |
| array = arrayty(cgctx, builder, llargs[0]) | ||
| # make readonly hack | ||
| parent = array._datamodel.get_type('parent') | ||
| setattr(array, 'parent', Constant(cgctx.get_value_type(parent), None)) |
There was a problem hiding this comment.
Why does it need to set parent to NULL? The only place this is used is in ary.imag for real domain array. The .parent is always NULL in that case.
There was a problem hiding this comment.
I vaguely recall adding this with view of trying provide a "general" way to set the readonly bit, was wondering (here: #7999 (comment)) whether this ought to be a utility function? Am fine to remove it or move it into numba.np.unsafe.ndarray.
There was a problem hiding this comment.
Let's remove it from _force_readonly. I don't think this is the way to do it. The boxer is already setting the writeable flag according to the array readonly/mutable property:
Line 1208 in 9a7820c
OWNDATA flag and it is a different concern.
There was a problem hiding this comment.
TBH, I'd rather that this didn't exist at all, but this sort of thing fails because the return type of the impl doesn't match the declared signature:
from numba import njit
from numba.core.extending import overload
import numpy as np
def foo(x):
pass
@overload(foo)
def ol_foo(x):
def impl(x):
return x
return x.copy(readonly=True)(x), impl
@njit
def call_foo(x):
return foo(x)
tmp = np.arange(5.)
print(call_foo(tmp))so the intrinsic is needed to fix it. I'll go fix the patch WRT the above.
sklam
left a comment
There was a problem hiding this comment.
#7999 (comment) is the only thing
Addressed in d69a6ac |
Turns these functions into true
@overloads.also adds a
_zero_fillmethod to thetypes.Arraytype to memsetthe array's memory region to zero, this is unchecked and for
convenience only.
Also converts the
.imagand.realattributes oftypes.Arrayto use@overload_attribute.