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

#2213 - Port zonotope splitting implementation from RA #2214

Merged
merged 24 commits into from
Jul 20, 2020
Merged

Conversation

SebastianGuadalupe
Copy link
Member

Closes #2213.

src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
Copy link
Member

@mforets mforets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/init.jl Outdated Show resolved Hide resolved
@mforets
Copy link
Member

mforets commented Jul 13, 2020

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)

mforets and others added 5 commits July 13, 2020 16:42
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]>
@mforets mforets requested a review from schillic July 14, 2020 12:05
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
test/unit_Zonotope.jl Outdated Show resolved Hide resolved
mforets and others added 3 commits July 14, 2020 11:53
src/Sets/Zonotope.jl Outdated Show resolved Hide resolved
src/Sets/Zonotope.jl Show resolved Hide resolved
@mforets
Copy link
Member

mforets commented Jul 16, 2020

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

@schillic
Copy link
Member

Before merging, can you add a test for the two split methods for one of the other zonotopic types (e.g., BallInf), please?

There is an issue with mixed array types. I guess that _split_ret for the two other combinations (where only one component is an MArray) would be needed. You can either fix it or open an issue.
We should also open an issue that in the conversion to zonotopes from static arrays we should use a static generator matrix.

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

@mforets mforets requested a review from schillic July 20, 2020 02:24
@mforets mforets merged commit 4d7f58e into master Jul 20, 2020
@mforets mforets deleted the sguadalupe/2213 branch July 20, 2020 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port zonotope splitting implementation from RA
3 participants