Skip to content

Commit a9dd3b0

Browse files
committed
Special case scalar broadcasting
1 parent 090c202 commit a9dd3b0

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/blocksparsearrayinterface/broadcast.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ function Base.similar(bc::Broadcasted{<:BlockSparseArrayStyle}, elt::Type)
3636
return similar(first(m.args), elt, combine_axes(axes.(m.args)...))
3737
end
3838

39+
# Catches cases like `dest .= value` or `dest .= value1 .+ value2`.
40+
# If the RHS is zero, this makes sure that the storage is emptied,
41+
# which is logic that is handled by `fill!`.
42+
function copyto_blocksparse!(dest::AbstractArray, bc::Broadcasted{<:AbstractArrayStyle{0}})
43+
value = bc.f(bc.args...)
44+
return fill!(dest, value)
45+
end
46+
3947
# Broadcasting implementation
4048
# TODO: Delete this in favor of `DerivableInterfaces` version.
4149
function copyto_blocksparse!(dest::AbstractArray, bc::Broadcasted)

test/test_gradedunitrangesext.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
325325
a = cat(a1, a2; dims=(1, 2))
326326
b = a[r, dual(r)]
327327
@test eltype(b) === elt
328-
@test b isa BlockSpareMatrix{elt}
328+
@test b isa BlockSparseMatrix{elt}
329329
@test blockstoredlength(b) == 2
330330
@test b[Block(1, 1)] == a1
331331
@test iszero(b[Block(2, 1)])

0 commit comments

Comments
 (0)