Skip to content
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

Adress some more JET warnings #1709

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/PrettyPrinting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function show_obj(io::IO, mi::MIME, obj)
finish(S)
end

global _html_as_latex = Ref(false)
global _html_as_latex = Ref{Bool}(false)

@doc raw"""
get_html_as_latex()
Expand Down Expand Up @@ -552,8 +552,8 @@ end
#
################################################################################

mutable struct printer
io::IO
mutable struct printer{IOT <: IO}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes all functions using this printer thing type-stable (as they eventually access the underlying IO)

io::IOT
array::Vector{String}

# if terse_level is positive we print a+b instead of a + b
Expand All @@ -565,7 +565,7 @@ end
function printer(io::IO)
terse_level = get(io, :terse_level, 0)
size_limit = get(io, :size_limit, -1)
return printer(io, String[], terse_level, Int[size_limit])
return printer{typeof(io)}(io, String[], terse_level, Int[size_limit])
end

# TODO since the subexpressions are not changing much, cache the leaf_count
Expand Down
10 changes: 5 additions & 5 deletions src/generic/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ number_of_generators(a::MPolyRing) = a.num_vars
function gen(a::MPolyRing{T}, i::Int, ::Val{:lex}) where {T <: RingElement}
n = nvars(a)
@boundscheck 1 <= i <= n || throw(ArgumentError("variable index out of range"))
return a([one(base_ring(a))], reshape([UInt(j == n - i + 1)
return a([one(base_ring(a))], reshape(UInt[UInt(j == n - i + 1)
for j = 1:n], n, 1))
end

function gen(a::MPolyRing{T}, i::Int, ::Val{:deglex}) where {T <: RingElement}
n = nvars(a)
@boundscheck 1 <= i <= n || throw(ArgumentError("variable index out of range"))
return a([one(base_ring(a))], reshape([[UInt(j == n - i + 1)
for j in 1:n]..., UInt(1)], n + 1, 1))
return a([one(base_ring(a))], reshape(UInt[(UInt(j == n - i + 1)
for j in 1:n)..., UInt(1)], n + 1, 1))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The input of reshape got inferred as Vector{Any}. This additional type annot helps. And additionally, I got rid of some allocations by not creating the inner vector.

end

function gen(a::MPolyRing{T}, i::Int, ::Val{:degrevlex}) where {T <: RingElement}
n = nvars(a)
@boundscheck 1 <= i <= n || throw(ArgumentError("variable index out of range"))
return a([one(base_ring(a))], reshape([[UInt(j == i)
for j in 1:n]..., UInt(1)], n + 1, 1))
return a([one(base_ring(a))], reshape(UInt[(UInt(j == i)
for j in 1:n)..., UInt(1)], n + 1, 1))
end

@doc raw"""
Expand Down
4 changes: 2 additions & 2 deletions src/generic/Residue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ function (a::EuclideanRingResidueRing{T})(b::Integer) where {T <: RingElement}
end

function (a::EuclideanRingResidueRing{T})(b::T) where {T <: RingElem}
base_ring(a) != parent(b) && error("Operation on incompatible objects")
base_ring(a) !== parent(b) && error("Operation on incompatible objects")
z = EuclideanRingResidueRingElem{T}(mod(b, modulus(a)))
z.parent = a
return z
end

function (a::EuclideanRingResidueRing{T})(b::AbstractAlgebra.ResElem{T}) where {T <: RingElement}
a != parent(b) && error("Operation on incompatible objects")
a !== parent(b) && error("Operation on incompatible objects")
return b
end

