-
Notifications
You must be signed in to change notification settings - Fork 33
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
#2213 - Port zonotope splitting implementation from RA #2214
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
A comparison between static vs non-static implementation: julia> using Revise, LazySets, StaticArrays, BenchmarkTools
[ Info: Precompiling LazySets [b4f0291d-fe17-52bc-9479-3d1a343d9043]
julia> Z = Zonotope(@SVector(rand(2)), @SMatrix(rand(2, 2)))
Zonotope{Float64,SArray{Tuple{2},Float64,1,2},SArray{Tuple{2,2},Float64,2,4}}([0.6088108765998801, 0.5135386852090658], [0.666497673074505
6 0.9542751369371558; 0.5158563660350037 0.5883345234682646])
julia> split(Z, 2)
(Zonotope{Float64,SArray{Tuple{2},Float64,1,2},SArray{Tuple{2,2},Float64,2,4}}([0.13167330813130218, 0.21937142347493344], [0.666497673074
5056 0.4771375684685779; 0.5158563660350037 0.2941672617341323]), Zonotope{Float64,SArray{Tuple{2},Float64,1,2},SArray{Tuple{2,2},Float64,
2,4}}([1.085948445068458, 0.8077059469431981], [0.6664976730745056 0.4771375684685779; 0.5158563660350037 0.2941672617341323]))
julia> @btime split($Z, 2);
35.733 ns (4 allocations: 160 bytes)
julia> Z2 = Zonotope(Vector(Z.center), Matrix(Z.generators));
julia> split(Z2, 2)
(Zonotope{Float64,Array{Float64,1},Array{Float64,2}}([0.13167330813130218, 0.21937142347493344], [0.6664976730745056 0.4771375684685779; 0
.5158563660350037 0.2941672617341323]), Zonotope{Float64,Array{Float64,1},Array{Float64,2}}([1.085948445068458, 0.8077059469431981], [0.66
64976730745056 0.4771375684685779; 0.5158563660350037 0.2941672617341323]))
julia> @btime split($Z2, 2);
120.027 ns (4 allocations: 416 bytes) runtime in master using regular arrays (errors with sarrays) julia> @btime split($Z2, 2);
196.267 ns (9 allocations: 704 bytes) |
Co-authored-by: Christian Schilling <[email protected]>
Co-authored-by: Christian Schilling <[email protected]>
Co-authored-by: Christian Schilling <[email protected]>
Co-authored-by: Christian Schilling <[email protected]>
Co-authored-by: Christian Schilling <[email protected]>
Co-authored-by: Christian Schilling <[email protected]>
Co-authored-by: Christian Schilling <[email protected]>
Thanks @SebastianGuadalupe to help porting this code from RA. Also, we can now begin adding optional parts for use with StaticArrays. Should we merge this? @schillic |
Before merging, can you add a test for the two split methods for one of the other zonotopic types (e.g., There is an issue with mixed array types. I guess that julia> B = BallInf(SVector{2}(1., 1.), 1.)
BallInf{Float64,SArray{Tuple{2},Float64,1,2}}([1.0, 1.0], 1.0)
julia> convert(Zonotope, B)
Zonotope{Float64,SArray{Tuple{2},Float64,1,2},Array{Float64,2}}([1.0, 1.0], [1.0 0.0; 0.0 1.0])
# note that only the center is a static vector; the generators are a normal matrix
julia> split(B, [1], [1])
ERROR: MethodError: Cannot `convert` an object of type
Zonotope{Float64{},MArray{Tuple{2},Float64,1,2},Array{Float64{},2}} to an object of type
Zonotope{Float64{},SArray{Tuple{2},Float64,1,2},Array{Float64{},2}}
Closest candidates are:
convert(::Type{T}, ::T) where T at essentials.jl:171
Stacktrace:
[1] setindex!(::Array{Zonotope{Float64,SArray{Tuple{2},Float64,1,2},Array{Float64,2}},1}, ::Zonotope{Float64,MArray{Tuple{2},Float64,1,2},Array{Float64,2}}, ::Int64) at ./array.jl:826
[2] _append! at ./array.jl:968 [inlined]
[3] append! at ./array.jl:960 [inlined]
[4] _split(::Zonotope{Float64,SArray{Tuple{2},Float64,1,2},Array{Float64,2}}, ::Array{Int64,1}, ::Array{Int64,1}) at .julia/dev/LazySets/src/Sets/Zonotope.jl:402
[5] split(::BallInf{Float64,SArray{Tuple{2},Float64,1,2}}, ::Array{Int64,1}, ::Array{Int64,1}) at .julia/dev/LazySets/src/Interfaces/AbstractZonotope.jl:652 |
Closes #2213.