Support morphisms in Matroid constructor#37940
Conversation
|
Thanks! @mkoeppe you may wish to have a look. |
| 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.
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.
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.
I need to do something similar for matrices though.
There was a problem hiding this comment.
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)
...
| 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.
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.
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! 🎉 |
sagemathgh-37940: Support morphisms in `Matroid` constructor 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
sagemathgh-37940: Support morphisms in `Matroid` constructor 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
sagemathgh-37940: Support morphisms in `Matroid` constructor 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
Matroidconstructor.Example: