@@ -229,6 +229,30 @@ function blockbanded_axpy!(a, X::AbstractMatrix, Y::AbstractMatrix)
229
229
Y
230
230
end
231
231
232
+ for op in (:+ , :- )
233
+ @eval begin
234
+ function similar (bc:: Broadcasted{<:BlockBandedStyle, <:Any, typeof($op), <:Tuple{<:AbstractMatrix,<:AbstractMatrix}} , :: Type{T} ) where T
235
+ A,B = bc. args
236
+ A_size = blocksizes (A). block_sizes
237
+ A_size == blocksizes (B). block_sizes || throw (DimensionMismatch ())
238
+ Al,Au = blockbandwidths (A)
239
+ Bl,Bu = blockbandwidths (B)
240
+ BlockBandedMatrix {T} (undef, A_size, (max (Al,Bl), max (Au,Bu)))
241
+ end
242
+
243
+ function similar (bc:: Broadcasted{<:BandedBlockBandedStyle, <:Any, typeof($op), <:Tuple{<:AbstractMatrix,<:AbstractMatrix}} , :: Type{T} ) where T
244
+ A,B = bc. args
245
+ A_size = blocksizes (A). block_sizes
246
+ A_size == blocksizes (B). block_sizes || throw (DimensionMismatch ())
247
+ Al,Au = blockbandwidths (A)
248
+ Bl,Bu = blockbandwidths (B)
249
+ Aλ,Aμ = subblockbandwidths (A)
250
+ Bλ,Bμ = subblockbandwidths (B)
251
+
252
+ BandedBlockBandedMatrix {T} (undef, A_size, (max (Al,Bl), max (Au,Bu)), (max (Aλ,Bλ), max (Aμ,Bμ)))
253
+ end
254
+ end
255
+ end
232
256
233
257
function copyto! (dest:: AbstractArray{T} , bc:: Broadcasted {<: AbstractBlockBandedStyle , <: Any , typeof (+ ),
234
258
<: Tuple{<:AbstractMatrix,<:AbstractMatrix} }) where T
@@ -244,29 +268,23 @@ function copyto!(dest::AbstractArray{T}, bc::Broadcasted{<:AbstractBlockBandedSt
244
268
end
245
269
end
246
270
247
- function similar (bc:: Broadcasted{<:BlockBandedStyle, <:Any, typeof(+), <:Tuple{<:AbstractMatrix,<:AbstractMatrix}} , :: Type{T} ) where T
248
- A,B = bc. args
249
- A_size = blocksizes (A). block_sizes
250
- A_size == blocksizes (B). block_sizes || throw (DimensionMismatch ())
251
- Al,Au = blockbandwidths (A)
252
- Bl,Bu = blockbandwidths (B)
253
- BlockBandedMatrix {T} (undef, A_size, (max (Al,Bl), max (Au,Bu)))
254
- end
255
-
256
- function similar (bc:: Broadcasted{<:BandedBlockBandedStyle, <:Any, typeof(+), <:Tuple{<:AbstractMatrix,<:AbstractMatrix}} , :: Type{T} ) where T
271
+ function copyto! (dest:: AbstractArray{T} , bc:: Broadcasted {<: AbstractBlockBandedStyle , <: Any , typeof (- ),
272
+ <: Tuple{<:AbstractMatrix,<:AbstractMatrix} }) where T
257
273
A,B = bc. args
258
- A_size = blocksizes (A). block_sizes
259
- A_size == blocksizes (B). block_sizes || throw (DimensionMismatch ())
260
- Al,Au = blockbandwidths (A)
261
- Bl,Bu = blockbandwidths (B)
262
- Aλ,Aμ = subblockbandwidths (A)
263
- Bλ,Bμ = subblockbandwidths (B)
264
274
265
- BandedBlockBandedMatrix {T} (undef, A_size, (max (Al,Bl), max (Au,Bu)), (max (Aλ,Bλ), max (Aμ,Bμ)))
275
+ if dest ≡ B
276
+ lmul! (- one (T), B)
277
+ blockbanded_axpy! (one (T), A, dest)
278
+ elseif dest ≡ A
279
+ blockbanded_axpy! (- one (T), B, dest)
280
+ else
281
+ blockbanded_copyto! (dest, B)
282
+ lmul! (- one (T), dest)
283
+ blockbanded_axpy! (one (T), A, dest)
284
+ end
266
285
end
267
286
268
287
269
-
270
288
function copyto! (dest:: AbstractArray{T} , bc:: Broadcasted {<: AbstractBlockBandedStyle , <: Any , typeof (+ ),
271
289
<: Tuple {<: Broadcasted{<:AbstractBlockBandedStyle,<:Any,typeof(*),<:Tuple{<:Number,<:AbstractMatrix}} ,
272
290
<: AbstractMatrix }}) where T
0 commit comments