Raise IndexError if matrix index out of bounds

Closes #318
This commit is contained in:
Sergey B Kirpichev
2023-04-19 11:46:53 +03:00
parent ae610886c2
commit a9637115e5
2 changed files with 6 additions and 0 deletions
+4
View File
@@ -454,6 +454,8 @@ class _matrix:
raise IndexError('Row index out of bounds')
else:
# Single row
if key[0] >= self.__rows:
raise IndexError('Row index out of bounds')
rows = [key[0]]
# Columns
@@ -468,6 +470,8 @@ class _matrix:
else:
# Single column
if key[1] >= self.__cols:
raise IndexError('Column index out of bounds')
columns = [key[1]]
# Create matrix slice
+2
View File
@@ -49,6 +49,8 @@ def test_matrix_basic():
assert A9 != A10
assert nstr(A9)
assert A9 != None # issue 283
pytest.raises(IndexError, lambda: zeros(1,1)[:, 1]) # issue 318
pytest.raises(IndexError, lambda: zeros(1,1)[1, :])
def test_matmul():
"""