Skip to content

Commit

Permalink
Fix a bunch of issues reported by JET.jl (#1473)
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin authored Oct 27, 2023
1 parent 1885232 commit 3c9ad08
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 37 deletions.
4 changes: 0 additions & 4 deletions src/NemoStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ base_ring(::Vector{Int}) = Int
#
################################################################################

function zero_matrix(::Type{MatElem}, R::Ring, n::Int)
return zero_matrix(R, n)
end

function zero_matrix(::Type{MatElem}, R::Ring, n::Int, m::Int)
return zero_matrix(R, n, m)
end
Expand Down
4 changes: 2 additions & 2 deletions src/PrettyPrinting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ function compare_op_string(mi::MIME, op)
if op === :(==)
return "="
else
return string(op)
return string(op)::String
end
end

Expand All @@ -681,7 +681,7 @@ function compare_op_string(mi::MIME"text/latex", op)
elseif op === :(!=)
return "\\neq"
else
return string(op)
return string(op)::String
end
end

Expand Down
5 changes: 3 additions & 2 deletions src/algorithms/MPolyEvaluate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ end
# arithmetic between ctxB and ctxC should be in ctxA
function _evaluate_horner_non_rec(
ctxA::Ring,
Bcoeffs, Bexps::Vector{Vector{Int}},
Bcoeffs,
Bexps::Vector{Vector{Int}},
C::Vector,
ctxC::Ring
)
Expand Down Expand Up @@ -494,7 +495,7 @@ end

# should allow e to be mutated !!
function look_up(PC::PowerCache, e::Vector{Int})
all(x->(x==0), e) && return one(p[1])
all(x->(x==0), e) && return one(PC.p[1])
haskey(PC.power_cache, e) && return PC.power_cache[e]
e = deepcopy(e) # !!
if all(x->(x<=1), e)
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/MPolyFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function taylor_set_coeff!(t::Vector{E}, i::Int, c::E) where E
end
t[1 + i] = c
while length(t) > 0 && iszero(t[end])
popback!(t)
pop!(t)
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ struct NotInvertibleError{T, S} <: Exception
mod::S # ring or modulus with respect to which it could not be inverted
end

function NotInvertibleError(x::T, y::S) where {T <: RingElement, S}
function NotInvertibleError(x::T, y::S) where {T <: NCRingElement, S}
return NotInvertibleError{T, S}(x, y)
end

function NotInvertibleError(x::RingElement)
function NotInvertibleError(x::NCRingElement)
return NotInvertibleError(x, parent(x))
end

Expand Down
3 changes: 1 addition & 2 deletions src/generic/GenericTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ end
mutable struct SparsePolyRing{T <: RingElement} <: AbstractAlgebra.Ring
base_ring::Ring
S::Symbol
num_vars::Int

function SparsePolyRing{T}(R::Ring, s::Symbol, cached::Bool = true) where T <: RingElement
return get_cached!(SparsePolyID, (R, s), cached) do
Expand Down Expand Up @@ -1111,7 +1110,7 @@ function MatAlgElem{T}(R::NCRing, n::Int, A::Vector{T}) where T <: NCRingElement
@assert elem_type(R) === T
t = Matrix{T}(undef, n, n)
for i = 1:n, j = 1:n
t[i, j] = A[(i - 1) * c + j]
t[i, j] = A[(i - 1) * n + j]
end
return MatAlgElem{T}(R, t)
end
Expand Down
2 changes: 1 addition & 1 deletion src/generic/Ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function show_inner(io::IO, n::lmnode)
end

# print a vector of nodes
function show(io::IO, B::Vector{lmnode})
function show(io::IO, B::Vector{<:lmnode})
if print_node_level[] == 0
BB = extract_gens(B)
print(io, "[")
Expand Down
12 changes: 7 additions & 5 deletions src/generic/PermGroups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ function parity(g::Perm{T}) where T
to_visit = trues(size(g.d))
parity = false
k = 1
@inbounds while any(to_visit)
@inbounds while true
k = findnext(to_visit, k)
k !== nothing || break
to_visit[k] = false
next = g[k]
while next != k
Expand Down Expand Up @@ -217,8 +218,9 @@ function cycledec(v::Vector{T}) where T<:Integer
k = 1
i = 1

while any(to_visit)
while true
k = findnext(to_visit, k)
k !== nothing || break
to_visit[k] = false
next = v[k]

Expand Down Expand Up @@ -331,15 +333,15 @@ function Base.show(io::IO, g::Perm)
end
end

function _print_perm(io::IO, p::Perm, width::Integer=last(displaysize(io)))
function _print_perm(io::IO, p::Perm, width::Int=last(displaysize(io)))
@assert width > 3
if isone(p)
return print(io, "()")
else
cum_length = 0
for c in cycles(p)
length(c) == 1 && continue
cyc = join(c, ",")
cyc = join(c, ",")::String

if width - cum_length >= length(cyc)+2
print(io, "(", cyc, ")")
Expand Down Expand Up @@ -492,7 +494,7 @@ function power_by_squaring(g::Perm{I}, n::Integer) where {I}
if n < 0
return inv(g)^-n
elseif n == 0
return Perm(T(length(g.d)))
return Perm(I(length(g.d)))
elseif n == 1
return deepcopy(g)
elseif n == 2
Expand Down
20 changes: 2 additions & 18 deletions src/generic/PriorityQueue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,7 @@ PriorityQueue{K,V}(o::Ord, ps::Pair...) where {K,V,Ord<:Ordering} = PriorityQueu
# e.g., PriorityQueue{Int,Float64}([1=>1, 2=>2.0])
PriorityQueue{K,V}(kv) where {K,V} = PriorityQueue{K,V}(Forward, kv)
function PriorityQueue{K,V}(o::Ord, kv) where {K,V,Ord<:Ordering}
try
PriorityQueue{K,V,Ord}(o, kv)
catch e
if not_iterator_of_pairs(kv)
throw(ArgumentError("PriorityQueue(kv): kv needs to be an iterator of tuples or pairs"))
else
rethrow(e)
end
end
PriorityQueue{K,V,Ord}(o, kv)
end

# Construction inferring Key/Value types from input
Expand All @@ -112,15 +104,7 @@ end
PriorityQueue(o1::Ordering, o2::Ordering) = throw(ArgumentError("PriorityQueue with two parameters must be called with an Ordering and an iterable of pairs"))
PriorityQueue(kv, o::Ordering=Forward) = PriorityQueue(o, kv)
function PriorityQueue(o::Ordering, kv)
try
_priority_queue_with_eltype(o, kv, eltype(kv))
catch e
if not_iterator_of_pairs(kv)
throw(ArgumentError("PriorityQueue(kv): kv needs to be an iterator of tuples or pairs"))
else
rethrow(e)
end
end
_priority_queue_with_eltype(o, kv, eltype(kv))
end

_priority_queue_with_eltype(o::Ord, ps, ::Type{Pair{K,V}} ) where {K,V,Ord} = PriorityQueue{ K, V,Ord}(o, ps)
Expand Down

0 comments on commit 3c9ad08

Please sign in to comment.