-
Notifications
You must be signed in to change notification settings - Fork 58
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
Move obvious type piracy from Hecke to Nemo #1501
Conversation
6175631
to
bd539b3
Compare
return c < 0 | ||
end | ||
|
||
function mulmod(a::UInt, b::UInt, n::UInt, ni::UInt) |
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.
There are probably better places for this and other functions. What's the plan here? Move the first into this file and merge it; and then when we are done, we can take our time to move things to a nicer place?
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.
Functions, where I do not directly see a good place to put them, will be in some files named after the Hecke file they originate from for the time being. Moving them around in Nemo is easy to do later in a separate PR. Or if you have any recommendations, let me know and I will move them in this PR.
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.
src/flint/fmpz.jl
?
Maybe it would be best to organize a meeting (real or virtual) involving at least @lgoettgens @thofma and @fieker (I am also happy to join) to closely coordinate these changes and do them in 1-2 days, instead of having all these disruptive changes spaced out over multiple weeks and PRs and so on.... |
That sounds like a good idea. I am available to travel to Kaiserslautern or Siegen for a few days. Or meet online. Let's further plan this on slack. |
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.
A couple more semi-random suggestions. I'd like to stress that these are just meant as food for thought. I don't mind merging the PR w/o them (of course there are other blockers for merging, like tests need to pass and syncing with our other packages be sorted out).
src/HeckeMiscInteger.jl
Outdated
function remove(z::T, p::T) where {T<:Integer} | ||
z == 0 && return (0, z) | ||
v = 0 | ||
@assert p > 1 | ||
while mod(z, p) == 0 | ||
z = Base.div(z, p) | ||
v += 1 | ||
end | ||
return (v, z) | ||
end | ||
|
||
function remove(z::Rational{T}, p::T) where {T<:Integer} | ||
z == 0 && return (0, z) | ||
v, d = remove(denominator(z), p) | ||
w, n = remove(numerator(z), p) | ||
return w - v, n // d | ||
end | ||
|
||
function valuation(z::T, p::T) where {T<:Integer} | ||
z == 0 && return 0 | ||
v = 0 | ||
@assert p > 1 | ||
while mod(z, p) == 0 | ||
z = Base.div(z, p) | ||
v += 1 | ||
end | ||
return v | ||
end | ||
|
||
function valuation(z::Rational{T}, p::T) where {T<:Integer} | ||
z == 0 && error("Not yet implemented") | ||
v = valuation(denominator(z), p) | ||
w = valuation(numerator(z), p) | ||
return w - v | ||
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.
These could even go into AbstractAlgebra, no?
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 do not know if it is easier to manage large PRs over three repos right now or first move stuff from Hecke to Nemo and then later, in a separate PR, tackle the Nemo <-> AbstractAlgebra side. For the moment, I am doing the later.
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.
Changed my plan. There now is Nemocas/AbstractAlgebra.jl#1392 containing the parts of this PR that belong to AA.
src/HeckeMiscInteger.jl
Outdated
function remove!(a::QQFieldElem, b::ZZRingElem) | ||
nr = ccall((:fmpq_numerator_ptr, libflint), Ptr{ZZRingElem}, (Ref{QQFieldElem},), a) | ||
vn = ccall((:fmpz_remove, libflint), Clong, (Ptr{ZZRingElem}, Ptr{ZZRingElem}, Ref{ZZRingElem}), nr, nr, b) | ||
#QQFieldElem's are simplified: either num OR den will be non-trivial | ||
if vn != 0 | ||
return vn, a | ||
end | ||
nr = ccall((:fmpq_denominator_ptr, libflint), Ptr{ZZRingElem}, (Ref{QQFieldElem},), a) | ||
vn = ccall((:fmpz_remove, libflint), Clong, (Ptr{ZZRingElem}, Ptr{ZZRingElem}, Ref{ZZRingElem}), nr, nr, b) | ||
return -vn, a | ||
end | ||
|
||
function valuation!(a::QQFieldElem, b::ZZRingElem) | ||
nr = ccall((:fmpq_numerator_ptr, libflint), Ptr{ZZRingElem}, (Ref{QQFieldElem},), a) | ||
vn = ccall((:fmpz_remove, libflint), Clong, (Ptr{ZZRingElem}, Ptr{ZZRingElem}, Ref{ZZRingElem}), nr, nr, b) | ||
#QQFieldElem's are simplified: either num OR den will be non-trivial | ||
if vn != 0 | ||
return vn | ||
end | ||
nr = ccall((:fmpq_denominator_ptr, libflint), Ptr{ZZRingElem}, (Ref{QQFieldElem},), a) | ||
vn = ccall((:fmpz_remove, libflint), Clong, (Ptr{ZZRingElem}, Ptr{ZZRingElem}, Ref{ZZRingElem}), nr, nr, b) | ||
return -vn | ||
end | ||
|
||
function BigFloat(a::QQFieldElem) | ||
r = BigFloat(0) | ||
ccall((:fmpq_get_mpfr, libflint), Nothing, (Ref{BigFloat}, Ref{QQFieldElem}, Int32), r, a, __get_rounding_mode()) | ||
return r | ||
end | ||
|
||
function isless(a::Float64, b::QQFieldElem) | ||
return a < b * 1.0 | ||
end | ||
function isless(a::QQFieldElem, b::Float64) | ||
return a * 1.0 < b | ||
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.
belongs to src/flint/fmpq.jl
...
Though I guess we could also move all the methods involving BigFloat
inputs into a file of their own... a matter of taste, I am open to either or a third alternative.
return c < 0 | ||
end | ||
|
||
function mulmod(a::UInt, b::UInt, n::UInt, ni::UInt) |
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.
src/flint/fmpz.jl
?
bd539b3
to
0c66dcc
Compare
Codecov Report
@@ Coverage Diff @@
## master #1501 +/- ##
==========================================
- Coverage 88.78% 82.76% -6.02%
==========================================
Files 89 95 +6
Lines 34346 37181 +2835
==========================================
+ Hits 30494 30773 +279
- Misses 3852 6408 +2556
... and 10 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
9020a7d
to
ebf791e
Compare
The number of reported piracy cases already went down from 721 to 425! |
2a83a9e
to
93fba0a
Compare
The OscarCI-release failures are expected as this is a breaking change. |
|
324e250
to
67d2f74
Compare
The move of some stuff to AbstractAlgebra seemed too involved for me to fix it in the next days. Thus I would revert back to the original plan to just move a lot of stuff from Hecke to Nemo in this PR, and look to Nemo and AA sometime in the future. |
Co-authored-by: Max Horn <[email protected]>
This reverts commit 67d2f74.
8149883
to
2819441
Compare
Resolves parts of thofma/Hecke.jl#1126.
I will have a look through the Hecke files that contain many cases of reported type piracy, and move those functions to Nemo, that are either trivial in their implementation, or if it is clear that they only use functionality already in Nemo (like calls to flint).
Functions, where I do not directly see a good place to put them, will be in some files named after the Hecke file they originate from for the time being. Moving them around in Nemo is easy to do later in a separate PR. Or if you have any recommendations, let me know and I will move them in this PR.
The then duplicate functions will be removed from Hecke at thofma/Hecke.jl#1143.