diff --git a/benchmark/supports.jl b/benchmark/supports.jl index 23dd55bc75..b65738dfb0 100644 --- a/benchmark/supports.jl +++ b/benchmark/supports.jl @@ -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) diff --git a/src/ConcreteOperations/convex_hull.jl b/src/ConcreteOperations/convex_hull.jl index 55b7e8df20..51cc983f98 100644 --- a/src/ConcreteOperations/convex_hull.jl +++ b/src/ConcreteOperations/convex_hull.jl @@ -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" diff --git a/src/ConcreteOperations/isdisjoint.jl b/src/ConcreteOperations/isdisjoint.jl index 47ad3fff38..1876b56c85 100644 --- a/src/ConcreteOperations/isdisjoint.jl +++ b/src/ConcreteOperations/isdisjoint.jl @@ -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) diff --git a/src/ConcreteOperations/issubset.jl b/src/ConcreteOperations/issubset.jl index 13b65e829b..b5667fa354 100644 --- a/src/ConcreteOperations/issubset.jl +++ b/src/ConcreteOperations/issubset.jl @@ -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 @@ -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 @@ -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 @@ -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 """ @@ -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 @@ -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 """ diff --git a/src/ConcreteOperations/minkowski_sum.jl b/src/ConcreteOperations/minkowski_sum.jl index 75fadf15c5..ff4ebc0925 100644 --- a/src/ConcreteOperations/minkowski_sum.jl +++ b/src/ConcreteOperations/minkowski_sum.jl @@ -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; " * @@ -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) diff --git a/src/Interfaces/AbstractHyperrectangle.jl b/src/Interfaces/AbstractHyperrectangle.jl index 8e7a4e82bc..f659476887 100644 --- a/src/Interfaces/AbstractHyperrectangle.jl +++ b/src/Interfaces/AbstractHyperrectangle.jl @@ -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 diff --git a/src/Interfaces/AbstractPolyhedron_functions.jl b/src/Interfaces/AbstractPolyhedron_functions.jl index f155566834..75a66e7b39 100644 --- a/src/Interfaces/AbstractPolyhedron_functions.jl +++ b/src/Interfaces/AbstractPolyhedron_functions.jl @@ -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 @@ -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) @@ -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 @@ -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) @@ -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) diff --git a/src/Interfaces/AbstractZonotope.jl b/src/Interfaces/AbstractZonotope.jl index 50a0bbfc41..e2498f2876 100644 --- a/src/Interfaces/AbstractZonotope.jl +++ b/src/Interfaces/AbstractZonotope.jl @@ -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) @@ -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) diff --git a/src/Interfaces/LazySet.jl b/src/Interfaces/LazySet.jl index 1c7409c356..64f4c8cc31 100644 --- a/src/Interfaces/LazySet.jl +++ b/src/Interfaces/LazySet.jl @@ -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 diff --git a/src/LazyOperations/Intersection.jl b/src/LazyOperations/Intersection.jl index 528e0e74aa..1e6a98c162 100644 --- a/src/LazyOperations/Intersection.jl +++ b/src/LazyOperations/Intersection.jl @@ -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...) diff --git a/src/LazyOperations/Rectification.jl b/src/LazyOperations/Rectification.jl index 887d394f31..79a90b4990 100644 --- a/src/LazyOperations/Rectification.jl +++ b/src/LazyOperations/Rectification.jl @@ -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 diff --git a/src/Plotting/mesh.jl b/src/Plotting/mesh.jl index b205a385b0..c8309bf841 100644 --- a/src/Plotting/mesh.jl +++ b/src/Plotting/mesh.jl @@ -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) @@ -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) diff --git a/src/Sets/HPolyhedron.jl b/src/Sets/HPolyhedron.jl index 814c81f0df..e22ce48e70 100644 --- a/src/Sets/HPolyhedron.jl +++ b/src/Sets/HPolyhedron.jl @@ -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 diff --git a/src/Sets/HPolytope.jl b/src/Sets/HPolytope.jl index 9b510701cc..e0eb295b6c 100644 --- a/src/Sets/HPolytope.jl +++ b/src/Sets/HPolytope.jl @@ -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) diff --git a/src/Sets/VPolytope.jl b/src/Sets/VPolytope.jl index d6403ddbc7..2db3f1172d 100644 --- a/src/Sets/VPolytope.jl +++ b/src/Sets/VPolytope.jl @@ -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) @@ -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 " * diff --git a/src/Utils/helper_functions.jl b/src/Utils/helper_functions.jl index 542307e6f0..97e2832bf7 100644 --- a/src/Utils/helper_functions.jl +++ b/src/Utils/helper_functions.jl @@ -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 @@ -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 diff --git a/test/Sets/Hyperrectangle.jl b/test/Sets/Hyperrectangle.jl index c4b6d7bc9d..273a1af48c 100644 --- a/test/Sets/Hyperrectangle.jl +++ b/test/Sets/Hyperrectangle.jl @@ -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)} diff --git a/test/Sets/Zonotope.jl b/test/Sets/Zonotope.jl index 4f7a982368..bbcff1bfd9 100644 --- a/test/Sets/Zonotope.jl +++ b/test/Sets/Zonotope.jl @@ -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