Skip to content

Commit

Permalink
Merge pull request #1523 from JuliaReach/schillic/1216
Browse files Browse the repository at this point in the history
#1216 - Negation of SingleEntryVector
  • Loading branch information
schillic authored Jul 27, 2019
2 parents 5cc0310 + 984ee7b commit cef6282
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/Arrays/SingleEntryVector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Translation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions test/unit_util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit cef6282

Please sign in to comment.