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

#1662 - Dimensional check in zonotope constructor #1664

Merged
merged 2 commits into from
Sep 3, 2019
Merged
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
3 changes: 3 additions & 0 deletions src/Zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ struct Zonotope{N<:Real} <: AbstractZonotope{N}

function Zonotope(center::AbstractVector{N}, generators::AbstractMatrix{N};
remove_zero_generators::Bool=true) where {N<:Real}
@assert length(center) == size(generators, 1) "the dimension of the " *
"center ($(length(center))) and the generators " *
"($(size(generators, 1))) need to match"
if remove_zero_generators
generators = delete_zero_columns!(generators)
end
Expand Down
2 changes: 1 addition & 1 deletion test/check_method_ambiguity_binary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function check_method_ambiguity_binary(op;
VPolytope([zeros(1)]),
Universe(1),
ZeroSet(1),
Zonotope(zeros(1), hcat([1.; 2.]))
Zonotope(zeros(1), [1. 2.;])
]
H2 = LinearConstraint(ones(2), 1.)
polytope_constraints_2D = [H2,
Expand Down
2 changes: 2 additions & 0 deletions test/unit_Zonotope.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
for N in [Float64, Rational{Int}, Float32]
# random zonotope
rand(Zonotope)
# Test dimension assertion
@test_throws AssertionError Zonotope([1., 1], [[0. 0]; [0.5 0]; [0. 0.5]; [0. 0]])

# 1D Zonotope
z = Zonotope(N[0], Matrix{N}(I, 1, 1))
Expand Down