-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Implemented Ellipsis in slicing Sympy Matrices. #11392
Conversation
fix for sympy#11345. Added test cases for Ellipsis arguments for matrix slicing. … means the same as : in a matrix. Hence, if the argument is ‘….’ , input to MatrixSlice is set to `slice(None, None, None) `.
@leosartaj , can your review this? |
@asmeurer , can you review this? |
This does not work.
|
This also doesn't work as expected.
I would expect something like this
|
@leosartaj , the following program does work in my local computer: >>> from sympy import *
>>> m = MatrixSymbol('A', 3, 4)
>>> m[...]
A[:3, :4] |
@leosartaj , the following program works now: >>> from sympy import *
>>> m = Matrix([[1, 2, 3], [4, 5, 6]])
>>> m[...]
Matrix([
[1, 2, 3],
[4, 5, 6]])
>>> m[0,...]
Matrix([[1, 2, 3]]) |
@leosartaj , ping. |
@asmeurer , ping. |
1 similar comment
@asmeurer , ping. |
i = j = slice(None, None, None) | ||
else: | ||
i, j = key | ||
if (i is Ellipsis) or (j is Ellipsis): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line does not have any effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing this PR. If only one among i
or j
is Ellipsis
, then this line will have use.
Example
assert X[2, ...] == MatrixSlice(X, 2, (0, m))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjodah is correct. the four lines below handle this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I have fixed it.
@leosartaj , ping. |
@@ -451,6 +451,9 @@ def test_slicing(): | |||
m2 = Matrix([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]) | |||
assert m2[:, -1] == Matrix(4, 1, [3, 7, 11, 15]) | |||
assert m2[-2:, :] == Matrix([[8, 9, 10, 11], [12, 13, 14, 15]]) | |||
assert m2[...] == m2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't equal to m2[:]
right? In other cases, ...
and :
are equivalent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, its not equal.
5549403
to
81ff1b7
Compare
… means the same as : in a matrix. Hence, if the argument is ‘….’ , input to MatrixSlice is set to `slice(None, None, None) `.
Although I don't see any clear advantage of slicing with ellipsis in matrix, |
This is fix for #11345. Added conditions when the argument is
ellipsis
.Sample Program