Skip to content

Commit

Permalink
[NDArray] Fix bug with tuple indexing (#1357)
Browse files Browse the repository at this point in the history
Fixes #1310
  • Loading branch information
leonardt committed Jan 31, 2024
1 parent 956a64d commit f08e78c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion magma/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,8 @@ def _ndarray_getitem(self, key: tuple):
if len(key) == 1:
return self[key[0]]
if not isinstance(key[0], slice):
return self[key[0]][key[1:]]
next_key = next_key = key[1:] if len(key) > 2 else key[1]
return self[key[0]][next_key]
if not self._is_whole_slice(key[0]):
# If it's not a slice of the whole array, first slice the
# current array (self), then replace with a slice of the whole
Expand Down
6 changes: 6 additions & 0 deletions tests/test_type/test_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,9 @@ class Main(m.Circuit):
m.compile("build/test_ndarray_get_slice", Main, inline=True)
assert check_files_equal(__file__, f"build/test_ndarray_get_slice.v",
f"gold/test_ndarray_get_slice.v")


def test_ndarray_constant():
class Foo(m.Circuit):
arr_m = m.Array[(3, 2), m.Bits[4]]([[1] * 2] * 3)
assert arr_m[0, 0] == 1

0 comments on commit f08e78c

Please sign in to comment.