Skip to content
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
2 changes: 1 addition & 1 deletion docs/src/lib/sets/SparsePolynomialZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Undocumented implementations:
* [`extrema`](@ref extrema(::LazySet))
* [`isoperationtype`](@ref isoperationtype(::Type{LazySet}))
* [`linear_map`](@ref linear_map(::AbstractMatrix, ::LazySet))
* [`scale`](@ref scale(::Real, ::LazySet))
* [`translate`](@ref translate(::LazySet, ::AbstractVector))

```@meta
Expand Down Expand Up @@ -134,7 +135,6 @@ Inherited from [`LazySet`](@ref):
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet))
* [`project`](@ref project(::LazySet, ::AbstractVector{Int}))
* [`sample`](@ref sample(::LazySet, ::Int=1))
* [`scale`](@ref scale(::Real, ::LazySet))
* [`σ`](@ref σ(::AbstractVector, ::LazySet))
* [`convex_hull`](@ref convex_hull(::LazySet, ::LazySet))
* [`≈`](@ref ≈(::LazySet, ::LazySet))
Expand Down
7 changes: 7 additions & 0 deletions src/Sets/SparsePolynomialZonotope/scale.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function scale(α::Real, P::SparsePolynomialZonotope)
return SparsePolynomialZonotope(α * center(P),
α * genmat_dep(P),
α * genmat_indep(P),
expmat(P),
indexvector(P))
end
8 changes: 8 additions & 0 deletions test/Sets/SparsePolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ for N in [Float64, Float32, Rational{Int}]
Z = overapproximate(S, Zonotope)
@test isequivalent(Z, Zonotope(N[0, 0], N[1.5 1 1; 1.5 0 -1]))

α = 2.0
PZscaled = scale(α, PZ)
@test center(PZscaled) == N[8, 8]
@test genmat_dep(PZscaled) == N[4 2 4; 0 4 4]
@test genmat_indep(PZscaled) == hcat(N[2, 0])
@test expmat(PZscaled) == expmat(PZ)
@test PZscaled == linear_map(α * Matrix{N}(I, 2, 2), PZ)

# remove_redundant_generators
PZ = SparsePolynomialZonotope(N[-1, 2], N[1 2 0 2; 0 1 2 -1], N[1 0; 2 0], [1 0 1 2; 0 0 0 1])
PZreduced = remove_redundant_generators(PZ)
Expand Down
Loading