@@ -21,27 +21,28 @@ Base.size(A::CompositeMap) = (size(A.maps[end], 1), size(A.maps[1], 2))
2121Base. isreal (A:: CompositeMap ) = all (isreal, A. maps) # sufficient but not necessary
2222
2323# the following rules are sufficient but not necessary
24- const RealOrComplex = Union{Real,Complex}
2524for (f, _f, g) in ((:issymmetric , :_issymmetric , :transpose ),
2625 (:ishermitian , :_ishermitian , :adjoint ),
2726 (:isposdef , :_isposdef , :adjoint ))
2827 @eval begin
2928 LinearAlgebra.$ f (A:: CompositeMap ) = $ _f (A. maps)
3029 $ _f (maps:: Tuple{} ) = true
3130 $ _f (maps:: Tuple{<:LinearMap} ) = $ f (maps[1 ])
32- function $_f (maps:: Tuple{Vararg{<:LinearMap}} ) # length(maps) >= 2
33- if maps[1 ] isa UniformScalingMap{<: RealOrComplex }
34- return $ f (maps[1 ]) && $ _f (Base. tail (maps))
35- elseif maps[end ] isa UniformScalingMap{<: RealOrComplex }
36- return $ f (maps[end ]) && $ _f (Base. front (maps))
37- else
38- return maps[end ] == $ g (maps[1 ]) && $ _f (Base. front (Base. tail (maps)))
39- end
40- end
31+ $ _f (maps:: Tuple{Vararg{<:LinearMap}} ) = maps[end ] == $ g (maps[1 ]) && $ _f (Base. front (Base. tail (maps)))
32+ # since the introduction of ScaledMap, the following cases cannot occur
33+ # function $_f(maps::Tuple{Vararg{<:LinearMap}}) # length(maps) >= 2
34+ # if maps[1] isa UniformScalingMap{<:RealOrComplex}
35+ # return $f(maps[1]) && $_f(Base.tail(maps))
36+ # elseif maps[end] isa UniformScalingMap{<:RealOrComplex}
37+ # return $f(maps[end]) && $_f(Base.front(maps))
38+ # else
39+ # return maps[end] == $g(maps[1]) && $_f(Base.front(Base.tail(maps)))
40+ # end
41+ # end
4142 end
4243end
4344
44- # scalar multiplication and division
45+ # scalar multiplication and division (non-commutative case)
4546function Base.:(* )(α:: Number , A:: LinearMap )
4647 T = promote_type (typeof (α), eltype (A))
4748 return CompositeMap {T} (tuple (A, UniformScalingMap (α, size (A, 1 ))))
@@ -55,6 +56,11 @@ function Base.:(*)(α::Number, A::CompositeMap)
5556 return CompositeMap {T} (tuple (A. maps... , UniformScalingMap (α, size (A, 1 ))))
5657 end
5758end
59+ # needed for disambiguation
60+ function Base.:(* )(α:: RealOrComplex , A:: CompositeMap )
61+ T = Base. promote_op (* , typeof (α), eltype (A))
62+ return ScaledMap {T} (α, A)
63+ end
5864function Base.:(* )(A:: LinearMap , α:: Number )
5965 T = promote_type (typeof (α), eltype (A))
6066 return CompositeMap {T} (tuple (UniformScalingMap (α, size (A, 2 )), A))
@@ -68,13 +74,18 @@ function Base.:(*)(A::CompositeMap, α::Number)
6874 return CompositeMap {T} (tuple (UniformScalingMap (α, size (A, 2 )), A. maps... ))
6975 end
7076end
77+ # needed for disambiguation
78+ function Base.:(* )(A:: CompositeMap , α:: RealOrComplex )
79+ T = Base. promote_op (* , typeof (α), eltype (A))
80+ return ScaledMap {T} (α, A)
81+ end
82+
7183Base.:(\ )(α:: Number , A:: LinearMap ) = inv (α) * A
7284Base.:(/ )(A:: LinearMap , α:: Number ) = A * inv (α)
73- Base.:(- )(A:: LinearMap ) = - 1 * A
7485
7586# composition of linear maps
7687"""
77- A::LinearMap * B::LinearMap
88+ *( A::LinearMap, B::LinearMap)
7889
7990Construct a `CompositeMap <: LinearMap`, a (lazy) representation of the product
8091of the two operators. Products of `LinearMap`/`CompositeMap` objects and
@@ -109,8 +120,6 @@ function Base.:(*)(A₁::CompositeMap, A₂::CompositeMap)
109120 T = promote_type (eltype (A₁), eltype (A₂))
110121 return CompositeMap {T} (tuple (A₂. maps... , A₁. maps... ))
111122end
112- Base.:(* )(A₁:: LinearMap , A₂:: UniformScaling ) = A₁ * A₂. λ
113- Base.:(* )(A₁:: UniformScaling , A₂:: LinearMap ) = A₁. λ * A₂
114123
115124# special transposition behavior
116125LinearAlgebra. transpose (A:: CompositeMap{T} ) where {T} = CompositeMap {T} (map (transpose, reverse (A. maps)))
0 commit comments