From 850eedee7a19882165c7d43a906329254d5b45bf Mon Sep 17 00:00:00 2001 From: schillic Date: Mon, 29 Jan 2018 20:30:19 +0100 Subject: [PATCH] fix scalar multiplication of a LinearMap --- src/LinearMap.jl | 26 +++++++++++++++++++++++--- test/unit_LinearMap.jl | 2 ++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/LinearMap.jl b/src/LinearMap.jl index 4b6a2809a9..10c3963bd4 100644 --- a/src/LinearMap.jl +++ b/src/LinearMap.jl @@ -23,7 +23,7 @@ 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. @@ -31,7 +31,7 @@ Return the linear map of a convex set. ### Input - `M` -- matrix/linear map -- `S` -- convex set +- `X` -- convex set ### Output @@ -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 @@ -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) diff --git a/test/unit_LinearMap.jl b/test/unit_LinearMap.jl index c14611f290..f12b3a8d59 100644 --- a/test/unit_LinearMap.jl +++ b/test/unit_LinearMap.jl @@ -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