From 9bf14e4ddafe7ef8f03f9e70236df26c72985d6d Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Mon, 2 May 2022 15:14:25 -0500 Subject: [PATCH] make indexing into non-positive dimension axes illegal --- pytato/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pytato/utils.py b/pytato/utils.py index 1eba387..f5d7845 100644 --- a/pytato/utils.py +++ b/pytato/utils.py @@ -521,6 +521,10 @@ def _index_into(ary: Array, indices: Tuple[ConvertibleToIndexExpr, ...]) -> Arra elif isinstance(idx, Array): if idx.dtype.kind not in ["i", "u"]: raise IndexError("only integer arrays are valid array indices") + if (_is_non_positive(ary.shape[i]) + and (not are_shape_components_equal(idx.size, 0))): + raise IndexError("Indirect indexing into a non-postive" + f" dimension (axis {i}) is illegal.") else: raise IndexError("only integers, slices, ellipsis and integer arrays" " are valid indices") -- GitLab