@@ -39,7 +39,8 @@ using BlockSparseArrays:
3939using GPUArraysCore: @allowscalar
4040using JLArrays: JLArray, JLMatrix
4141using LinearAlgebra: Adjoint, Transpose, dot, norm, tr
42- using SparseArraysBase: SparseArrayDOK, SparseMatrixDOK, SparseVectorDOK, storedlength
42+ using SparseArraysBase:
43+ SparseArrayDOK, SparseMatrixDOK, SparseVectorDOK, isstored, storedlength
4344using Test: @test , @test_broken , @test_throws , @testset , @inferred
4445using TestExtras: @constinferred
4546using TypeParameterAccessors: TypeParameterAccessors, Position
@@ -1159,6 +1160,24 @@ arrayts = (Array, JLArray)
11591160 @test view! (a, blk... ) == x
11601161 @test @view! (a[blk... ]) == x
11611162 end
1163+ # 0-dim case
1164+ # Regression test for https://github.com/ITensor/BlockSparseArrays.jl/issues/148
1165+ for I in ((), (Block (),))
1166+ a = dev (BlockSparseArray {elt} (undef))
1167+ @test ! isstored (a)
1168+ @test iszero (blockstoredlength (a))
1169+ @test isempty (eachblockstoredindex (a))
1170+ @test iszero (a)
1171+ b = @view! a[I... ]
1172+ @test isstored (a)
1173+ @test isone (blockstoredlength (a))
1174+ @test issetequal (eachblockstoredindex (a), [Block ()])
1175+ @test iszero (adapt (Array)(a))
1176+ @test b isa arrayt{elt,0 }
1177+ @test size (b) == ()
1178+ # Converting to `Array` works around a bug in `iszero(JLArray{Float64}(undef))`.
1179+ @test iszero (adapt (Array)(b))
1180+ end
11621181 end
11631182 @testset " LinearAlgebra" begin
11641183 a1 = dev (BlockSparseArray {elt} (undef, [2 , 3 ], [2 , 3 ]))
0 commit comments