Skip to content

Commit

Permalink
Merge pull request #3674 from JuliaReach/schillic/copy
Browse files Browse the repository at this point in the history
Type-preserving `copy` for `Universe` and `ZeroSet`
  • Loading branch information
schillic authored Dec 16, 2024
2 parents dd5361b + 78a33b5 commit d033373
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Sets/Universe/UniverseModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using ReachabilityBase.Require: require
translate, translate!, cartesian_product, intersection
@reexport import ..LazySets: constrained_dimensions, linear_map_inverse,
tosimplehrep
import Base: copy
@reexport using ..API

export Universe
Expand All @@ -25,6 +26,7 @@ include("an_element.jl")
include("complement.jl")
include("constraints.jl")
include("constraints_list.jl")
include("copy.jl")
include("diameter.jl")
include("dim.jl")
include("isbounded.jl")
Expand Down
4 changes: 4 additions & 0 deletions src/Sets/Universe/copy.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# since there is only a single instance (per dimensionality), we do not copy
function copy(U::Universe)
return U
end
2 changes: 2 additions & 0 deletions src/Sets/ZeroSet/ZeroSetModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ using ReachabilityBase.Require: require
@reexport import ..API: dim, isoperationtype, rand, rectify, reflect, ,
linear_map, scale, scale!, ρ, translate, minkowski_sum
@reexport import ..LazySets: element
import Base: copy
@reexport using ..API

export ZeroSet

include("ZeroSet.jl")

include("copy.jl")
include("dim.jl")
include("isoperationtype.jl")
include("rand.jl")
Expand Down
4 changes: 4 additions & 0 deletions src/Sets/ZeroSet/copy.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# since there is only a single instance (per dimensionality), we do not copy
function copy(Z::ZeroSet)
return Z
end
4 changes: 4 additions & 0 deletions test/Sets/Universe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ for N in [Float64, Rational{Int}, Float32]
# dim
@test dim(U) == 2

# copy
U2 = copy(U)
@test U2 isa Universe{N} && dim(U2) == 2

# support function and support vector
@test ρ(N[0, 1], U) == N(Inf)
@test ρ(N[0, 0], U) == zero(N)
Expand Down
4 changes: 4 additions & 0 deletions test/Sets/ZeroSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ for N in [Float64, Rational{Int}, Float32]
Z = ZeroSet{N}(2)
B = BallInf(ones(N, 2), N(1))

# copy
Z2 = copy(Z)
@test Z2 isa ZeroSet{N} && dim(Z2) == 2

# isoperationtype
@test !isoperationtype(ZeroSet)

Expand Down

0 comments on commit d033373

Please sign in to comment.