Repository navigation
Fix shape mismatch ignored by in-place array operators - #10671
eyupcanakman wants to merge 2 commits into
Conversation
An in-place operator on arrays whose shapes don't broadcast was lowered without a shape check, so the loop ran over the output's shape and read past the smaller input. @njit returned a wrong result with no error, while NumPy and Python raise a ValueError. When the caller supplies the output (an in-place operator or an explicit out=), the broadcast check in _build_array is skipped. Numba now validates each input against the output shape there and raises a ValueError. a + b and other implicit-output ufuncs are unaffected. Closes numba#9166
|
@eyupcanakman could you port the NumPy test to your PR? |
Port NumPy's test_out_broadcast_errors: a provided output may broadcast the inputs but cannot be smaller than the result, so a too-small out raises instead of silently writing.
|
Done, ported it as test_out_broadcast_errors. numba raises "unable to broadcast" rather than numpy's "non-broadcastable", so I matched the assertion to that. |
|
There's one test failure now for python 3.10. Can you fix it? |
|
That's the docs job ( |
|
oh, ok. It's not related to your PR. |
|
@kc611 could you review this one? |
An in-place operator on arrays whose shapes don't broadcast was lowered without a shape check, so the loop ran over the output's shape and read past the smaller input.
@njitreturned a wrong result with no error, while NumPy and Python raise aValueError.When the caller supplies the output (an in-place operator or an explicit
out=), the broadcast check in_build_arrayis skipped. Numba now validates each input against the output shape there and raises aValueError.a + band other implicit-output ufuncs are unaffected.Closes #9166