From 5db70d159a76c958a31b10efea11ee6527fd87f9 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Wed, 15 Jan 2025 15:56:08 -0500 Subject: [PATCH 1/5] Fix setting zero dimensional block --- src/blocksparsearrayinterface/blocksparsearrayinterface.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/blocksparsearrayinterface/blocksparsearrayinterface.jl b/src/blocksparsearrayinterface/blocksparsearrayinterface.jl index 0aace04d..46f95ca0 100644 --- a/src/blocksparsearrayinterface/blocksparsearrayinterface.jl +++ b/src/blocksparsearrayinterface/blocksparsearrayinterface.jl @@ -157,7 +157,8 @@ end a::AbstractArray{<:Any,0}, value, I::BlockIndex{0} ) a_b = blocks(a)[] - a_b[] = value + # `value[]` handles scalars and 0-dimensional arrays. + a_b[] = value[] # Set the block, required if it is structurally zero. blocks(a)[] = a_b return a From 944ac82bddfbe75fcb9944227672937fa4dd46d8 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Wed, 15 Jan 2025 17:20:32 -0500 Subject: [PATCH 2/5] Add tests --- Project.toml | 2 +- examples/README.jl | 3 +-- test/basics/test_basics.jl | 6 ++++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index 2a2d8b2c..c7a8b187 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BlockSparseArrays" uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4" authors = ["ITensor developers and contributors"] -version = "0.2.7" +version = "0.2.8" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/examples/README.jl b/examples/README.jl index 7374d883..2d00e5b0 100644 --- a/examples/README.jl +++ b/examples/README.jl @@ -87,8 +87,7 @@ function main() @test b[Block(1, 2)] == a₁₂ ## Matrix multiplication - ## TODO: Fix this, broken. - @test_broken b * b ≈ Array(b) * Array(b) + @test b * b ≈ Array(b) * Array(b) permuted_b = permutedims(b, (2, 1)) @test permuted_b isa BlockSparseArray diff --git a/test/basics/test_basics.jl b/test/basics/test_basics.jl index 71f5d15e..921fc82d 100644 --- a/test/basics/test_basics.jl +++ b/test/basics/test_basics.jl @@ -192,6 +192,9 @@ arrayts = (Array, JLArray) for b in ( (b = copy(a); @allowscalar b[] = 2; b), (b = copy(a); @allowscalar b[CartesianIndex()] = 2; b), + (b = copy(a); @allowscalar b[CartesianIndex()] = 2; b), + # Regression test for https://github.com/ITensor/BlockSparseArrays.jl/issues/27. + (b = copy(a); @allowscalar b[Block()] = dev(fill(2)); b), ) @test size(b) == () @test isone(length(b)) @@ -202,8 +205,7 @@ arrayts = (Array, JLArray) @test @allowscalar(b[CartesianIndex()]) == 2 @test b[Block()] == dev(fill(2)) @test @allowscalar(b[Block()][]) == 2 - # Broken: - ## @test b[Block()[]] == 2 + @test b[Block()[]] == 2 end end From f431be0d3e890c88d94bd39470b4aec7f3ac62a9 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Wed, 15 Jan 2025 17:25:54 -0500 Subject: [PATCH 3/5] Update README --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 40fdf33c..e2f415e4 100644 --- a/README.md +++ b/README.md @@ -82,8 +82,7 @@ function main() @test b[Block(1, 2)] == a₁₂ # Matrix multiplication - # TODO: Fix this, broken. - @test_broken b * b ≈ Array(b) * Array(b) + @test b * b ≈ Array(b) * Array(b) permuted_b = permutedims(b, (2, 1)) @test permuted_b isa BlockSparseArray From 3a24990ad54ba07dfc0eaa5347595ccbd5e53e10 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Wed, 15 Jan 2025 17:27:57 -0500 Subject: [PATCH 4/5] Fix test --- test/basics/test_basics.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/basics/test_basics.jl b/test/basics/test_basics.jl index 921fc82d..afe403fe 100644 --- a/test/basics/test_basics.jl +++ b/test/basics/test_basics.jl @@ -205,7 +205,7 @@ arrayts = (Array, JLArray) @test @allowscalar(b[CartesianIndex()]) == 2 @test b[Block()] == dev(fill(2)) @test @allowscalar(b[Block()][]) == 2 - @test b[Block()[]] == 2 + @test @allowscalar(b[Block()[]]) == 2 end end From f9d4c21d91f688c7cfac7765290e414d80b81886 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Wed, 15 Jan 2025 17:34:44 -0500 Subject: [PATCH 5/5] Update runtests --- test/runtests.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index bd974411..1c52c3e1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -24,9 +24,11 @@ isexamplefile(fn) = # tests in groups based on folder structure for testgroup in filter(isdir, readdir(@__DIR__)) if GROUP == "ALL" || GROUP == uppercase(testgroup) - for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join=true)) + groupdir = joinpath(@__DIR__, testgroup) + for file in filter(istestfile, readdir(groupdir)) + filename = joinpath(groupdir, file) @eval @safetestset $file begin - include($file) + include($filename) end end end