Skip to content

Commit 55d25ec

Browse files
committed
Fix 0-dim broadcasting bug
1 parent 8cfd7f9 commit 55d25ec

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BlockSparseArrays"
22
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.10.0"
4+
version = "0.10.1"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/blocksparsearrayinterface/broadcast.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ end
6363
# which is logic that is handled by `fill!`.
6464
function copyto_blocksparse!(dest::AbstractArray, bc::Broadcasted{<:AbstractArrayStyle{0}})
6565
# `[]` is used to unwrap zero-dimensional arrays.
66-
value = @allowscalar bc.f(bc.args...)[]
66+
bcf = Broadcast.flatten(bc)
67+
value = @allowscalar bcf.f(map(arg -> arg[], bcf.args)...)
6768
return @interface BlockSparseArrayInterface() fill!(dest, value)
6869
end
6970

test/test_map.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ arrayts = (Array, JLArray)
8383
@test blocktype(a′) <: arrayt{Float32,3}
8484
@test axes(a′) == (blockedrange([2, 4]), blockedrange([2, 5]), blockedrange([2, 2]))
8585

86+
# Regression test for 0-dimensional in-place broadcasting.
87+
rng = StableRNG(123)
88+
a = dev(BlockSparseArray{elt}(undef))
89+
a[] = randn(rng, elt)
90+
b = dev(BlockSparseArray{elt}(undef))
91+
b[] = randn(rng, elt)
92+
c = similar(a)
93+
c .= 2 .* a .+ 3 .* b
94+
@test c[] == 2 * a[] + 3 * b[]
95+
8696
a = dev(BlockSparseArray{elt}(undef, ([2, 3], [3, 4])))
8797
@views for b in [Block(1, 2), Block(2, 1)]
8898
a[b] = dev(randn(elt, size(a[b])))

0 commit comments

Comments
 (0)