Skip to content

Commit

Permalink
Merge pull request #204 from JuliaReach/schillic/203
Browse files Browse the repository at this point in the history
#203 - fix scalar multiplication of a LinearMap
  • Loading branch information
Marcelo Forets authored Jan 29, 2018
2 parents ccccf40 + 850eede commit f9d638f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/LinearMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ LinearMap(M::AbstractMatrix{N}, map::LinearMap{N, S}

"""
```
*(M::AbstractMatrix{<:Real}, S::LazySet)
*(M::AbstractMatrix{<:Real}, X::LazySet)
```
Return the linear map of a convex set.
### Input
- `M` -- matrix/linear map
- `S` -- convex set
- `X` -- convex set
### Output
Expand All @@ -56,7 +56,7 @@ Return a linear map of a convex set by a scalar value.
### Input
- `a` -- real scalar
- `S` -- convex set
- `X` -- convex set
### Output
Expand All @@ -66,6 +66,26 @@ function *(a::N, X::S)::LinearMap{N, S} where {S<:LazySet{N}} where {N<:Real}
return LinearMap(a * speye(N, dim(X)), X)
end

"""
```
*(a::N, map::S)::S where {S<:LinearMap{N, S}} where {N<:Real}
```
Return a linear map scaled by a scalar value.
### Input
- `a` -- real scalar
- `map` -- linear map
### Output
The scaled linear map.
"""
function *(a::N, map::S)::S where {S<:LinearMap{N, T}} where {N<:Real} where {T}
return LinearMap(a * map.M, map.sf)
end

"""
```
*(M::AbstractMatrix, Z::ZeroSet)
Expand Down
2 changes: 2 additions & 0 deletions test/unit_LinearMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ for N in [Float64, Rational{Int}, Float32]
# scalar multiplication
b = BallInf(N[0., 0.], N(1.))
lm = N(2.) * b
# repeated scalar multiplication
lm2 = N(2.) * lm
# Test Dimension
@test dim(lm) == 2
# Test Support Vector
Expand Down

0 comments on commit f9d638f

Please sign in to comment.