@@ -47,10 +47,10 @@ SparseArrays.SparseMatrixCSC(A::LinearMap) = sparse(A)
4747# special cases
4848
4949# ScaledMap
50- Base. Matrix {T} (A:: ScaledMap{<:Any, <:Any, <:MatrixMap } ) where {T} =
50+ Base. Matrix {T} (A:: ScaledMap{<:Any, <:Any, <:VecOrMatMap } ) where {T} =
5151 convert (Matrix{T}, A. λ * A. lmap. lmap)
52- SparseArrays. sparse (A:: ScaledMap{<:Any, <:Any, <:MatrixMap } ) =
53- convert (SparseMatrixCSC, A. λ * A. lmap. lmap)
52+ SparseArrays. sparse (A:: ScaledMap{<:Any, <:Any, <:VecOrMatMap } ) =
53+ A. λ * sparse ( A. lmap. lmap)
5454
5555# UniformScalingMap
5656Base. Matrix {T} (J:: UniformScalingMap ) where {T} = Matrix {T} (J. λ* I, size (J))
@@ -59,6 +59,8 @@ Base.convert(::Type{AbstractMatrix}, J::UniformScalingMap) = Diagonal(fill(J.λ,
5959# WrappedMap
6060Base. Matrix {T} (A:: WrappedMap ) where {T} = Matrix {T} (A. lmap)
6161Base. convert (:: Type{T} , A:: WrappedMap ) where {T<: Matrix } = convert (T, A. lmap)
62+ Base. Matrix {T} (A:: VectorMap ) where {T} = copyto! (Matrix {eltype(T)} (undef, size (A)), A. lmap)
63+ Base. convert (:: Type{T} , A:: VectorMap ) where {T<: Matrix } = T (A)
6264Base. convert (:: Type{AbstractMatrix} , A:: WrappedMap ) = convert (AbstractMatrix, A. lmap)
6365SparseArrays. sparse (A:: WrappedMap ) = sparse (A. lmap)
6466Base. convert (:: Type{SparseMatrixCSC} , A:: WrappedMap ) = convert (SparseMatrixCSC, A. lmap)
@@ -70,19 +72,19 @@ for (T, t) in ((AdjointMap, adjoint), (TransposeMap, transpose))
7072end
7173
7274# LinearCombination
73- function Base. Matrix {T} (ΣA:: LinearCombination{<:Any, <:Tuple{Vararg{MatrixMap }}} ) where {T}
75+ function Base. Matrix {T} (ΣA:: LinearCombination{<:Any, <:Tuple{Vararg{VecOrMatMap }}} ) where {T}
7476 maps = ΣA. maps
7577 mats = map (A-> getfield (A, :lmap ), maps)
7678 return Matrix {T} (sum (mats))
7779end
78- function SparseArrays. sparse (ΣA:: LinearCombination{<:Any, <:Tuple{Vararg{MatrixMap }}} )
80+ function SparseArrays. sparse (ΣA:: LinearCombination{<:Any, <:Tuple{Vararg{VecOrMatMap }}} )
7981 maps = ΣA. maps
8082 mats = map (A-> getfield (A, :lmap ), maps)
8183 return convert (SparseMatrixCSC, sum (mats))
8284end
8385
8486# CompositeMap
85- function Base. Matrix {T} (AB:: CompositeMap{<:Any, <:Tuple{MatrixMap , LinearMap}} ) where {T}
87+ function Base. Matrix {T} (AB:: CompositeMap{<:Any, <:Tuple{VecOrMatMap , LinearMap}} ) where {T}
8688 B, A = AB. maps
8789 require_one_based_indexing (B)
8890 Y = Matrix {eltype(AB)} (undef, size (AB))
@@ -91,36 +93,36 @@ function Base.Matrix{T}(AB::CompositeMap{<:Any, <:Tuple{MatrixMap, LinearMap}})
9193 end
9294 return Y
9395end
94- for ((TA, fieldA), (TB, fieldB)) in (((MatrixMap , :lmap ), (MatrixMap , :lmap )),
95- ((MatrixMap , :lmap ), (UniformScalingMap, :λ )),
96- ((UniformScalingMap, :λ ), (MatrixMap , :lmap )))
96+ for ((TA, fieldA), (TB, fieldB)) in (((VecOrMatMap , :lmap ), (VecOrMatMap , :lmap )),
97+ ((VecOrMatMap , :lmap ), (UniformScalingMap, :λ )),
98+ ((UniformScalingMap, :λ ), (VecOrMatMap , :lmap )))
9799 @eval function Base. convert (:: Type{AbstractMatrix} ,
98100 AB:: CompositeMap{<:Any,<:Tuple{$TB,$TA}} )
99101 B, A = AB. maps
100102 return A.$ fieldA* B.$ fieldB
101103 end
102104end
103- function Base. Matrix {T} (AB:: CompositeMap{<:Any, <:Tuple{MatrixMap, MatrixMap }} ) where {T}
105+ function Base. Matrix {T} (AB:: CompositeMap{<:Any, <:Tuple{VecOrMatMap, VecOrMatMap }} ) where {T}
104106 B, A = AB. maps
105107 return convert (Matrix{T}, A. lmap* B. lmap)
106108end
107- function SparseArrays. sparse (AB:: CompositeMap{<:Any, <:Tuple{MatrixMap, MatrixMap }} )
109+ function SparseArrays. sparse (AB:: CompositeMap{<:Any, <:Tuple{VecOrMatMap, VecOrMatMap }} )
108110 B, A = AB. maps
109111 return convert (SparseMatrixCSC, A. lmap* B. lmap)
110112end
111- function Base. Matrix {T} (λA:: CompositeMap{<:Any, <:Tuple{MatrixMap , UniformScalingMap}} ) where {T}
113+ function Base. Matrix {T} (λA:: CompositeMap{<:Any, <:Tuple{VecOrMatMap , UniformScalingMap}} ) where {T}
112114 A, J = λA. maps
113115 return convert (Matrix{T}, J. λ* A. lmap)
114116end
115- function SparseArrays. sparse (λA:: CompositeMap{<:Any, <:Tuple{MatrixMap , UniformScalingMap}} )
117+ function SparseArrays. sparse (λA:: CompositeMap{<:Any, <:Tuple{VecOrMatMap , UniformScalingMap}} )
116118 A, J = λA. maps
117119 return convert (SparseMatrixCSC, J. λ* A. lmap)
118120end
119- function Base. Matrix {T} (Aλ:: CompositeMap{<:Any, <:Tuple{UniformScalingMap, MatrixMap }} ) where {T}
121+ function Base. Matrix {T} (Aλ:: CompositeMap{<:Any, <:Tuple{UniformScalingMap, VecOrMatMap }} ) where {T}
120122 J, A = Aλ. maps
121123 return convert (Matrix{T}, A. lmap* J. λ)
122124end
123- function SparseArrays. sparse (Aλ:: CompositeMap{<:Any, <:Tuple{UniformScalingMap, MatrixMap }} )
125+ function SparseArrays. sparse (Aλ:: CompositeMap{<:Any, <:Tuple{UniformScalingMap, VecOrMatMap }} )
124126 J, A = Aλ. maps
125127 return convert (SparseMatrixCSC, A. lmap* J. λ)
126128end
0 commit comments