-
Notifications
You must be signed in to change notification settings - Fork 63
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
Simplify and fix similar
and zero
for our matrix types
#1890
Conversation
From a first glance it looks like that some tests depend on the old (wrong) behaviour |
There is also a doctests, which illustrates the "feature", that sometimes entries can be |
Yeah so one thing that is wrong is that the
So it ignores it first argument. This is apparently even desired (?) but only if the user supplied R ?!? More on that below, but the key here is: if only a matrix is provided as input, then the resulting output matrix should have the same type. Which the current It is unclear to me whether So here is for some background: Those failing tests in Nemo reference Nemocas/Nemo.jl#651 which describes:
There is the also a linked issue #490 which was also closed long ago. It contains a somewhat relevant example perhaps motivating this (slightly edited for context):
Of course that's for Though it is not quite clear to me why That leaves the task of how to specify / document / implement this coherently, but that goes a bit beyond this PR. I'll see what I can do here at least in the coming days/weeks. |
If I understand it right then That then means we must not document it as Presumably the same for For the cases taking a ring, to what matrix types shall it change? What we can do for now is to produce something of |
Remove the internal helper `_similar` which untangles the `MatElem` and `MatRingElem` code further and makes it easier to see what's going on. Also change `similar` for `MatElem` to default to calling `zero_matrix`. With this `similar(::ZZMatrix)` in Nemo returns a new `ZZMatrix` instead of a `AbstractAlgebra.Generic.MatSpaceElem{ZZRingElem}`.
abe822f
to
9b184d4
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1890 +/- ##
==========================================
+ Coverage 88.13% 88.16% +0.03%
==========================================
Files 120 120
Lines 30294 30295 +1
==========================================
+ Hits 26700 26710 +10
+ Misses 3594 3585 -9 ☔ View full report in Codecov by Sentry. |
9b184d4
to
f7da828
Compare
This should be ready now :-) |
Fixes the Nemo issue, so it is an improvement. |
Hrm, I just realized another twist to the rules for But that means the type of the resulting matrix differs from the input matrix even in the single-argument version Can be dealt with of course, but it's yet another wrinkle in the story that our docs don't tell (I think? Didn't search thoroughly yet, so perhaps it is better than I claim) |
A very simple rule would be if we ignore the
But then there are trouble again with Urgh |
Maybe a "proper" fix is to have AbstractAlgebra, Nemo and Singular have their own |
Also, let's not throw out the baby with the wash water :-). First off, I think this PR here still is "safe" (and in any case, even if something regressed, it should be easy enough to adjust). So I'll merge it. Next, I note that also
What really causes me confusion is the different between To me it feels like this is what we need to resolve. Perhaps by indeed splitting
In each case, My feeling is that we want 2, and we may not even need 1 -- adjusting the artihmetic code in e.g. |
Maybe we should just discuss the desired behavior in triage? |
I don't think a discussion of this during the triage meeting would be productive. For the discussion, I think we should not assume that something like
and
The philosophy is that for a user there is only one matrix type per element type and this is preserved under If AA or Singular really need a method that makes similar on |
I agree with @thofma. |
I think we agree so far that
should hold. Good! That leaves the question whether to require
But this "choice" only matters because we allow instances of Put concretely, we could change the Of course this would be mildly breaking (as in: some code might accidentally have some of those; and the Nemo test suite on purpose tries to create such object). But other than that I can't think of any serious downside? |
f19a27d
to
cea07e2
Compare
similar
for our matrix typessimilar
and zero
for our matrix types
function similar(x::MatSpaceElem{T}, r::Int, c::Int) where T <: NCRingElement | ||
M = Matrix{T}(undef, (r, c)) | ||
return MatSpaceElem{T}(base_ring(x), M) | ||
end |
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 method would go if we agree on the proposal to forbid MatSpaceElem{T}
instances if dense_matrix_type(T) != MatSpaceElem{T}
.
But in the meantime it is necessary to preserve Nemo tests.
These don't really make much sense and I suggest we deprecate them in the future but for now I want to keep it simple.
To clarify: this PR does not implement the If @lgoettgens can get himself to agree, I suggest we merge this now as it improves the state of affairs (I've suggested that before but then didn't merge... ah well). For the docstrings, I note that also the manual itself currently says many no longer quite true things about matrices and matrix ring elements. I would adjust these and the docstrings in one go. But it doesn't make sense to adjust them to the current state of things if then later agree to implement changes to how If we then agree on the plan to "forbid |
On Tue, Nov 12, 2024 at 12:39:50AM -0800, Max Horn wrote:
To clarify: this PR does not implement the `similar` revision we are discussing. I've now adjust it once more to cleanup some docstrings. The docstrings are currently not quite correct. But I deliberate leave them as they are, as this PR has dragged on for far too long already.
If @lgoettgens can get himself to agree, I suggest we merge this now as it improves the state of affairs (I've suggested that before but then didn't merge... ah well).
For the docstrings, I note that also the manual itself currently says many no longer quite true things about matrices and matrix ring elements. I would adjust these and the docstrings in one go. But it doesn't make sense to adjust them to the current state of things if then later agree to implement changes to how `similar` works. Hence my reluctance for further changes *in this PR*.
If we then agree on the plan to "forbid `Generic.MatSpaceElem{ZZRingElem}`" then in fact the docstrings here are mostly fine, I would just extend them to spell out more clearly what is going on.
I don't thinkn we're going to put effort in to forbidding it - but we
don't care about it and will not support it (actively)
…
--
Reply to this email directly or view it on GitHub:
#1890 (comment)
You are receiving this because you are subscribed to this thread.
Message ID: ***@***.***>
|
I agree with your summary @fingolfin, but also agree with @fieker that we probably should not enforce this by throwing an error. I can imagine that for some horrible internal hacks it might be advantage to still have this option. (Similar to how we allow |
Create an uninitialized matrix over the given ring and dimensions, | ||
with defaults based upon the given source matrix `x`. | ||
""" | ||
similar(x::MatElem, R::NCRing, r::Int, c::Int) = zero_matrix(R, r, c) |
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 could be changed in the future to use the UndefInitializer, right? (but not needed right now)
so something like dense_matrix_type(R)(R, undef, r, c)
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, that's the plan (but we can't change it now because that'd be a breaking change and wouldn't work with older Nemo versions.
Remove the internal helper
_similar
which untangles theMatElem
andMatRingElem
code further and makes it easier to see what's going on.Also change
similar
forMatElem
to default to callingzero_matrix
. With thissimilar(::ZZMatrix)
in Nemo returns a newZZMatrix
instead of aAbstractAlgebra.Generic.MatSpaceElem{ZZRingElem}
.Resolves Nemocas/Nemo.jl#1826