Hello,
if I make the types in the signature of my @guvectorize procedure c-ontiguous, compilation fails very early with a strange AssertionError. Here is a a minimal example:
@guvectorize([void(float32[::1], float32[::1])], '(four)->(four)')
def foo(x, out):
assert x.shape[-1] == 4
for i in literal_unroll(range(4)):
out[i] = x[i]
@jit([float32[:, ::1](float32[:, ::1])])
def bar(xs):
out = numpy.empty_like(xs)
foo(xs, out)
return out
print(bar(numpy.arange(24).astype(numpy.float32).reshape(6, 4)))
Lowering crashes with this:
File "/opt/miniconda3/envs/video/lib/python3.11/site-packages/numba/np/arrayobj.py", line 6460, in array_to_array
assert fromty.mutable != toty.mutable or toty.layout == 'A'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
There are two ways I can work around this:
- I replace
::1by:in the@guvectorizedecorator (but not in the@jitdectorator). - I hack the numba code in
arrayobj.py, simply deleting theassertstatement.
In both cases, the code runs just fine afterwards.
I have two questions:
- Am I observing a bug here, or am I doing something wrong?
- Is it even desirable to use
::1in the@guvectorizedecorator? I have been experimenting and I believe that it reduces the temporal overhead for calling my GUFunc, but I am not sure of this observation yet. So I would like to know whether c-contiguousness can have an impact on speed (and on loop vectorization) at all.