Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pytensor/link/numba/dispatch/elemwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ def dimshuffle_inner(x, shuffle):

@numba_basic.numba_njit
def dimshuffle_inner(x, shuffle):
return np.reshape(x, ())
return np.reshape(np.ascontiguousarray(x), ())

# Without the following wrapper function we would see this error:
# E No implementation of function Function(<built-in function getitem>) found for signature:
Expand Down
11 changes: 11 additions & 0 deletions tests/link/numba/test_elemwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ def test_Dimshuffle_returns_array():
assert out.ndim == 0


def test_Dimshuffle_non_contiguous():
"""The numba impl of reshape doesn't work with
non-contiguous arrays, make sure we work around that."""
x = at.dvector()
idx = at.vector(dtype="int64")
op = pytensor.tensor.elemwise.DimShuffle([True], [])
out = op(at.specify_shape(x[idx][::2], (1,)))
func = pytensor.function([x, idx], out, mode="NUMBA")
assert func(np.zeros(3), np.array([1])).ndim == 0


@pytest.mark.parametrize(
"careduce_fn, axis, v",
[
Expand Down