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 warnings raised by linter #3273

Merged
merged 5 commits into from
Apr 16, 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
2 changes: 1 addition & 1 deletion benchmark/supports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ for set_type in (Ball1, BallInf, Hyperrectangle)
for n in (2, 10, 100, 1000)
rng = MersenneTwister(n)
d = rand(rng, n)
X = rand(set_type, dim=n, rng=rng)
X = LazySets.rand(set_type, dim=n, rng=rng)
SUITE["ρ"][string(set_type), "dense", n] = @benchmarkable ρ($d, $X)
SUITE["σ"][string(set_type), "dense", n] = @benchmarkable σ($d, $X)
A = tridiagm(1, -2, 0.5, n)
Expand Down
2 changes: 1 addition & 1 deletion src/ConcreteOperations/convex_hull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ end
function _convex_hull_2d!(points::Vector{VN};
algorithm="monotone_chain"
) where {N, VN<:AbstractVector{N}}
if algorithm == nothing
if isnothing(algorithm)
algorithm = default_convex_hull_algorithm(points)
end
if algorithm == "monotone_chain"
Expand Down
2 changes: 1 addition & 1 deletion src/ConcreteOperations/isdisjoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ function _isdisjoint_polyhedron(P::AbstractPolyhedron, X::LazySet,
end
clist_P = _normal_Vector(P) # TODO
clist_X = _normal_Vector(X) # TODO
if solver == nothing
if isnothing(solver)
solver = default_lp_solver(N)
end
return _isempty_polyhedron_lp([clist_P; clist_X], witness; solver=solver)
Expand Down
13 changes: 7 additions & 6 deletions src/ConcreteOperations/issubset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ function ⊆(∅::EmptySet, X::LazySet, witness::Bool=false)
return _issubset_emptyset(∅, X, witness)
end

function _issubset_emptyset(∅, X, witness)
function _issubset_emptyset(∅::EmptySet, X::LazySet, witness::Bool=false)
N = promote_type(eltype(∅), eltype(X))
return witness ? (true, N[]) : true
end
Expand Down Expand Up @@ -867,7 +867,7 @@ function ⊆(X::LazySet, ∅::EmptySet, witness::Bool=false)
return _issubset_in_emptyset(X, ∅, witness)
end

function _issubset_in_emptyset(X, ∅, witness)
function _issubset_in_emptyset(X::LazySet, ∅::EmptySet, witness::Bool=false)
if isempty(X)
N = promote_type(eltype(∅), eltype(X))
return witness ? (true, N[]) : true
Expand Down Expand Up @@ -987,7 +987,7 @@ function ⊆(X::LazySet, U::Universe, witness::Bool=false)
return _issubset_universe(X, U, witness)
end

function _issubset_universe(X, U, witness)
function _issubset_universe(X::LazySet, U::Universe, witness::Bool=false)
if !witness
return true
end
Expand All @@ -998,7 +998,8 @@ end
# disambiguations
for ST in [:AbstractPolytope, :AbstractHyperrectangle, :AbstractSingleton,
:LineSegment, :EmptySet, :UnionSet, :UnionSetArray]
@eval ⊆(X::($ST), U::Universe, witness::Bool=false) = _issubset_universe(X, U, witness)
@eval ⊆(X::($ST), U::Universe, witness::Bool=false) =
_issubset_universe(X, U, witness)
end

"""
Expand All @@ -1025,7 +1026,7 @@ compute a witness.

We fall back to `isuniversal(X)`.
"""
function ⊆(U::Universe, X::LazySet, witness::Bool=false)
function ⊆(::Universe, X::LazySet, witness::Bool=false)
return isuniversal(X, witness)
end

Expand All @@ -1037,7 +1038,7 @@ end
# disambiguations
for ST in [:AbstractPolyhedron, :AbstractPolytope, :AbstractHyperrectangle,
:AbstractSingleton, :EmptySet, :UnionSetArray, :Complement]
@eval ⊆(U::Universe, X::($ST), witness::Bool=false) = isuniversal(X, witness)
@eval ⊆(::Universe, X::($ST), witness::Bool=false) = isuniversal(X, witness)
end

"""
Expand Down
6 changes: 3 additions & 3 deletions src/ConcreteOperations/minkowski_sum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ function _minkowski_sum_hrep(A::AbstractMatrix, b::AbstractVector,
C::AbstractMatrix, d::AbstractVector;
backend=nothing, algorithm=nothing, prune=true)

if backend == nothing
if isnothing(backend)
N = promote_type(eltype(A), eltype(b), eltype(C), eltype(d))
backend = default_cddlib_backend(N)
end

if algorithm == nothing
if isnothing(algorithm)
algorithm = Polyhedra.FourierMotzkin()
elseif !(algorithm isa Polyhedra.EliminationAlgorithm)
error("algorithm $algorithm is not a valid elimination algorithm; " *
Expand Down Expand Up @@ -433,7 +433,7 @@ function _minkowski_sum_vrep_nd(vlist1::Vector{VT}, vlist2::Vector{VT};
end
end
if apply_convex_hull
if backend == nothing
if isnothing(backend)
require(@__MODULE__, :Polyhedra; fun_name="minkowski_sum")
backend = default_polyhedra_backend_nd(N)
solver = default_lp_solver_polyhedra(N)
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/AbstractHyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ function split(H::AbstractHyperrectangle{N},
centers = Vector{StepRangeLen{N}}(undef, dim(H))
@inbounds for (i, m) in enumerate(num_blocks)
if m <= 0
throw(ArgumentError(m, "each dimension needs at least one block"))
throw(ArgumentError("each dimension needs at least one block, got $m"))
elseif m == one(N)
centers[i] = range(lo[i] + radius[i], length=1)
else
Expand Down
14 changes: 7 additions & 7 deletions src/Interfaces/AbstractPolyhedron_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end
# default LP solver for Polyhedra (fallback method)
# NOTE: exists in parallel to `default_lp_solver` because we use different
# interfaces (see #1493)
function default_lp_solver_polyhedra(N, varargs...)
function default_lp_solver_polyhedra(N; kwargs...)
require(@__MODULE__, :Polyhedra; fun_name="default_lp_solver_polyhedra")
error("no default solver for numeric type $N")
end
Expand Down Expand Up @@ -416,11 +416,11 @@ end

function _get_elimination_instance(N, backend, elimination_method)
require(@__MODULE__, :Polyhedra; fun_name="linear_map with elimination")
if backend == nothing
if isnothing(backend)
require(@__MODULE__, :CDDLib; fun_name="linear_map with elimination")
backend = default_cddlib_backend(N)
end
if elimination_method == nothing
if isnothing(elimination_method)
elimination_method = Polyhedra.BlockElimination()
end
return LinearMapElimination(backend, elimination_method)
Expand Down Expand Up @@ -647,12 +647,12 @@ function _linear_map_polyhedron(M::AbstractMatrix{NM},
size(M, 2) != dim(P) && throw(ArgumentError("a linear map of size " *
"$(size(M)) cannot be applied to a set of dimension $(dim(P))"))

got_algorithm = algorithm != nothing
got_algorithm = !isnothing(algorithm)
got_inv = got_algorithm && (algorithm == "inv" || algorithm == "inverse")
got_inv_right = got_algorithm && (algorithm ==
"inv_right" || algorithm == "inverse_right")

if inverse != nothing
if !isnothing(inverse)
if !got_algorithm || got_inv
algo = LinearMapInverse(inverse)
elseif got_inv_right
Expand Down Expand Up @@ -726,7 +726,7 @@ function _linear_map_vrep(M::AbstractMatrix, P::AbstractPolyhedron,

P_hpoly = HPolytope(constraints_list(P), check_boundedness=false)
backend = algo.backend
if backend == nothing
if isnothing(backend)
backend = default_polyhedra_backend(P)
end
P = tovrep(P_hpoly, backend=backend)
Expand Down Expand Up @@ -1168,7 +1168,7 @@ function project(P::AbstractPolyhedron{N}, block::AbstractVector{Int};
elseif status == 1
# simple projection of half-space
hs = HalfSpace(c.a[block], c.b)
if clist == nothing
if isnothing(clist)
clist = [hs] # get the right type of the constraints
else
push!(clist, hs)
Expand Down
4 changes: 2 additions & 2 deletions src/Interfaces/AbstractZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function genmat_fallback(Z::AbstractZonotope{N};
gens=generators(Z), ngens=nothing) where {N}
if isempty(gens)
return Matrix{N}(undef, dim(Z), 0)
elseif ngens == nothing
elseif isnothing(ngens)
return _genmat_fallback_generic(Z, gens)
else
return _genmat_fallback_ngens(Z, gens, ngens)
Expand Down Expand Up @@ -280,7 +280,7 @@ function ∈(x::AbstractVector, Z::AbstractZonotope; solver=nothing)
sense = ['>'; fill('=', n)]
obj = [one(N); zeros(N, p)]

if solver == nothing
if isnothing(solver)
solver = default_lp_solver(N)
end
lp = linprog(obj, A, sense, b, lbounds, ubounds, solver)
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/LazySet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ function _isempty_polyhedron_polyhedra(P::LazySet{N}, witness::Bool=false;
require(@__MODULE__, :Polyhedra; fun_name="isempty",
explanation="with the active option `use_polyhedra_interface`")

if backend == nothing
if isnothing(backend)
backend = default_polyhedra_backend(P)
end

Expand Down
2 changes: 1 addition & 1 deletion src/LazyOperations/Intersection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ function _projection(ℓ, X::S, H::Union{Hyperplane{N}, Line2D{N}};
Xnℓ = lazy_linear_map ? LinearMap(Πnℓ, X) : linear_map(Πnℓ, X)
Xnℓ⋂Lγ = lazy_2d_intersection ? Intersection(Xnℓ, Lγ) : intersection(Xnℓ, Lγ)

if algorithm_2d_intersection == nothing
if isnothing(algorithm_2d_intersection)
return ρ(y_dir, Xnℓ⋂Lγ; kwargs...)
else
return ρ(y_dir, Xnℓ⋂Lγ, algorithm=algorithm_2d_intersection; kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/LazyOperations/Rectification.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ isoperationtype(::Type{<:Rectification}) = true
isconvextype(::Type{<:Rectification}) = false

function _compute_exact_representation!(R::Rectification)
if R.cache.set == nothing
if isnothing(R.cache.set)
R.cache.set = to_union_of_projections(R)
end
return R.cache.set
Expand Down
4 changes: 2 additions & 2 deletions src/Plotting/mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function plot3d(S::LazySet; backend=default_polyhedra_backend(S), alpha=1.0,
transparency=true, visible=true)
require(@__MODULE__, [:Makie, :Polyhedra]; fun_name="plot3d")

if colorrange == nothing
if isnothing(colorrange)
colorrange = Automatic()
end
P_poly_mesh = _plot3d_helper(S, backend)
Expand Down Expand Up @@ -152,7 +152,7 @@ function plot3d!(S::LazySet; backend=default_polyhedra_backend(S), alpha=1.0,
transparency=true, visible=true)
require(@__MODULE__, [:Makie, :Polyhedra]; fun_name="plot3d!")

if colorrange == nothing
if isnothing(colorrange)
colorrange = Automatic()
end
P_poly_mesh = _plot3d_helper(S, backend)
Expand Down
2 changes: 1 addition & 1 deletion src/Sets/HPolyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ end

# construct the solution from the solver's ray result
function _σ_unbounded_lp(d, P::HPoly{N}, lp) where {N}
if lp == nothing
if isnothing(lp)
ray = d
elseif has_lp_infeasibility_ray(lp.model)
ray = lp.sol # infeasibility ray is stored as the solution
Expand Down
4 changes: 2 additions & 2 deletions src/Sets/HPolytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ function vertices_list(P::HPolytope;
N = eltype(P)
if isempty(P.constraints)
return Vector{N}(Vector{N}(undef, 0)) # illegal polytope
elseif dim(P) == 2 && backend == nothing
elseif dim(P) == 2 && isnothing(backend)
# use efficient 2D implementation
return vertices_list(convert(HPolygon, P, prune=prune))
else
require(@__MODULE__, :Polyhedra; fun_name="vertices_list")
if backend == nothing
if isnothing(backend)
backend = default_polyhedra_backend(P)
end
Q = polyhedron(P; backend=backend)
Expand Down
6 changes: 3 additions & 3 deletions src/Sets/VPolytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,12 @@ function remove_redundant_vertices(P::VPolytope{N};
backend=nothing,
solver=nothing) where {N}
require(@__MODULE__, :Polyhedra; fun_name="remove_redundant_vertices")
if backend == nothing
if isnothing(backend)
backend = default_polyhedra_backend(P)
end
Q = polyhedron(P; backend=backend)
if Polyhedra.supportssolver(typeof(Q))
if solver == nothing
if isnothing(solver)
solver = default_lp_solver_polyhedra(N)
end
vQ = Polyhedra.vrep(Q)
Expand Down Expand Up @@ -555,7 +555,7 @@ function polyhedron(P::VPolytope;
backend=default_polyhedra_backend(P),
relative_dimension=nothing)
if isempty(P)
if relative_dimension == nothing
if isnothing(relative_dimension)
error("the conversion to a `Polyhedra.polyhedron` requires the " *
"(relative) dimension of the `VPolytope` to be known, but it " *
"cannot be inferred from an empty set; use the keyword " *
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/helper_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function implementing_sets(op::Function;
if type_args isa Type
augmented_set_type = set_type{type_args}
else
@assert type_args == nothing "for binary functions, " *
@assert isnothing(type_args) "for binary functions, " *
"`type_args` must not be a list"
end
catch e
Expand Down Expand Up @@ -164,7 +164,7 @@ function _implementing_sets_unary!(dict, op, signature, index, type_args)
try
if type_args isa Type
augmented_set_type = set_type{type_args}
elseif type_args != nothing
elseif !isnothing(type_args)
augmented_set_type = set_type{type_args...}
end
catch e
Expand Down
1 change: 1 addition & 0 deletions test/Sets/Hyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ for N in [Float64, Rational{Int}, Float32]
H = Hyperrectangle(N[0, 0], N[1, 2])
S = split(H, [2, 2])
@test S isa Vector{typeof(H)}
@test_throws ArgumentError split(H, [0, 4])
H = Hyperrectangle(SA[N(0), N(0)], SA[N(1), N(2)])
S = split(H, [2, 2])
@test S isa Vector{typeof(H)}
Expand Down
2 changes: 1 addition & 1 deletion test/Sets/Zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ for N in [Float64, Rational{Int}, Float32]
if N<:AbstractFloat || test_suite_polyhedra
@test isequivalent(Z, Z2)
end
if G2 != nothing
if !isnothing(G2)
@test genmat(remove_redundant_generators(Z)) == G2
end

Expand Down