@@ -16,11 +16,6 @@ BlockMap{T}(maps::As, rows::S) where {T,As<:Tuple{Vararg{LinearMap}},S} = BlockM
1616
1717MulStyle (A:: BlockMap ) = MulStyle (A. maps... )
1818
19- function check_dim (A:: LinearMap , dim, n)
20- n == size (A, dim) || throw (DimensionMismatch (" Expected $n , got $(size (A, dim)) " ))
21- return nothing
22- end
23-
2419"""
2520 rowcolranges(maps, rows)
2621
5146
5247Base. size (A:: BlockMap ) = (last (last (A. rowranges)), last (last (A. colranges)))
5348
54- # ###########
55- # concatenation
56- # ###########
57-
58- for k in 1 : 8 # is 8 sufficient?
59- Is = ntuple (n-> :($ (Symbol (:A ,n)):: UniformScaling ), Val (k- 1 ))
60- L = :($ (Symbol (:A ,k)):: LinearMap )
61- args = ntuple (n-> Symbol (:A ,n), Val (k))
62-
63- @eval begin
64- Base. hcat ($ (Is... ), $ L, As:: Union{LinearMap,UniformScaling} ...) = _hcat ($ (args... ), As... )
65- Base. vcat ($ (Is... ), $ L, As:: Union{LinearMap,UniformScaling} ...) = _vcat ($ (args... ), As... )
66- Base. hvcat (rows:: Tuple{Vararg{Int}} , $ (Is... ), $ L, As:: Union{LinearMap,UniformScaling} ...) = _hvcat (rows, $ (args... ), As... )
67- end
68- end
69-
7049# ###########
7150# hcat
7251# ###########
7352"""
74- hcat(As::Union{LinearMap,UniformScaling}...)::BlockMap
53+ hcat(As::Union{LinearMap,UniformScaling,AbstractVecOrMat }...)::BlockMap
7554
7655Construct a (lazy) representation of the horizontal concatenation of the arguments.
77- `UniformScaling` objects are promoted to `LinearMap` automatically. To avoid fallback
78- to the generic `Base.hcat`, there must be a `LinearMap` object among the first 8 arguments.
56+ All arguments are promoted to `LinearMap`s automatically.
7957
8058# Examples
8159```jldoctest; setup=(using LinearMaps)
@@ -90,9 +68,7 @@ julia> L * ones(Int, 6)
9068 6
9169```
9270"""
93- Base. hcat
94-
95- function _hcat (As:: Union{LinearMap,UniformScaling} ...)
71+ function Base. hcat (As:: Union{LinearMap,UniformScaling,AbstractVecOrMat} ...)
9672 T = promote_type (map (eltype, As)... )
9773 nbc = length (As)
9874
11288# vcat
11389# ###########
11490"""
115- vcat(As::Union{LinearMap,UniformScaling}...)::BlockMap
91+ vcat(As::Union{LinearMap,UniformScaling,AbstractVecOrMat }...)::BlockMap
11692
11793Construct a (lazy) representation of the vertical concatenation of the arguments.
118- `UniformScaling` objects are promoted to `LinearMap` automatically. To avoid fallback
119- to the generic `Base.vcat`, there must be a `LinearMap` object among the first 8 arguments.
94+ All arguments are promoted to `LinearMap`s automatically.
12095
12196# Examples
12297```jldoctest; setup=(using LinearMaps)
@@ -134,9 +109,7 @@ julia> L * ones(Int, 3)
134109 3
135110```
136111"""
137- Base. vcat
138-
139- function _vcat (As:: Union{LinearMap,UniformScaling} ...)
112+ function Base. vcat (As:: Union{LinearMap,UniformScaling,AbstractVecOrMat} ...)
140113 T = promote_type (map (eltype, As)... )
141114 nbr = length (As)
142115
@@ -157,12 +130,11 @@ end
157130# hvcat
158131# ###########
159132"""
160- hvcat(rows::Tuple{Vararg{Int}}, As::Union{LinearMap,UniformScaling}...)::BlockMap
133+ hvcat(rows::Tuple{Vararg{Int}}, As::Union{LinearMap,UniformScaling,AbstractVecOrMat }...)::BlockMap
161134
162135Construct a (lazy) representation of the horizontal-vertical concatenation of the arguments.
163136The first argument specifies the number of arguments to concatenate in each block row.
164- `UniformScaling` objects are promoted to `LinearMap` automatically. To avoid fallback
165- to the generic `Base.hvcat`, there must be a `LinearMap` object among the first 8 arguments.
137+ All arguments are promoted to `LinearMap`s automatically.
166138
167139# Examples
168140```jldoctest; setup=(using LinearMaps)
@@ -185,7 +157,7 @@ julia> L * ones(Int, 6)
185157"""
186158Base. hvcat
187159
188- function _hvcat (rows:: Tuple{Vararg{Int}} , As:: Union{LinearMap,UniformScaling} ...)
160+ function Base . hvcat (rows:: Tuple{Vararg{Int}} , As:: Union{LinearMap,UniformScaling,AbstractVecOrMat } ...)
189161 nr = length (rows)
190162 T = promote_type (map (eltype, As)... )
191163 sum (rows) == length (As) || throw (ArgumentError (" mismatch between row sizes and number of arguments" ))
@@ -237,6 +209,13 @@ function _hvcat(rows::Tuple{Vararg{Int}}, As::Union{LinearMap,UniformScaling}...
237209 return BlockMap {T} (promote_to_lmaps (n, 1 , 1 , As... ), rows)
238210end
239211
212+ function check_dim (A, dim, n)
213+ n == size (A, dim) || throw (DimensionMismatch (" Expected $n , got $(size (A, dim)) " ))
214+ return nothing
215+ end
216+
217+ promote_to_lmaps_ (n:: Int , dim, A:: AbstractMatrix ) = (check_dim (A, dim, n); LinearMap (A))
218+ promote_to_lmaps_ (n:: Int , dim, A:: AbstractVector ) = (check_dim (A, dim, n); LinearMap (reshape (A, length (A), 1 )))
240219promote_to_lmaps_ (n:: Int , dim, J:: UniformScaling ) = UniformScalingMap (J. λ, n)
241220promote_to_lmaps_ (n:: Int , dim, A:: LinearMap ) = (check_dim (A, dim, n); A)
242221promote_to_lmaps (n, k, dim) = ()
292271
293272Base.:(== )(A:: BlockMap , B:: BlockMap ) = (eltype (A) == eltype (B) && A. maps == B. maps && A. rows == B. rows)
294273
295- # special transposition behavior
296-
297- LinearAlgebra. transpose (A:: BlockMap ) = TransposeMap (A)
298- LinearAlgebra. adjoint (A:: BlockMap ) = AdjointMap (A)
299-
300274# ###########
301275# multiplication helper functions
302276# ###########
@@ -310,6 +284,7 @@ function _blockmul!(y, A::BlockMap, x, α, β)
310284 return __blockmul! (MulStyle (A), y, A, x, α, β)
311285end
312286
287+ # provide one global intermediate storage vector if necessary
313288__blockmul! (:: FiveArg , y, A, x, α, β) = ___blockmul! (y, A, x, α, β, nothing )
314289__blockmul! (:: ThreeArg , y, A, x, α, β) = ___blockmul! (y, A, x, α, β, similar (y))
315290
@@ -401,7 +376,6 @@ for (intype, outtype) in ((AbstractVector, AbstractVecOrMat), (AbstractMatrix, A
401376 function _unsafe_mul! (y:: $outtype , wrapA:: $maptype , x:: $intype ,
402377 α:: Number , β:: Number )
403378 require_one_based_indexing (y, x)
404-
405379 return _transblockmul! (y, wrapA. lmap, x, α, β, $ transform)
406380 end
407381 end
@@ -437,22 +411,24 @@ BlockDiagonalMap{T}(maps::As) where {T,As<:Tuple{Vararg{LinearMap}}} =
437411BlockDiagonalMap (maps:: LinearMap... ) =
438412 BlockDiagonalMap {promote_type(map(eltype, maps)...)} (maps)
439413
414+ # since the below methods are more specific than the Base method,
415+ # they would redefine Base/SparseArrays behavior
440416for k in 1 : 8 # is 8 sufficient?
441- Is = ntuple (n-> :($ (Symbol (:A ,n)):: AbstractMatrix ), Val (k- 1 ))
417+ Is = ntuple (n-> :($ (Symbol (:A ,n)):: AbstractVecOrMat ), Val (k- 1 ))
442418 # yields (:A1, :A2, :A3, ..., :A(k-1))
443419 L = :($ (Symbol (:A ,k)):: LinearMap )
444420 # yields :Ak
445- mapargs = ntuple (n -> :(LinearMap ( $ (Symbol (:A ,n) ))), Val (k- 1 ))
421+ mapargs = ntuple (n -> :($ (Symbol (:A ,n))), Val (k- 1 ))
446422 # yields (:LinearMap(A1), :LinearMap(A2), ..., :LinearMap(A(k-1)))
447423
448424 @eval begin
449- function SparseArrays. blockdiag ($ (Is... ), $ L, As:: Union{LinearMap,AbstractMatrix } ...)
450- return BlockDiagonalMap ($ (mapargs... ), $ (Symbol (:A ,k)), convert_to_lmaps (As... )... )
425+ function SparseArrays. blockdiag ($ (Is... ), $ L, As:: Union{LinearMap,AbstractVecOrMat } ...)
426+ return BlockDiagonalMap (convert_to_lmaps ( $ (mapargs... )) ... , $ (Symbol (:A ,k)), convert_to_lmaps (As... )... )
451427 end
452428
453- function Base. cat ($ (Is... ), $ L, As:: Union{LinearMap,AbstractMatrix } ...; dims:: Dims{2} )
429+ function Base. cat ($ (Is... ), $ L, As:: Union{LinearMap,AbstractVecOrMat } ...; dims:: Dims{2} )
454430 if dims == (1 ,2 )
455- return BlockDiagonalMap ($ (mapargs... ), $ (Symbol (:A ,k)), convert_to_lmaps (As... )... )
431+ return BlockDiagonalMap (convert_to_lmaps ( $ (mapargs... )) ... , $ (Symbol (:A ,k)), convert_to_lmaps (As... )... )
456432 else
457433 throw (ArgumentError (" dims keyword in cat of LinearMaps must be (1,2)" ))
458434 end
@@ -461,7 +437,7 @@ for k in 1:8 # is 8 sufficient?
461437end
462438
463439"""
464- blockdiag(As::Union{LinearMap,AbstractMatrix }...)::BlockDiagonalMap
440+ blockdiag(As::Union{LinearMap,AbstractVecOrMat }...)::BlockDiagonalMap
465441
466442Construct a (lazy) representation of the diagonal concatenation of the arguments.
467443To avoid fallback to the generic `SparseArrays.blockdiag`, there must be a `LinearMap`
@@ -470,7 +446,7 @@ object among the first 8 arguments.
470446SparseArrays. blockdiag
471447
472448"""
473- cat(As::Union{LinearMap,AbstractMatrix }...; dims=(1,2))::BlockDiagonalMap
449+ cat(As::Union{LinearMap,AbstractVecOrMat }...; dims=(1,2))::BlockDiagonalMap
474450
475451Construct a (lazy) representation of the diagonal concatenation of the arguments.
476452To avoid fallback to the generic `Base.cat`, there must be a `LinearMap`
0 commit comments