-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Support morphisms in Matroid
constructor
#37940
Conversation
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.
LGTM.
Thanks! @mkoeppe you may wish to have a look. |
@@ -734,6 +778,10 @@ def Matroid(groundset=None, data=None, **kwds): | |||
key = 'graph' | |||
elif is_Matrix(data): | |||
key = 'matrix' | |||
elif isinstance(data, sage.modules.with_basis.morphism.ModuleMorphism) or ( | |||
isinstance(data, tuple) and |
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'm not sure if I find "tuple" input very convincing.
Does it have a clear benefit over just passing the groundset via the groundset
parameter?
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 reason I did this is so that the following works:
sage: M = matroids.catalog.Fano()
sage: A = M.representation(order=True, labels=True)
sage: Matroid(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.
yes, ok
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 need to do something similar for matrices though.
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 made it so that this also works and retains the groundset labels:
sage: M = matroids.catalog.Fano()
sage: A = M.representation(labels=True)
sage: Matroid(A)
...
@@ -734,6 +778,10 @@ def Matroid(groundset=None, data=None, **kwds): | |||
key = 'graph' | |||
elif is_Matrix(data): | |||
key = 'matrix' | |||
elif isinstance(data, sage.modules.with_basis.morphism.ModuleMorphism) or ( |
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.
instead of using isinstance
with this class, I think it's better to use isinstance(data, Morphism) and data.category_for().is_subcategory(Modules(data.base_ring()).WithBasis())
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.
Not sure what's best but the above doesn't seem to work.
Also get groundset labels
LGTM, thanks! |
Documentation preview for this PR (built with commit 13e499a; changes) is ready! 🎉 |
This follows the merging of sagemath#37692 and it enables the (re-)feeding of a linear matroid's morphism representation into the `Matroid` constructor. Example: ``` sage: M = matroids.catalog.Fano() sage: A = M.representation(order=True); A Generic morphism: From: Free module generated by {'a', 'b', 'c', 'd', 'e', 'f', 'g'} over Finite Field of size 2 To: Free module generated by {0, 1, 2} over Finite Field of size 2 sage: Matroid(A) Binary matroid of rank 3 on 7 elements, type (3, 0) ``` URL: sagemath#37940 Reported by: gmou3 Reviewer(s): gmou3, Matthias Köppe, Travis Scrimshaw
This follows the merging of sagemath#37692 and it enables the (re-)feeding of a linear matroid's morphism representation into the `Matroid` constructor. Example: ``` sage: M = matroids.catalog.Fano() sage: A = M.representation(order=True); A Generic morphism: From: Free module generated by {'a', 'b', 'c', 'd', 'e', 'f', 'g'} over Finite Field of size 2 To: Free module generated by {0, 1, 2} over Finite Field of size 2 sage: Matroid(A) Binary matroid of rank 3 on 7 elements, type (3, 0) ``` URL: sagemath#37940 Reported by: gmou3 Reviewer(s): gmou3, Matthias Köppe, Travis Scrimshaw
This follows the merging of sagemath#37692 and it enables the (re-)feeding of a linear matroid's morphism representation into the `Matroid` constructor. Example: ``` sage: M = matroids.catalog.Fano() sage: A = M.representation(order=True); A Generic morphism: From: Free module generated by {'a', 'b', 'c', 'd', 'e', 'f', 'g'} over Finite Field of size 2 To: Free module generated by {0, 1, 2} over Finite Field of size 2 sage: Matroid(A) Binary matroid of rank 3 on 7 elements, type (3, 0) ``` URL: sagemath#37940 Reported by: gmou3 Reviewer(s): gmou3, Matthias Köppe, Travis Scrimshaw
This follows the merging of #37692 and it enables the (re-)feeding of a linear matroid's morphism representation into the
Matroid
constructor.Example: