Skip to content

Commit

Permalink
Merge pull request #3607 from JuliaReach/schillic/requires
Browse files Browse the repository at this point in the history
Rename `load_*` functions in set modules
  • Loading branch information
schillic authored Jul 22, 2024
2 parents bc129eb + 6dc5f59 commit fd1b70e
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/Initialization/init_Distributions.jl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
eval(load_distributions_samples())
eval(load_Distributions_sample())
2 changes: 1 addition & 1 deletion src/Sets/Ball2/init.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function __init__()
@require Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" eval(load_distributions_samples())
@require Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" eval(load_Distributions_sample())
end
10 changes: 4 additions & 6 deletions src/Sets/Ball2/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,15 @@ function _sample_unit_nball_muller!(D::Vector{Vector{N}}, n::Int, p::Int;
return _sample_unit_nball_muller_distributions!(D, n, p; rng=rng, seed=seed)
end

function load_distributions_samples()
function load_Distributions_sample()
return quote
using .Distributions: Uniform, Normal

function _sample_unit_nball_muller_distributions!(D::Vector{Vector{N}}, n::Int,
p::Int;
rng::AbstractRNG=GLOBAL_RNG,
seed::Union{Int,Nothing}=nothing) where {N}
rng = reseed!(rng, seed)
Zdims = [Normal() for _ in 1:n] # normal distributions for each dimension
Zrad = Uniform() # distribution to pick random radius
Zdims = [Distributions.Normal() for _ in 1:n] # normal distributions for each dimension
Zrad = Distributions.Uniform() # distribution to pick random radius
one_over_n = one(N) / n
v = Vector{N}(undef, n) # sample direction
@inbounds for j in 1:p
Expand All @@ -108,4 +106,4 @@ function load_distributions_samples()
return D
end
end
end # quote / load_distributions_samples()
end # load_Distributions_sample
12 changes: 6 additions & 6 deletions src/Sets/BallInf/genmat.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
function load_genmat_ballinf_static()
function load_StaticArraysCore_genmat()
return quote
using StaticArraysCore: SMatrix, SVector, MMatrix
using StaticArraysCore: SVector

function genmat(B::BallInf{N,SVector{L,N}}) where {L,N}
if isflat(B)
return SMatrix{L,0,N,0}()
return StaticArraysCore.SMatrix{L,0,N,0}()
else
gens = zeros(MMatrix{L,L})
gens = zeros(StaticArraysCore.MMatrix{L,L})
@inbounds for i in 1:L
gens[i, i] = B.radius
end
return SMatrix(gens)
return StaticArraysCore.SMatrix(gens)
end
end
end
end # quote / load_genmat_ballinf_static()
end # load_StaticArraysCore_genmat
2 changes: 1 addition & 1 deletion src/Sets/BallInf/init.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function __init__()
@require StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" eval(load_genmat_ballinf_static())
@require StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" eval(load_StaticArraysCore_genmat())
end
4 changes: 2 additions & 2 deletions src/Sets/HPolyhedron/HPolyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function load_Polyhedra_HPolyhedron()
end
end # load_Polyhedra_HPolyhedron

function load_symbolics_hpolyhedron()
function load_Symbolics_HPolyhedron()
return quote
using .Symbolics: Num
using ..LazySets: _get_variables, _vec, _is_halfspace, _is_hyperplane
Expand Down Expand Up @@ -140,4 +140,4 @@ function load_symbolics_hpolyhedron()
return HPolyhedron(expr, _vec(vars); N=N)
end
end
end # quote / load_symbolics_hpolyhedron()
end # load_Symbolics_HPolyhedron
2 changes: 1 addition & 1 deletion src/Sets/HPolyhedron/init.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function __init__()
@require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("init_LazySets.jl")
@require Polyhedra = "67491407-f73d-577b-9b50-8179a7c68029" include("init_Polyhedra.jl")
@require Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" eval(load_symbolics_hpolyhedron())
@require Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" eval(load_Symbolics_HPolyhedron())
end
4 changes: 2 additions & 2 deletions src/Sets/HPolytope/HPolytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function load_Polyhedra_HPolytope()
end
end # load_Polyhedra_HPolytope

function load_symbolics_hpolytope()
function load_Symbolics_HPolytope()
return quote
using .Symbolics: Num
using ..LazySets: _get_variables, _vec
Expand Down Expand Up @@ -161,4 +161,4 @@ function load_symbolics_hpolytope()
return HPolytope(expr, _vec(vars); N=N, check_boundedness=check_boundedness)
end
end
end # quote / load_symbolics_hpolytope()
end # load_Symbolics_HPolytope
2 changes: 1 addition & 1 deletion src/Sets/HPolytope/init.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function __init__()
@require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("init_LazySets.jl")
@require Polyhedra = "67491407-f73d-577b-9b50-8179a7c68029" include("init_Polyhedra.jl")
@require Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" eval(load_symbolics_hpolytope())
@require Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" eval(load_Symbolics_HPolytope())
end
14 changes: 7 additions & 7 deletions src/Sets/Hyperrectangle/genmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ function genmat(H::Hyperrectangle{N,<:AbstractVector,<:SparseVector{N}}) where {
return sparse(nze, 1:length(nze), nzv, n, length(nze))
end

function load_genmat_hyperrectangle_static()
function load_StaticArraysCore_genmat()
return quote
using .StaticArraysCore: SVector, MMatrix, SMatrix
using .StaticArraysCore: SVector

function genmat(H::Hyperrectangle{N,SVector{L,N},SVector{L,N}}) where {L,N}
gens = zeros(MMatrix{L,L,N})
gens = zeros(StaticArraysCore.MMatrix{L,L,N})
nzcol = Vector{Int}()
@inbounds for i in 1:L
r = H.radius[i]
Expand All @@ -19,18 +19,18 @@ function load_genmat_hyperrectangle_static()
end
end
m = length(nzcol)
return SMatrix{L,m}(view(gens, :, nzcol))
return StaticArraysCore.SMatrix{L,m}(view(gens, :, nzcol))
end

# this function is type stable, but it does not prune the generators
# according to flat dimensions of H
function _genmat_static(H::Hyperrectangle{N,SVector{L,N},SVector{L,N}}) where {L,N}
gens = zeros(MMatrix{L,L,N})
gens = zeros(StaticArraysCore.MMatrix{L,L,N})
@inbounds for i in 1:L
r = H.radius[i]
gens[i, i] = r
end
return SMatrix{L,L}(gens)
return StaticArraysCore.SMatrix{L,L}(gens)
end
end
end # quote / load_genmat_hyperrectangle_static()
end # load_StaticArraysCore_genmat
2 changes: 1 addition & 1 deletion src/Sets/Hyperrectangle/init.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function __init__()
@require IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" eval(load_IntervalArithmetic_convert())
@require StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" eval(load_genmat_hyperrectangle_static())
@require StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" eval(load_StaticArraysCore_genmat())
end
4 changes: 1 addition & 3 deletions src/Sets/SparsePolynomialZonotope/init_RangeEnclosures.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
using .RangeEnclosures: enclose

eval(load_RangeEnclosures_rho())
eval(load_RangeEnclosures_support_function())
6 changes: 3 additions & 3 deletions src/Sets/SparsePolynomialZonotope/support_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function ρ(d::AbstractVector, P::SparsePolynomialZonotope;
return _ρ_range_enclosures(d, P, enclosure_method)
end

function load_RangeEnclosures_rho()
function load_RangeEnclosures_support_function()
return quote
function _ρ_range_enclosures(d::AbstractVector, P::SparsePolynomialZonotope,
method::Union{RangeEnclosures.AbstractEnclosureAlgorithm,
Expand All @@ -48,8 +48,8 @@ function load_RangeEnclosures_rho()
f(x) = sum(d' * gi * prod(x .^ ei) for (gi, ei) in zip(eachcol(G), eachcol(E)))

dom = IA.IntervalBox(IA.interval(-1, 1), n)
res += IA.sup(enclose(f, dom, method))
res += IA.sup(RangeEnclosures.enclose(f, dom, method))
return res
end
end
end
end # load_RangeEnclosures_support_function
6 changes: 2 additions & 4 deletions src/Sets/Zonotope/init_StaticArraysCore.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
using StaticArraysCore: SMatrix, SVector, MMatrix, MVector

eval(load_split_static())
eval(load_reduce_order_static_zonotope())
eval(load_StaticArraysCore_split())
eval(load_StaticArraysCore_reduce_order())
7 changes: 4 additions & 3 deletions src/Sets/Zonotope/reduce_order.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
function load_reduce_order_static_zonotope()
function load_StaticArraysCore_reduce_order()
return quote
using .StaticArraysCore: MMatrix
using ..LazySets: AbstractReductionMethod

# conversion for static matrix
function reduce_order(Z::Zonotope{N,<:AbstractVector,<:MMatrix}, r::Real,
method::AbstractReductionMethod=GIR05()) where {N}
return reduce_order(Zonotope(center(Z), SMatrix(genmat(Z))), r, method)
return reduce_order(Zonotope(center(Z), StaticArraysCore.SMatrix(genmat(Z))), r, method)
end
end
end # quote / load_reduce_order_static_zonotope
end # load_StaticArraysCore_reduce_order
10 changes: 6 additions & 4 deletions src/Sets/Zonotope/split.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ end

_split_ret(Z₁::Zonotope, Z₂::Zonotope) = (Z₁, Z₂)

function load_split_static()
function load_StaticArraysCore_split()
return quote
using .StaticArraysCore: MMatrix, MVector

function _split_ret(Z₁::Zonotope{N,SV,SM},
Z₂::Zonotope{N,SV,SM}) where {N,n,p,SV<:MVector{n,N},SM<:MMatrix{n,p,N}}
Z₁ = Zonotope(SVector{n}(Z₁.center), SMatrix{n,p}(Z₁.generators))
Z₂ = Zonotope(SVector{n}(Z₂.center), SMatrix{n,p}(Z₂.generators))
Z₁ = Zonotope(StaticArraysCore.SVector{n}(Z₁.center), StaticArraysCore.SMatrix{n,p}(Z₁.generators))
Z₂ = Zonotope(StaticArraysCore.SVector{n}(Z₂.center), StaticArraysCore.SMatrix{n,p}(Z₂.generators))
return Z₁, Z₂
end
end
end # quote / load_split_static
end # load_StaticArraysCore_split

function _split(Z::Zonotope, gens::AbstractVector, n::AbstractVector)
p = length(gens)
Expand Down
8 changes: 4 additions & 4 deletions src/Utils/samples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,9 @@ function _sample_unit_nsphere_muller!(D::Vector{Vector{N}}, n::Int, p::Int;
return _sample_unit_nsphere_muller_distributions!(D, n, p; rng=rng, seed=seed)
end

function load_distributions_samples()
function load_Distributions_sample()
return quote
using .Distributions: Normal, UnivariateDistribution
using .Distributions: UnivariateDistribution

function RejectionSampler(distr::UnivariateDistribution; tight::Bool=false)
return RejectionSampler([distr]; tight=tight)
Expand All @@ -638,7 +638,7 @@ function load_distributions_samples()
rng::AbstractRNG=GLOBAL_RNG,
seed::Union{Int,Nothing}=nothing) where {N}
rng = reseed!(rng, seed)
Zdims = [Normal() for _ in 1:n] # normal distributions for each dimension
Zdims = [Distributions.Normal() for _ in 1:n] # normal distributions for each dimension
v = Vector{N}(undef, n) # sample direction
@inbounds for j in 1:p
α = zero(N)
Expand All @@ -651,4 +651,4 @@ function load_distributions_samples()
return D
end
end
end # quote / load_distributions_samples()
end # load_Distributions_sample

0 comments on commit fd1b70e

Please sign in to comment.