@@ -84,17 +84,13 @@ function Base.hcat(As::Union{LinearMap, UniformScaling, AbstractVecOrMat}...)
84
84
T = promote_type (map (eltype, As)... )
85
85
nbc = length (As)
86
86
87
- nrows = - 1
88
87
# find first non-UniformScaling to detect number of rows
89
- for A in As
90
- if ! (A isa UniformScaling)
91
- nrows = size (A, 1 )
92
- break
93
- end
94
- end
95
- @assert nrows != - 1
88
+ j = findfirst (x -> ! isa (x, UniformScaling), As)
96
89
# this should not happen, function should only be called with at least one LinearMap
97
- return BlockMap {T} (promote_to_lmaps (ntuple (i-> nrows, nbc), 1 , 1 , As... ), (nbc,))
90
+ @assert ! isnothing (j)
91
+ nrows = size (As[j], 1 )
92
+
93
+ return BlockMap {T} (promote_to_lmaps (ntuple (_ -> nrows, Val (nbc)), 1 , 1 , As... ), (nbc,))
98
94
end
99
95
100
96
# ###########
@@ -126,18 +122,14 @@ function Base.vcat(As::Union{LinearMap,UniformScaling,AbstractVecOrMat}...)
126
122
T = promote_type (map (eltype, As)... )
127
123
nbr = length (As)
128
124
129
- ncols = - 1
130
- # find first non-UniformScaling to detect number of columns
131
- for A in As
132
- if ! (A isa UniformScaling)
133
- ncols = size (A, 2 )
134
- break
135
- end
136
- end
137
- @assert ncols != - 1
125
+ # find first non-UniformScaling to detect number of rows
126
+ j = findfirst (x -> ! isa (x, UniformScaling), As)
138
127
# this should not happen, function should only be called with at least one LinearMap
139
- rows = ntuple (i-> 1 , nbr)
140
- return BlockMap {T} (promote_to_lmaps (ntuple (i-> ncols, nbr), 1 , 2 , As... ), rows)
128
+ @assert ! isnothing (j)
129
+ ncols = size (As[j], 2 )
130
+
131
+ rows = ntuple (i-> 1 , Val (nbr))
132
+ return BlockMap {T} (promote_to_lmaps (ntuple (_ -> ncols, Val (nbr)), 1 , 2 , As... ), rows)
141
133
end
142
134
143
135
# ###########
0 commit comments