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

add in-place splitting #215

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/Flowpipes/setops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,29 @@ end
# Zonotope splitting methods
# ==================================

function _split(Z::Zonotope{N, Vector{N}, Matrix{N}}, j::Int) where {N}
function _split(Z::Zonotope, j::Int)
c, G = Z.center, Z.generators

c₁ = similar(c)
G₁ = similar(G)
Z₁ = Zonotope(c₁, G₁)

c₂ = similar(c)
G₂ = similar(G)
Z₂ = Zonotope(c₂, G₂)

_split!(Z₁, Z₂, Z, j)
end

function _split!(Z₁::Zonotope, Z₂::Zonotope, Z::Zonotope, j::Int)
c, G = Z.center, Z.generators
n, p = size(G)
@assert 1 <= j <= p "cannot split a zonotope with $p generators along index $j"

c₁ = Vector{N}(undef, n)
c₂ = Vector{N}(undef, n)

G₁ = copy(G)
G₂ = copy(G)
c₁, G₁ = Z₁.center, Z₁.generators
c₂, G₂ = Z₂.center, Z₂.generators
copyto!(G₁, G)
copyto!(G₂, G)

@inbounds for i in 1:n
α = G[i, j] / 2
Expand All @@ -457,9 +470,6 @@ function _split(Z::Zonotope{N, Vector{N}, Matrix{N}}, j::Int) where {N}
G₁[i, j] = α
G₁[i, j] = α
end

Z₁ = Zonotope(c₁, G₁)
Z₂ = Zonotope(c₂, G₂)
return Z₁, Z₂
end

Expand All @@ -486,6 +496,8 @@ function _split(Z::Zonotope{N, SVector{n, N}, <:SMatrix{n, p, N}}, j::Int) where
return Z₁, Z₂
end

# TODO in-place split for static arrays

# ==================================
# Zonotope order reduction methods
# ==================================
Expand Down