diff --git a/docs/src/lib/sets/SimpleSparsePolynomialZonotope.md b/docs/src/lib/sets/SimpleSparsePolynomialZonotope.md index 2088356d9b..0b08c4ba8c 100644 --- a/docs/src/lib/sets/SimpleSparsePolynomialZonotope.md +++ b/docs/src/lib/sets/SimpleSparsePolynomialZonotope.md @@ -15,7 +15,7 @@ dim(::SimpleSparsePolynomialZonotope) ngens(::SimpleSparsePolynomialZonotope) nparams(::SimpleSparsePolynomialZonotope) order(::SimpleSparsePolynomialZonotope) -linear_map(::AbstractMatrix, ::SimpleSparsePolynomialZonotope) +linear_map(::Union{Real, AbstractMatrix, LinearAlgebra.UniformScaling}, ::SimpleSparsePolynomialZonotope) minkowski_sum(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope) cartesian_product(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope) linear_combination(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope) diff --git a/docs/src/lib/sets/SparsePolynomialZonotope.md b/docs/src/lib/sets/SparsePolynomialZonotope.md index 6a06bd6424..7915221b52 100644 --- a/docs/src/lib/sets/SparsePolynomialZonotope.md +++ b/docs/src/lib/sets/SparsePolynomialZonotope.md @@ -18,6 +18,6 @@ ngens_dep(::SparsePolynomialZonotope) ngens_indep(::SparsePolynomialZonotope) nparams(::SparsePolynomialZonotope) order(::SparsePolynomialZonotope) -linear_map(::AbstractMatrix, ::SparsePolynomialZonotope) +linear_map(::Union{Real, AbstractMatrix, LinearAlgebra.UniformScaling}, ::SparsePolynomialZonotope) exact_sum(::SparsePolynomialZonotope, ::SparsePolynomialZonotope) ``` diff --git a/src/Sets/SimpleSparsePolynomialZonotope.jl b/src/Sets/SimpleSparsePolynomialZonotope.jl index 28f5093e6b..eac22d9c2c 100644 --- a/src/Sets/SimpleSparsePolynomialZonotope.jl +++ b/src/Sets/SimpleSparsePolynomialZonotope.jl @@ -190,7 +190,7 @@ julia> expmat(S) expmat(P::SSPZ) = P.E """ - linear_map(M::AbstractMatrix, P::SimpleSparsePolynomialZonotope) + linear_map(M::Union{Real, AbstractMatrix, LinearAlgebra.UniformScaling}, P::SimpleSparsePolynomialZonotope) Apply the linear map `M` to the simple sparse polynomial zonotope `P`. @@ -203,7 +203,7 @@ Apply the linear map `M` to the simple sparse polynomial zonotope `P`. The set resulting from applying the linear map `M` to `P`. """ -function linear_map(M::AbstractMatrix, P::SSPZ) +function linear_map(M::Union{Real, AbstractMatrix, LinearAlgebra.UniformScaling}, P::SSPZ) return SimpleSparsePolynomialZonotope(M * center(P), M * genmat(P), expmat(P)) end diff --git a/src/Sets/SparsePolynomialZonotope.jl b/src/Sets/SparsePolynomialZonotope.jl index 0dcb6b6443..5fc68848c2 100644 --- a/src/Sets/SparsePolynomialZonotope.jl +++ b/src/Sets/SparsePolynomialZonotope.jl @@ -208,7 +208,7 @@ Returns a collection of n unique identifiers (intergers 1, …, n). """ uniqueID(n::Int) = 1:n """ - linear_map(M::AbstractMatrix, P::SparsePolynomialZonotope) + linear_map(M::Union{Real, AbstractMatrix, LinearAlgebra.UniformScaling}, P::SparsePolynomialZonotope) Apply the linear map `M` to the sparse polynomial zonotope `P`. @@ -221,7 +221,7 @@ Apply the linear map `M` to the sparse polynomial zonotope `P`. The set resulting from applying the linear map `M` to `P`. """ -function linear_map(M::AbstractMatrix, P::SPZ) +function linear_map(M::Union{Real, AbstractMatrix, LinearAlgebra.UniformScaling}, P::SPZ) return SparsePolynomialZonotope(M * center(P), M * genmat_dep(P), M * genmat_indep(P), @@ -230,7 +230,6 @@ function linear_map(M::AbstractMatrix, P::SPZ) ) end - """ rand(::Type{SparsePolynomialZonotope}; [N]::Type{<:Real}=Float64, [dim]::Int=2, [nparams]::Int=2, [maxdeg]::Int=3, diff --git a/test/Sets/SimpleSparsePolynomialZonotope.jl b/test/Sets/SimpleSparsePolynomialZonotope.jl index 7bb5948690..69c2e1a94f 100644 --- a/test/Sets/SimpleSparsePolynomialZonotope.jl +++ b/test/Sets/SimpleSparsePolynomialZonotope.jl @@ -24,6 +24,11 @@ for N in [Float64, Float32, Rational{Int}] @test genmat(LMS) == [5.0 6.0;11.0 14.0] @test expmat(LMS) == expmat(S) + LMS2 = linear_map(0.5, S) + @test center(LMS2) == [1.0, 0.0] + @test genmat(LMS2) == [0.5 1;1 1] + @test expmat(LMS2) == expmat(LMS2) + MSS = minkowski_sum(S, S) @test center(MSS) == [4.0, 0.0] @test genmat(MSS) == [1 2 1 2;2 2 2 2.] diff --git a/test/Sets/SparsePolynomialZonotope.jl b/test/Sets/SparsePolynomialZonotope.jl index 834476be5b..bab681d989 100644 --- a/test/Sets/SparsePolynomialZonotope.jl +++ b/test/Sets/SparsePolynomialZonotope.jl @@ -21,6 +21,13 @@ for N in [Float64, Float32, Rational{Int}] @test nparams(PZ) == 2 @test order(PZ) == 2//1 + + LM = linear_map(0.5, PZ) + @test center(LM) == [2, 2] + @test genmat_dep(LM) == [1 0.5 1;0 1 1] + @test genmat_indep(LM) == hcat([0.5, 0.0]) + @test expmat(LM) == expmat(PZ) + M = N[-0.5 0.2;-0.1 0.6] PZ2 = SparsePolynomialZonotope(zeros(N, 2), N[2 0 1;1 2 1], zeros(N, 2, 0), [1 0 1;0 1 3]) LMPZ = linear_map(M, PZ2) @@ -30,6 +37,7 @@ for N in [Float64, Float32, Rational{Int}] @test expmat(LMPZ) == [1 0 1;0 1 3] @test indexvector(LMPZ) == indexvector(PZ) + ESPZ = PZ ⊞ PZ2 @test center(ESPZ) == [4, 4] @test genmat_dep(ESPZ) == [2 1 2 2 0 1;0 2 2 1 2 1]