@@ -22,36 +22,49 @@ LinearAlgebra.adjoint(A::UniformScalingMap) = UniformScalingMap(conj(A.λ), si
2222Base.:(* )(A:: UniformScalingMap , x:: AbstractVector ) =
2323 length (x) == A. M ? A. λ * x : throw (DimensionMismatch (" A_mul_B!" ))
2424
25- # call of LinearAlgebra.generic_mul! since order of arguments in mul! in stdlib/LinearAlgebra/src/generic.jl
26- # TODO : either leave it as is or use mul! (and lower bound on version) once fixed in LinearAlgebra
25+ if VERSION < v " 1.3.0-alpha.115"
2726function A_mul_B! (y:: AbstractVector , A:: UniformScalingMap , x:: AbstractVector )
2827 (length (x) == length (y) == A. M || throw (DimensionMismatch (" A_mul_B!" )))
2928 if iszero (A. λ)
3029 return fill! (y, 0 )
3130 elseif isone (A. λ)
3231 return copyto! (y, x)
3332 else
33+ # call of LinearAlgebra.generic_mul! since order of arguments in mul! in
34+ # stdlib/LinearAlgebra/src/generic.jl reversed
3435 return LinearAlgebra. generic_mul! (y, A. λ, x)
3536 end
3637end
37- At_mul_B! (y:: AbstractVector , A:: UniformScalingMap , x:: AbstractVector ) = A_mul_B! (y, transpose (A), x)
38- Ac_mul_B! (y:: AbstractVector , A:: UniformScalingMap , x:: AbstractVector ) = A_mul_B! (y, adjoint (A), x)
38+ else # 5-arg mul! exists and order of arguments is corrected
39+ function A_mul_B! (y:: AbstractVector , A:: UniformScalingMap , x:: AbstractVector )
40+ (length (x) == length (y) == A. M || throw (DimensionMismatch (" A_mul_B!" )))
41+ λ = A. λ
42+ if iszero (λ)
43+ return fill! (y, 0 )
44+ elseif isone (λ)
45+ return copyto! (y, x)
46+ else
47+ return y .= λ .* x
48+ end
49+ end
50+ end # VERSION
3951
4052function LinearAlgebra. mul! (y:: AbstractVector , J:: UniformScalingMap{T} , x:: AbstractVector , α:: Number = one (T), β:: Number = zero (T)) where {T}
4153 @boundscheck (length (x) == length (y) == J. M || throw (DimensionMismatch (" mul!" )))
54+ λ = J. λ
4255 @inbounds if isone (α)
4356 if iszero (β)
4457 A_mul_B! (y, J, x)
4558 return y
4659 elseif isone (β)
47- iszero (J . λ) && return y
48- isone (J . λ) && return y .+ = x
49- y .+ = J . λ .* x
60+ iszero (λ) && return y
61+ isone (λ) && return y .+ = x
62+ y .+ = λ .* x
5063 return y
5164 else # β != 0, 1
52- iszero (J . λ) && (rmul! (y, β); return y)
53- isone (J . λ) && (y .= y .* β .+ x; return y)
54- y .= y .* β .+ J . λ .* x
65+ iszero (λ) && (rmul! (y, β); return y)
66+ isone (λ) && (y .= y .* β .+ x; return y)
67+ y .= y .* β .+ λ .* x
5568 return y
5669 end
5770 elseif iszero (α)
@@ -61,14 +74,18 @@ function LinearAlgebra.mul!(y::AbstractVector, J::UniformScalingMap{T}, x::Abstr
6174 rmul! (y, β)
6275 return y
6376 else # α != 0, 1
64- iszero (β) && (y .= J . λ .* x .* α; return y)
65- isone (β) && (y .+ = J . λ .* x .* α; return y)
77+ iszero (β) && (y .= λ .* x .* α; return y)
78+ isone (β) && (y .+ = λ .* x .* α; return y)
6679 # β != 0, 1
67- y .= y .* β .+ J . λ .* x .* α
80+ y .= y .* β .+ λ .* x .* α
6881 return y
6982 end
7083end
7184
85+ At_mul_B! (y:: AbstractVector , A:: UniformScalingMap , x:: AbstractVector ) = A_mul_B! (y, transpose (A), x)
86+ Ac_mul_B! (y:: AbstractVector , A:: UniformScalingMap , x:: AbstractVector ) = A_mul_B! (y, adjoint (A), x)
87+
88+
7289# combine LinearMap and UniformScaling objects in linear combinations
7390Base.:(+ )(A₁:: LinearMap , A₂:: UniformScaling ) = A₁ + UniformScalingMap (A₂. λ, size (A₁, 1 ))
7491Base.:(+ )(A₁:: UniformScaling , A₂:: LinearMap ) = UniformScalingMap (A₁. λ, size (A₂, 1 )) + A₂
0 commit comments