From ecddca8421ee6d5bd8121f815e3bdf76f2fafe92 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 27 Oct 2023 15:17:07 +0200 Subject: [PATCH] Fix a bunch of issues reported by JET.jl --- src/NemoStuff.jl | 4 ---- src/PrettyPrinting.jl | 4 ++-- src/algorithms/MPolyEvaluate.jl | 5 +++-- src/algorithms/MPolyFactor.jl | 2 +- src/error.jl | 4 ++-- src/generic/GenericTypes.jl | 3 +-- src/generic/Ideal.jl | 2 +- src/generic/PermGroups.jl | 12 +++++++----- src/generic/PriorityQueue.jl | 20 ++------------------ 9 files changed, 19 insertions(+), 37 deletions(-) diff --git a/src/NemoStuff.jl b/src/NemoStuff.jl index 64825d5a87..a518f83d8c 100644 --- a/src/NemoStuff.jl +++ b/src/NemoStuff.jl @@ -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 diff --git a/src/PrettyPrinting.jl b/src/PrettyPrinting.jl index 15b6ad0a59..4ecdc8a914 100644 --- a/src/PrettyPrinting.jl +++ b/src/PrettyPrinting.jl @@ -667,7 +667,7 @@ function compare_op_string(mi::MIME, op) if op === :(==) return "=" else - return string(op) + return string(op)::String end end @@ -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 diff --git a/src/algorithms/MPolyEvaluate.jl b/src/algorithms/MPolyEvaluate.jl index 3ff2e5c062..77d7d6a9fc 100644 --- a/src/algorithms/MPolyEvaluate.jl +++ b/src/algorithms/MPolyEvaluate.jl @@ -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 ) @@ -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) diff --git a/src/algorithms/MPolyFactor.jl b/src/algorithms/MPolyFactor.jl index f8eeef6fe2..80e878f6a1 100644 --- a/src/algorithms/MPolyFactor.jl +++ b/src/algorithms/MPolyFactor.jl @@ -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 diff --git a/src/error.jl b/src/error.jl index 3db749cf69..e98674f7a1 100644 --- a/src/error.jl +++ b/src/error.jl @@ -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 diff --git a/src/generic/GenericTypes.jl b/src/generic/GenericTypes.jl index bc550c5f6d..2c09e3cb59 100644 --- a/src/generic/GenericTypes.jl +++ b/src/generic/GenericTypes.jl @@ -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 @@ -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 diff --git a/src/generic/Ideal.jl b/src/generic/Ideal.jl index a3f100c7de..8a9e41e099 100644 --- a/src/generic/Ideal.jl +++ b/src/generic/Ideal.jl @@ -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, "[") diff --git a/src/generic/PermGroups.jl b/src/generic/PermGroups.jl index e758923b66..def2b25e1b 100644 --- a/src/generic/PermGroups.jl +++ b/src/generic/PermGroups.jl @@ -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 @@ -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] @@ -331,7 +333,7 @@ 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, "()") @@ -339,7 +341,7 @@ function _print_perm(io::IO, p::Perm, width::Integer=last(displaysize(io))) 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, ")") @@ -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 diff --git a/src/generic/PriorityQueue.jl b/src/generic/PriorityQueue.jl index 131294352e..94b46b7b75 100644 --- a/src/generic/PriorityQueue.jl +++ b/src/generic/PriorityQueue.jl @@ -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 @@ -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)