Skip to content

Commit 683b35d

Browse files
authored
Fix setting zero dimensional block (#28)
1 parent 004403d commit 683b35d

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
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.2.7"
4+
version = "0.2.8"
55

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

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ function main()
8282
@test b[Block(1, 2)] == a₁₂
8383

8484
# Matrix multiplication
85-
# TODO: Fix this, broken.
86-
@test_broken b * b Array(b) * Array(b)
85+
@test b * b Array(b) * Array(b)
8786

8887
permuted_b = permutedims(b, (2, 1))
8988
@test permuted_b isa BlockSparseArray

examples/README.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ function main()
8787
@test b[Block(1, 2)] == a₁₂
8888

8989
## Matrix multiplication
90-
## TODO: Fix this, broken.
91-
@test_broken b * b Array(b) * Array(b)
90+
@test b * b Array(b) * Array(b)
9291

9392
permuted_b = permutedims(b, (2, 1))
9493
@test permuted_b isa BlockSparseArray

src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ end
157157
a::AbstractArray{<:Any,0}, value, I::BlockIndex{0}
158158
)
159159
a_b = blocks(a)[]
160-
a_b[] = value
160+
# `value[]` handles scalars and 0-dimensional arrays.
161+
a_b[] = value[]
161162
# Set the block, required if it is structurally zero.
162163
blocks(a)[] = a_b
163164
return a

test/basics/test_basics.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ arrayts = (Array, JLArray)
192192
for b in (
193193
(b = copy(a); @allowscalar b[] = 2; b),
194194
(b = copy(a); @allowscalar b[CartesianIndex()] = 2; b),
195+
(b = copy(a); @allowscalar b[CartesianIndex()] = 2; b),
196+
# Regression test for https://github.com/ITensor/BlockSparseArrays.jl/issues/27.
197+
(b = copy(a); @allowscalar b[Block()] = dev(fill(2)); b),
195198
)
196199
@test size(b) == ()
197200
@test isone(length(b))
@@ -202,8 +205,7 @@ arrayts = (Array, JLArray)
202205
@test @allowscalar(b[CartesianIndex()]) == 2
203206
@test b[Block()] == dev(fill(2))
204207
@test @allowscalar(b[Block()][]) == 2
205-
# Broken:
206-
## @test b[Block()[]] == 2
208+
@test @allowscalar(b[Block()[]]) == 2
207209
end
208210
end
209211

test/runtests.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ isexamplefile(fn) =
2424
# tests in groups based on folder structure
2525
for testgroup in filter(isdir, readdir(@__DIR__))
2626
if GROUP == "ALL" || GROUP == uppercase(testgroup)
27-
for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join=true))
27+
groupdir = joinpath(@__DIR__, testgroup)
28+
for file in filter(istestfile, readdir(groupdir))
29+
filename = joinpath(groupdir, file)
2830
@eval @safetestset $file begin
29-
include($file)
31+
include($filename)
3032
end
3133
end
3234
end

0 commit comments

Comments
 (0)