Expand Down
28 changes: 14 additions & 14 deletions src/generic/UnivPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function is_exact_type(::Type{T}) where {S <: RingElement, U <: MPolyRingElem{S}
return is_exact_type(S)
end

parent(p::UnivPoly) = p.parent
parent(p::UnivPoly) = p.parent::parent_type(p)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow julia couldn't infer p.parent properly, the second type param (the MPolyRing) abstract. Additionally use this accessor everywhere in this file instead of direct access


elem_type(::Type{UniversalPolyRing{T, U}}) where {T <: RingElement, U <: AbstractAlgebra.MPolyRingElem{T}} =
UnivPoly{T, U}
Expand Down Expand Up @@ -252,7 +252,7 @@ function gen(S::UniversalPolyRing{T, U}, s::VarName) where {T <: RingElement, U
i = findfirst(==(Symbol(s)), S.S)
if i === nothing
push!(S.S, Symbol(s))
S.mpoly_ring = MPolyRing{T}(S.base_ring, S.S, S.ord, false)
S.mpoly_ring = MPolyRing{T}(base_ring(S), S.S, S.ord, false)
i = length(S.S)
end
return UnivPoly{T, U}(gen(mpoly_ring(S), i), S)
Expand Down Expand Up @@ -297,7 +297,7 @@ function Base.hash(p::UnivPoly, h::UInt)
end

function deepcopy_internal(p::UnivPoly{T, U}, dict::IdDict) where {T, U}
return UnivPoly{T, U}(deepcopy_internal(p.p, dict), p.parent)
return UnivPoly{T, U}(deepcopy_internal(p.p, dict), parent(p))
end

###############################################################################
Expand Down Expand Up @@ -355,7 +355,7 @@ end
###############################################################################

function -(p::UnivPoly{T, U}) where {T, U}
return UnivPoly{T, U}(-p.p, p.parent)
return UnivPoly{T, U}(-p.p, parent(p))
end

###############################################################################
Expand All @@ -377,19 +377,19 @@ end
function +(a::UnivPoly{T, U}, b::UnivPoly{T, U}) where {T, U}
check_parent(a, b)
a, b = univ_promote(a, b)
return UnivPoly{T, U}(a.p + b.p, a.parent)
return UnivPoly{T, U}(a.p + b.p, parent(a))
end

function -(a::UnivPoly{T, U}, b::UnivPoly{T, U}) where {T, U}
check_parent(a, b)
a, b = univ_promote(a, b)
return UnivPoly{T, U}(a.p - b.p, a.parent)
return UnivPoly{T, U}(a.p - b.p, parent(a))
end

function *(a::UnivPoly{T, U}, b::UnivPoly{T, U}) where {T, U}
check_parent(a, b)
a, b = univ_promote(a, b)
return UnivPoly{T, U}(a.p*b.p, a.parent)
return UnivPoly{T, U}(a.p*b.p, parent(a))
end

###############################################################################
Expand Down Expand Up @@ -680,14 +680,14 @@ end
function divexact(a::UnivPoly{T, U}, b::UnivPoly{T, U}; check::Bool=true) where {T, U}
check_parent(a, b)
a, b = univ_promote(a, b)
return UnivPoly{T, U}(divexact(a.p, b.p; check=check), a.parent)
return UnivPoly{T, U}(divexact(a.p, b.p; check=check), parent(a))
end

function divides(a::UnivPoly{T, U}, b::UnivPoly{T, U}) where {T, U}
check_parent(a, b)
a, b = univ_promote(a, b)
flag, q = divides(a.p, b.p)
return flag, UnivPoly{T, U}(q, a.parent)
return flag, UnivPoly{T, U}(q, parent(a))
end

###############################################################################
Expand All @@ -699,14 +699,14 @@ end
function Base.div(a::UnivPoly{T, U}, b::UnivPoly{T, U}) where {T, U}
check_parent(a, b)
a, b = univ_promote(a, b)
return UnivPoly{T, U}(div(a.p, b.p), a.parent)
return UnivPoly{T, U}(div(a.p, b.p), parent(a))
end

function Base.divrem(a::UnivPoly{T, U}, b::UnivPoly{T, U}) where {T, U}
check_parent(a, b)
a, b = univ_promote(a, b)
q, r = divrem(a.p, b.p)
return UnivPoly{T, U}(q, a.parent), UnivPoly{T, U}(r, a.parent)
return UnivPoly{T, U}(q, parent(a)), UnivPoly{T, U}(r, parent(a))
end

###############################################################################
Expand All @@ -720,7 +720,7 @@ function derivative(p::UnivPoly{T, U}, j::Int) where {T, U}
if j > nvars(parent(p.p))
return zero(parent(p))
end
return UnivPoly{T, U}(derivative(p.p, j), p.parent)
return UnivPoly{T, U}(derivative(p.p, j), parent(p))
end

function derivative(p::UnivPoly{T, U}, x::UnivPoly{T, U}) where {T, U}
Expand Down Expand Up @@ -872,13 +872,13 @@ end
function gcd(a::UnivPoly{T, U}, b::UnivPoly{T, U}) where {T <: RingElement, U}
check_parent(a, b)
a, b = univ_promote(a, b)
return UnivPoly{T, U}(gcd(a.p, b.p), a.parent)
return UnivPoly{T, U}(gcd(a.p, b.p), parent(a))
end

function lcm(a::UnivPoly{T, U}, b::UnivPoly{T, U}) where {T <: RingElement, U}
check_parent(a, b)
a, b = univ_promote(a, b)
return UnivPoly{T, U}(lcm(a.p, b.p), a.parent)
return UnivPoly{T, U}(lcm(a.p, b.p), parent(a))
end

###############################################################################
Expand Down
Loading