-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Added Documentation for SDM class #21163
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
Conversation
✅ Hi, I am the SymPy bot (v161). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like: This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.9. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
sympy/polys/matrices/sdm.py
Outdated
>>> elemsdict = {0:{1:QQ(2)}, 1:{}} | ||
>>> A = SDM(elemsdict, (2, 2), QQ) | ||
>>> A | ||
{0: {1: 2}, 1: {}} |
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.
The elemsdict
should not have any empty dicts in there. This docstring should explain that it is the responsibility of whoever creates elemsdict
to remove zero rows and zero elements.
Also this should show how to construct a DomainMatrix
from the SDM
.
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.
I think it would be better to move this docstring to be the main class docstring and also to show examples of using the SDM
e.g. for adding and multiplying
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.
I'll do that
sympy/polys/matrices/sdm.py
Outdated
|
||
>>> from sympy.polys.matrices.sdm import SDM | ||
>>> from sympy import QQ | ||
>>> ddm = [[QQ(1, 2), 0], [0, QQ(3, 4)]] |
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.
The 0
should be QQ(0)
.
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.
I'll change it everywhere
sympy/polys/matrices/sdm.py
Outdated
|
||
>>> from sympy import QQ | ||
>>> from sympy.polys.matrices.sdm import SDM | ||
>>> A = SDM({0:{0:QQ(1), 1:QQ(2)}, 1:{0: QQ(3), 1: QQ(4)}}, (2, 2), QQ) |
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.
The spacing around colons is inconsistent.
>>> from sympy.polys.matrices.sdm import SDM | ||
>>> A = SDM({0:{0:QQ(1), 1:QQ(2)}, 1:{0: QQ(3), 1: QQ(4)}}, (2, 2), QQ) | ||
>>> A.charpoly() | ||
[1, -5, -2] |
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.
It would be good to show here how to construct a Poly from these e.g.:
x = Symbol('x')
p = Poly(A.charpoly(), x, domain=A.domain)
p
>>> A = SDM({0:{1: ZZ(2)}, 1:{0:ZZ(1)}}, (2, 2), ZZ) | ||
>>> B = SDM({0:{0:ZZ(2), 1:ZZ(3)}, 1:{0:ZZ(4)}}, (2, 2), ZZ) | ||
>>> A.matmul(B) | ||
{0: {0: 8}, 1: {0: 2, 1: 3}} |
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.
For each of these methods it would be good to point out that they are also used by the operators so e.g. this could show that you get the same from A*B
.
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.
These docstrings should also explain when the domains are are required to match or what constraints there are on the shapes of the matrices for the operation to be defined.
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.
You actually don't get the same from A * B
.
A * B
Traceback (most recent call last):
File "", line 1, in
TypeError: unsupported operand type(s) for *: 'SDM' and 'SDM'
This is what you get with A*B
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.
I think __add__(A, B)
needs to be implemented for SDM class
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.
Oh yeah, I think it's A @ B
or __matmul__
. Is that not implemented for SDM
?
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.
Perhaps it is better to use *
anyway. Either way SDM
and DDM
should be made consistent so can you compare how DDM
works?
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.
Consistent in what ways? You want both to have the same functionality right, is that what you're saying
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.
By the way *
does not work in DDM either
A = DDM([[ZZ(1), ZZ(2)], [ZZ(2), ZZ(3)]], (2, 2), ZZ)
B = DDM([[ZZ(3), ZZ(4)], [ZZ(1), ZZ(2)]], (2, 2), ZZ)
A * B
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for *: 'DDM' and 'DDM
I'll have to make __mul__
in DDM consistent with definition in DomainMatrix
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.
I mean that when using methods like A * B
or A.matmul(B)
etc then all behaviour should be exactly the same whether A
and B
are both DDM
or both SDM
. These two classes are supposed to be completely interchangeable in that sense. So if you are changing any part of the behaviour of SDM
you should check that DDM
behaves in exactly the same way.
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.
I'll have to make
__mul__
in DDM consistent with definition in DomainMatrix
Note that DDM
and DomainMatrix
do not need to be consistent as they are not intended to be interchangeable. It is DDM
and SDM
that need to be consistent. For now I think that SDM
should just use @
for matrix multiplication just like DDM
does. We can consider changing that in future but these two classes need to remain equivalent.
sympy/polys/matrices/sdm.py
Outdated
>>> elemsdict = {0:{1:QQ(2)}} | ||
>>> A = SDM(elemsdict, (2, 2), QQ) | ||
>>> A | ||
{0: {1: 2}} |
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.
The most useful thing to show here would be what this looks like as a Matrix. I don't think that the meaning of the dict of dicts structure is obvious without being explained.
sympy/polys/matrices/sdm.py
Outdated
We can manipulate :py:class:`~.SDM` the same way | ||
as a Matrix class | ||
|
||
>>> from sympy import ZZ | ||
>>> A = SDM({0:{1: ZZ(2)}, 1:{0:ZZ(1)}}, (2, 2), ZZ) | ||
>>> B = SDM({0:{0: ZZ(3)}, 1:{1:ZZ(4)}}, (2, 2), ZZ) | ||
>>> A + B | ||
{0: {0: 3, 1: 2}, 1: {0: 1, 1: 4}} | ||
|
||
Multiplication | ||
|
||
>>> A = SDM({0:{1: ZZ(2)}, 1:{0:ZZ(1)}}, (2, 2), ZZ) | ||
>>> B = SDM({0:{0: ZZ(3)}, 1:{1:ZZ(4)}}, (2, 2), ZZ) | ||
>>> A*B | ||
{0: {1: 8}, 1: {0: 3}} | ||
>>> A*ZZ(2) | ||
{0: {1: 4}, 1: {0: 2}} |
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.
These examples can be condensed. We don't need to create new matrices for each demonstration.
sympy/polys/matrices/sdm.py
Outdated
|
||
>>> from sympy.polys.matrices.sdm import SDM | ||
>>> from sympy import QQ | ||
>>> elemsdict = {0:{1:2}, 1:{}} |
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.
The empty dict shouldn't be there. The 2
should be QQ(2)
>>> from sympy import QQ | ||
>>> A = SDM.zeros((2, 3), QQ) | ||
>>> A | ||
{} |
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 would be easier to understand if you also show what the corresponding matrix would be.
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.
You could show what A.to_Matrix()
gives here
sympy/polys/matrices/sdm.py
Outdated
@@ -308,7 +751,7 @@ def sdm_irref(A): | |||
>>> pivots | |||
[0, 1] | |||
|
|||
The analogous calculation with :py:class:`~.Matrix` would be | |||
The analogous calculation with Matrix class would be |
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.
Why is this changed?
@oscarbenjamin please review |
>>> elemsdict = {0:{1:QQ(1, 2)}} | ||
>>> A = SDM(elemsdict, (2, 2), QQ) | ||
>>> A | ||
{0: {1: 1/2}} |
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.
It would be good so short the result of A.to_Matrix()
here.
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.
I don't think SDM class has to_Matrix()
, DomainMatrix
on the other hand does have that functionality
sympy/polys/matrices/sdm.py
Outdated
MT = sdm_transpose(M) | ||
return M.new(MT, M.shape[::-1], M.domain) | ||
return MT |
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.
Why is this changed? Does this return a dict or SDM
?
Okay, looks good. |
References to other Issues or PRs
Brief description of what is fixed or changed
Added Documentation for SDM class
Other comments
Release Notes