diff --git a/src/Arrays/SingleEntryVector.jl b/src/Arrays/SingleEntryVector.jl index 607063dec4..aefad6b33d 100644 --- a/src/Arrays/SingleEntryVector.jl +++ b/src/Arrays/SingleEntryVector.jl @@ -37,12 +37,17 @@ function Base.:(*)(A::Transpose{N, <:AbstractMatrix{N}}, return A[:, e.i] * e.v end -# diagonal matrix times unit vector +# multiplication with diagonal matrix function Base.:(*)(D::Diagonal{N, V}, e::SingleEntryVector{N}) where {N, V<:AbstractVector{N}} return SingleEntryVector(e.i, e.n, D.diag[e.i] * e.v) end +# negation +function Base.:(-)(e::SingleEntryVector{N}) where {N} + return SingleEntryVector(e.i, e.n, -e.v) +end + function inner(e1::SingleEntryVector{N}, A::AbstractMatrix{N}, e2::SingleEntryVector{N}) where {N} return A[e1.i, e2.i] * e1.v * e2.v diff --git a/src/Translation.jl b/src/Translation.jl index 094871183a..645e5012c1 100644 --- a/src/Translation.jl +++ b/src/Translation.jl @@ -130,9 +130,9 @@ julia> constraints_list(tr) HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([1.0, 0.0, 0.0], 5.0) HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([0.0, 1.0, 0.0], 3.0) HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([0.0, 0.0, 1.0], 3.0) - HalfSpace{Float64,Array{Float64,1}}([-1.0, -0.0, -0.0], -3.0) - HalfSpace{Float64,Array{Float64,1}}([-0.0, -1.0, -0.0], -1.0) - HalfSpace{Float64,Array{Float64,1}}([-0.0, -0.0, -1.0], -1.0) + HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([-1.0, 0.0, 0.0], -3.0) + HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([0.0, -1.0, 0.0], -1.0) + HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([0.0, 0.0, -1.0], -1.0) ``` """ struct Translation{N<:Real, VN<:AbstractVector{N}, S<:LazySet{N}} <: LazySet{N} diff --git a/test/unit_util.jl b/test/unit_util.jl index 3040c9d55a..4c4a41fec2 100644 --- a/test/unit_util.jl +++ b/test/unit_util.jl @@ -51,6 +51,7 @@ for _dummy_ in 1:1 # avoid global variable warnings y1 = N[3, 0] x2 = SingleEntryVector(2, 3, N(2)) y2 = SingleEntryVector(1, 2, N(3)) + @test -x2 == SingleEntryVector(2, 3, N(-2)) @test inner(x1, A, y1) == dot(x1, A * y1) == inner(x2, A, y2) == dot(x2, A * y2) == N(12)