Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified a check in _getitem_RepMatrix #26590

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 1 addition & 2 deletions sympy/matrices/repmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,7 @@ def _getitem_RepMatrix(self, key):
return self._rep.getitem_sympy(index_(i), index_(j))
except (TypeError, IndexError):
if (isinstance(i, Expr) and not i.is_number) or (isinstance(j, Expr) and not j.is_number):
if ((j < 0) is True) or ((j >= self.shape[1]) is True) or\
((i < 0) is True) or ((i >= self.shape[0]) is True):
if (j < 0) or (j >= self.shape[1]) or (i < 0) or (i >= self.shape[0]):
Comment on lines 959 to +960
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change does not work for symbolic indices:

In [54]: i, j = symbols('i, j')

In [55]: M = Matrix([[1, 2], [3, 4]])

In [56]: M[i,j]
Out[56]: 
⎛⎡1  2⎤⎞      
⎜⎢    ⎥⎟[i, j]
⎝⎣3  4⎦⎠      

In [57]: M[i,j].subs({i:1,j:0})
Out[57]: 3

raise ValueError("index out of boundary")
from sympy.matrices.expressions.matexpr import MatrixElement
return MatrixElement(self, i, j)
Expand Down
Loading