diff --git a/Project.toml b/Project.toml index 720a92b..cf07790 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.7.13" +version = "0.7.14" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/BlockArraysExtensions/BlockArraysExtensions.jl b/src/BlockArraysExtensions/BlockArraysExtensions.jl index 31e3ac9..c4d034d 100644 --- a/src/BlockArraysExtensions/BlockArraysExtensions.jl +++ b/src/BlockArraysExtensions/BlockArraysExtensions.jl @@ -561,6 +561,11 @@ function view!(a::AbstractArray{<:Any,N}, index::Vararg{Block{1},N}) where {N} blocks(a)[Int.(index)...] = blocks(a)[Int.(index)...] return blocks(a)[Int.(index)...] end +# Fix ambiguity error. +function view!(a::AbstractArray{<:Any,0}) + blocks(a)[] = blocks(a)[] + return blocks(a)[] +end function view!(a::AbstractArray{<:Any,N}, index::BlockIndexRange{N}) where {N} # TODO: Is there a better code pattern for this? diff --git a/test/test_basics.jl b/test/test_basics.jl index b399b58..cde6f2e 100644 --- a/test/test_basics.jl +++ b/test/test_basics.jl @@ -39,7 +39,8 @@ using BlockSparseArrays: using GPUArraysCore: @allowscalar using JLArrays: JLArray, JLMatrix using LinearAlgebra: Adjoint, Transpose, dot, norm, tr -using SparseArraysBase: SparseArrayDOK, SparseMatrixDOK, SparseVectorDOK, storedlength +using SparseArraysBase: + SparseArrayDOK, SparseMatrixDOK, SparseVectorDOK, isstored, storedlength using Test: @test, @test_broken, @test_throws, @testset, @inferred using TestExtras: @constinferred using TypeParameterAccessors: TypeParameterAccessors, Position @@ -1159,6 +1160,24 @@ arrayts = (Array, JLArray) @test view!(a, blk...) == x @test @view!(a[blk...]) == x end + # 0-dim case + # Regression test for https://github.com/ITensor/BlockSparseArrays.jl/issues/148 + for I in ((), (Block(),)) + a = dev(BlockSparseArray{elt}(undef)) + @test !isstored(a) + @test iszero(blockstoredlength(a)) + @test isempty(eachblockstoredindex(a)) + @test iszero(a) + b = @view! a[I...] + @test isstored(a) + @test isone(blockstoredlength(a)) + @test issetequal(eachblockstoredindex(a), [Block()]) + @test iszero(adapt(Array)(a)) + @test b isa arrayt{elt,0} + @test size(b) == () + # Converting to `Array` works around a bug in `iszero(JLArray{Float64}(undef))`. + @test iszero(adapt(Array)(b)) + end end @testset "LinearAlgebra" begin a1 = dev(BlockSparseArray{elt}(undef, [2, 3], [2, 3]))