-
Notifications
You must be signed in to change notification settings - Fork 64
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
Adopt MutableArithmetics.jl ? #1000
Comments
I don't doubt that this package is the best thing since sliced bread. What I am not sure about is whether it helps at all with our matrix pains. Indeed, it also gets everything wrong if matrix entries are allowed to alias each other. The problem with matrices is not just missing pretty syntax.
Our pains with the matrices are of a different nature. I am happy to discuss it (again). It boils down to what 1. Disallow aliasing between matrix entriesSince this is just too easy to do wrong as a user (
To circumvent the performance problems, one could introduce
or
and use this everywhere in library code. But this means that user code dealing with matrix entries will always be slow, since no user will ever use this complicated syntax. 2. Allow aliasing of matrix entriesThis means no copy on write (ever) and the user can set entries in whichever way he wants without performance penalty. The disadvantage is, that 3. ConclusionOver the last years I had many discussions with Bill, Claus and Dan. At one point, Bill tried out the version 1. and the |
I agree that having aliases as entries of arrays can be a confusing mistake: julia> c = big.([0, 0])
2-element Vector{BigInt}:
0
0
julia> c[1] === c[2]
false
julia> c .= 0
2-element Vector{BigInt}:
0
0
julia> c[1] === c[2]
true
julia> c = zeros(BigInt, 2)
2-element Vector{BigInt}:
0
0
julia> c[1] === c[2]
true In JuMP, the way we deal with this is that the user calling the MutableArithmetics (MA) API is expected to be an advanced user that knows about these aliasing issues. |
Perhaps we should reconsider adopting https://github.com/jump-dev/MutableArithmetics.jl which has gotten some traction by now. To be clear: this does not invalidate all work done one the AA/Nemo/... mutable API, but rather it can complement it, and help us to fix some issues with its design and implementation.
For some background, this was originally brought up in kalmarek/GroupsCore.jl#21 by @blegat on @kalmarek's GroupsCore repository. I've been hesitant to support this, and @thofma and @fieker seemed rather sceptical about it.
But since then I've had a chance to watch the JuliaCon 2021 presentation on MutableArithmetics, and looked at their code and documentation. And at the same time, I tried to use some of our own mutable arithmetic, and found many gaps in what we provide, and some bugs (I think -- PRs will be submitted once I had a chance to write some test for and clean up what I added to Nemo)
Overall I think there are a few advantages to be had:
MA.mutable_copy
andMA.copy_if_mutable
, which we really should also offer for our types -- see also fix some deepcopy_internals: they need to call #955 were it is made clear that many of ourdeepcopy
methods violate the Julia specification@rewrite
macro for automatically rewriting an arithmetic expression to use mutating APIs seems pretty sweetIn addition, it seems (see here) like adding support for this won't be that much work, we just have to provide a few "adapter" functions and then "our" mutable API and "theirs" could be used in parallel.
The main work would be to add
MA.mutable_copy
methods and use them, but that's something I believe we have to do anyway (if notMA.mutable_copy
then via our own analogue).The main drawback in my eyes is that this adds an external dependency on something out of our control. However, the JuMP people seem reasonable enough, so I'd be willing to risk it.
Anyway, this would still be a major undertaking; but it can be done in separate steps
mutable_copy
andcopy_if_mutable
and start adding and using them; I'd try to make sure they match their MA counterparts exactly. Then if we later start usingMutableArithmetics
, it'll be a simple switch; and even if we don't use MA, then for people familiar with MA it'll be easier to use our codefmpz
in Nemo and see how that works out. If it does, one can use it more in Nemo (and Singular, and elsewhere, and eventually in AA). If not, we can give it up.The text was updated successfully, but these errors were encountered: