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

Fix a bunch of issues reported by JET.jl #1473

Merged
merged 1 commit into from
Oct 27, 2023
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
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

Copy link
Collaborator

Choose a reason for hiding this comment

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

why do you delete this?

Copy link
Member

Choose a reason for hiding this comment

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

I think @lgoettgens wanted to delete this before and I objected with some argument, which I don't want to rehash again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because JET complained because there is no method for zero_matrix taking a ring and a single integer... which is correct, at least for AA...

Of course we could add such a thing if people think this is useful, but maybe not?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would find this useful. identity_matrix needs a single Int as well, so why not just add it

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 @@
end
t[1 + i] = c
while length(t) > 0 && iszero(t[end])
popback!(t)
pop!(t)

Check warning on line 55 in src/algorithms/MPolyFactor.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/MPolyFactor.jl#L55

Added line #L55 was not covered by tests
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 @@
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 @@
@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]

Check warning on line 1113 in src/generic/GenericTypes.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/GenericTypes.jl#L1113

Added line #L1113 was not covered by tests
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 @@
end

# print a vector of nodes
function show(io::IO, B::Vector{lmnode})
function show(io::IO, B::Vector{<:lmnode})

Check warning on line 241 in src/generic/Ideal.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/Ideal.jl#L241

Added line #L241 was not covered by tests
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 @@
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 @@
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 @@
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 @@
if n < 0
return inv(g)^-n
elseif n == 0
return Perm(T(length(g.d)))
return Perm(I(length(g.d)))

Check warning on line 497 in src/generic/PermGroups.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/PermGroups.jl#L497

Added line #L497 was not covered by tests
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 @@
# 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)

Check warning on line 98 in src/generic/PriorityQueue.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/PriorityQueue.jl#L98

Added line #L98 was not covered by tests
end

# Construction inferring Key/Value types from input
Expand All @@ -112,15 +104,7 @@
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
Loading