Nemocas / Nemo.jl

Julia bindings for various mathematical libraries (including flint2)
http://nemocas.github.io/Nemo.jl/
Other
177 stars 57 forks source link

Type piracy in Nemo #1495

Open fingolfin opened 1 year ago

fingolfin commented 1 year ago

Enabling the type piracy report in test/Aqua.jl currently reports this (in Julia 1.10.3, for commit 50e68d81afa8b5ceb332358d36a7d156d31cfb80):

julia> using Aqua, Nemo ; Aqua.test_piracies(Nemo);

Welcome to Nemo version 0.45.0

Nemo comes with absolutely no warranty whatsoever
Possible type-piracy detected:
[1] ^(a::T, n::Union{Integer, ZZRingElem}) where T<:RingElem @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMiscInteger.jl:279
[2] _order(G::AbstractAlgebra.Group) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/Nemo.jl:590
[3] _order(g::GroupElem) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/Nemo.jl:591
[4] divrem(f::PolyRingElem{T}, g::PolyRingElem{T}) where T<:RingElem @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMiscPoly.jl:441
[5] eigvals(M::MatElem{T}) where T<:FieldElem @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/matrix.jl:253
[6] eigvals(L::Field, M::MatElem{T}) where T<:RingElem @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/matrix.jl:280
[7] factor(a::T) where T<:Union{Int64, UInt64} @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/flint/fmpz.jl:1478
[8] factor_squarefree(f::PolyRingElem{<:FieldElement}) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMiscPoly.jl:314
[9] gcd(a::ResElem{T}, b::ResElem{T}) where T<:Union{Integer, ZZRingElem} @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMoreStuff.jl:587
[10] gcdx(a::ResElem{T}, b::ResElem{T}) where T<:Union{Integer, ZZRingElem} @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMoreStuff.jl:592
[11] image(M::Map{D, C}, a) where {D, C} @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMoreStuff.jl:1099
[12] is_power(a::Rational) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMiscInteger.jl:162
[13] is_power(a::Integer) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMiscInteger.jl:141
[14] is_squarefree(f::PolyRingElem{<:FieldElement}) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMiscPoly.jl:497
[15] is_squarefree(f::PolyRingElem{<:RingElement}) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMiscPoly.jl:517
[16] is_squarefree(n::Union{Int64, ZZRingElem}) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMiscInteger.jl:221
[17] isdiag(A::MatElem) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMiscMatrix.jl:468
[18] mod(f::PolyRingElem{T}, g::PolyRingElem{T}) where T<:RingElem @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMiscPoly.jl:414
[19] mulmod(a::UInt64, b::UInt64, n::UInt64, ni::UInt64) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMiscInteger.jl:16
[20] preimage(M::Map{D, C}, a) where {D, C} @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMoreStuff.jl:1090
[21] preimage_map(k::T, K::T) where T<:FinField @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/embedding/embedding.jl:444
[22] remove(a::BigInt, b::BigInt) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/flint/fmpz.jl:1733
[23] remove(a::UInt64, b::UInt64) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/flint/fmpz.jl:1716
[24] remove(a::Int64, b::Int64) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/flint/fmpz.jl:1727
[25] remove(x::Integer, y::Integer) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/flint/fmpz.jl:1743
[26] root(a::FinFieldElem, n::Integer) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMoreStuff.jl:1299
[27] setprecision(x::BigFloat, p::Int64) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMoreStuff.jl:430
[28] valuation(a::UInt64, b::UInt64) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/HeckeMoreStuff.jl:148
[29] valuation(x::Integer, y::Integer) @ Nemo ~/Projekte/OSCAR/Nemo.jl/src/flint/fmpz.jl:1763
fingolfin commented 10 months ago

@lgoettgens with the move of stuff from Hecke to here, we are now at 122 reported cases of piracy :-(. Quit a lot of that hints at things which really should be moved to AbstractAlgebra. To pick a random example:

function matrix(A::Matrix{T}) where {T<:RingElem}
    r, c = size(A)
    (r < 0 || c < 0) && error("Array must be non-empty")
    m = matrix(parent(A[1, 1]), A)
    return m
end

function matrix(A::Vector{T}) where {T<:RingElem}
    return matrix(reshape(A, length(A), 1))
end

export scalar_matrix

function scalar_matrix(R::Ring, n::Int, a::RingElement)
    b = R(a)
    z = zero_matrix(R, n, n)
    for i in 1:n
        z[i, i] = b
    end
    return z
end

Any chance you might be interested to look into that? 😜

lgoettgens commented 10 months ago

@lgoettgens with the move of stuff from Hecke to here, we are now at 122 reported cases of piracy :-(.

With #1530, there will be even more.

Any chance you might be interested to look into that? 😜

I can totally do that, but I cannot say right now if next week or the week after. Having #1530 until then would be great :)

lgoettgens commented 10 months ago

1531 reduces the number of reported type piracies from 140 to 29 :tada: