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

Let 1D linear_map of zonotopic set remove redudant generator #3764

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions src/Interfaces/AbstractZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ A `Zonotope`.

We apply the linear map to the center and the generators.

If the map has outpu dimension 1, a specialized algorithm ensures that the
resulting zonotope only has a single generator.
If the map has output dimension 1, a specialized algorithm ensures that the
resulting zonotope only has a single generator (or none if the map is zero).
"""
function linear_map(M::AbstractMatrix, Z::AbstractZonotope)
@assert dim(Z) == size(M, 2) "a linear map of size $(size(M)) cannot be " *
Expand All @@ -326,7 +326,8 @@ function _linear_map_zonotope_1D(M::AbstractMatrix, Z::LazySet)
@inbounds for g in generators(Z)
gi += abs(sum(M[1, i] * g[i] for i in eachindex(g)))
end
return Zonotope(c, hcat(gi))
G = iszero(gi) ? Matrix{N}(undef, 1, 0) : hcat(gi)
return Zonotope(c, G)
end

function _linear_map_zonotope_nD(M::AbstractMatrix, Z::LazySet)
Expand Down
4 changes: 4 additions & 0 deletions test/Sets/Zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ for N in [Float64, Rational{Int}, Float32]
M = N[-1 1;]
Z6 = linear_map(M, Z3)
@test ngens(Z6) == 1 && genmat(Z6) == hcat(N[4])
# ... unless the map is zero
M = N[0 0;]
Z7 = linear_map(M, Z3)
@test ngens(Z7) == 0 && genmat(Z7) == Matrix{N}(undef, 1, 0)

# in-place linear map
Zin = convert(Zonotope, BallInf(zeros(N, 2), N(1)))
Expand Down
Loading