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
Matrix stack() should coerce to a common parent #16399
Comments
Commit: |
Branch: u/chapoton/16399 |
comment:1
I have tried to look at the code. Apparently, one only tries to change the base ring of the bottom matrix. But of course, the coercion could be the other way, or there could be some complicated way to find a common coercion. I have made a preliminary attempt, very incomplete. New commits:
|
comment:2
Here's how to get a common parent:
and since we're modifying cython files, we could probably use the cdef global coercion model from element.pyx:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:5
Given the syntax, The example below gives questionable results, but the change you propose here would break the behaviour we have already:
Clearly, the current semantics are conversion into the base ring of the first matrix. Changing that into coercion into a common parent would be a real change, and it's not clear to me the resulting semantics are entirely desirable. I'm not particularly defending the current semantics either. I'm just pointing out you're proposing an incompatible change and for that to be justified we'd need fairly wide concensus that the change leads to significantly more desirable behaviour. |
comment:7
Replying to @nbruin:
I disagree with this. That's just a pure syntactical thing, mathematically "stacking" could be seen as a binary operator. I am +1 to coercion, but there could indeed be unexpected consequences. |
comment:8
Note: I hit the issue on this ticket by working on #17585. Apparently, the |
Changed branch from u/chapoton/16399 to u/jdemeyer/ticket/16399 |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
Author: Frédéric Chapoton, Jeroen Demeyer |
comment:14
Looks good overall, but there are two things. The first is could you keep the "returns a new matrix" part of the documentation? Since matrices are mutable, your proposed change makes the result slightly ambiguous to me as we could mutate in place and return Second is about this change: diff --git a/src/sage/modules/fg_pid/fgp_morphism.py b/src/sage/modules/fg_pid/fgp_morphism.py
index 80fe02b..86bbe37 100644
--- a/src/sage/modules/fg_pid/fgp_morphism.py
+++ b/src/sage/modules/fg_pid/fgp_morphism.py
@@ -423,6 +423,7 @@ class FGP_Morphism(Morphism):
# Stack it on top of the basis for W'.
Wp = CD.V().coordinate_module(CD.W()).basis_matrix()
+ Wp = Wp.change_ring(A.base_ring())
B = A.stack(Wp)
# Compute Hermite form of C with transformation Is this necessary for this ticket or is it suppose to be a part of #17585? |
comment:15
Replying to @tscrim:
Yes, it's necessary for this ticket but it's not needed with #16399 and #17585 together. So it could be added here and removed again in #17585. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
This comment has been minimized.
This comment has been minimized.
Reviewer: Travis Scrimshaw |
comment:19
Replying to @jdemeyer:
Okay, then positive review. Thanks for making that change to the doc. |
Changed branch from u/jdemeyer/ticket/16399 to |
I feel like we shouldn't have to do an explicit ring change to do this. Plus we get (somewhat) different failures for dense versus sparse matrices:
Follow-up: #17595
Component: linear algebra
Keywords: matrix stack coercion
Author: Frédéric Chapoton, Jeroen Demeyer
Branch/Commit:
810a889
Reviewer: Travis Scrimshaw
Issue created by migration from https://trac.sagemath.org/ticket/16399
The text was updated successfully, but these errors were encountered: