@@ -22,36 +22,49 @@ LinearAlgebra.adjoint(A::UniformScalingMap) = UniformScalingMap(conj(A.λ), si
22
22
Base.:(* )(A:: UniformScalingMap , x:: AbstractVector ) =
23
23
length (x) == A. M ? A. λ * x : throw (DimensionMismatch (" A_mul_B!" ))
24
24
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"
27
26
function A_mul_B! (y:: AbstractVector , A:: UniformScalingMap , x:: AbstractVector )
28
27
(length (x) == length (y) == A. M || throw (DimensionMismatch (" A_mul_B!" )))
29
28
if iszero (A. λ)
30
29
return fill! (y, 0 )
31
30
elseif isone (A. λ)
32
31
return copyto! (y, x)
33
32
else
33
+ # call of LinearAlgebra.generic_mul! since order of arguments in mul! in
34
+ # stdlib/LinearAlgebra/src/generic.jl reversed
34
35
return LinearAlgebra. generic_mul! (y, A. λ, x)
35
36
end
36
37
end
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
39
51
40
52
function LinearAlgebra. mul! (y:: AbstractVector , J:: UniformScalingMap{T} , x:: AbstractVector , α:: Number = one (T), β:: Number = zero (T)) where {T}
41
53
@boundscheck (length (x) == length (y) == J. M || throw (DimensionMismatch (" mul!" )))
54
+ λ = J. λ
42
55
@inbounds if isone (α)
43
56
if iszero (β)
44
57
A_mul_B! (y, J, x)
45
58
return y
46
59
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
50
63
return y
51
64
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
55
68
return y
56
69
end
57
70
elseif iszero (α)
@@ -61,14 +74,18 @@ function LinearAlgebra.mul!(y::AbstractVector, J::UniformScalingMap{T}, x::Abstr
61
74
rmul! (y, β)
62
75
return y
63
76
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)
66
79
# β != 0, 1
67
- y .= y .* β .+ J . λ .* x .* α
80
+ y .= y .* β .+ λ .* x .* α
68
81
return y
69
82
end
70
83
end
71
84
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
+
72
89
# combine LinearMap and UniformScaling objects in linear combinations
73
90
Base.:(+ )(A₁:: LinearMap , A₂:: UniformScaling ) = A₁ + UniformScalingMap (A₂. λ, size (A₁, 1 ))
74
91
Base.:(+ )(A₁:: UniformScaling , A₂:: LinearMap ) = UniformScalingMap (A₁. λ, size (A₂, 1 )) + A₂
0 commit comments