diff --git a/Project.toml b/Project.toml index 0a2cd552..a550e68e 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.3.0" +version = "0.3.1" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" @@ -43,7 +43,7 @@ LabelledNumbers = "0.1.0" LinearAlgebra = "1.10" MacroTools = "0.5.13" MapBroadcast = "0.1.5" -SparseArraysBase = "0.3" +SparseArraysBase = "0.3.2" SplitApplyCombine = "1.2.3" TensorAlgebra = "0.1.0, 0.2" Test = "1.10" diff --git a/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl b/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl index 39225d1a..1f1a8619 100644 --- a/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl +++ b/src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl @@ -9,7 +9,7 @@ using BlockArrays: blockedrange, mortar, unblock -using DerivableInterfaces: DerivableInterfaces, @interface +using DerivableInterfaces: DerivableInterfaces, @interface, DefaultArrayInterface using GPUArraysCore: @allowscalar using SplitApplyCombine: groupcount using TypeParameterAccessors: similartype @@ -338,11 +338,20 @@ function Base.Array(a::AnyAbstractBlockSparseArray) end function SparseArraysBase.isstored( - A::AnyAbstractBlockSparseArray{<:Any,N}, I::Vararg{Int,N} + a::AnyAbstractBlockSparseArray{<:Any,N}, I::Vararg{Int,N} ) where {N} - bI = BlockIndex(findblockindex.(axes(A), I)) - bA = blocks(A) - return isstored(bA, bI.I...) && isstored(bA[bI.I...], bI.α...) + bI = BlockIndex(findblockindex.(axes(a), I)) + blocks_a = blocks(a) + return isstored(blocks_a, bI.I...) && isstored(blocks_a[bI.I...], bI.α...) +end + +# This circumvents issues passing certain kinds of SubArrays +# to the more generic block sparse `isstored` definition, +# for example `blocks(a)` is broken for certain slices. +function SparseArraysBase.isstored( + a::SubArray{<:Any,N,<:AbstractBlockSparseArray}, I::Vararg{Int,N} +) where {N} + return @interface DefaultArrayInterface() isstored(a, I...) end function Base.replace_in_print_matrix( diff --git a/test/test_basics.jl b/test/test_basics.jl index e39e2667..144128c3 100644 --- a/test/test_basics.jl +++ b/test/test_basics.jl @@ -1148,10 +1148,16 @@ arrayts = (Array, JLArray) if elt === Float64 # Not testing other element types since they change the # spacing so it isn't easy to make the test general. + a = BlockSparseMatrix{elt,arrayt{elt,2}}(undef, [2, 2], [2, 2]) @allowscalar a[1, 2] = 12 @test sprint(show, "text/plain", a) == "$(summary(a)):\n $(zero(eltype(a))) $(eltype(a)(12)) │ ⋅ ⋅ \n $(zero(eltype(a))) $(zero(eltype(a))) │ ⋅ ⋅ \n ───────────┼──────────\n ⋅ ⋅ │ ⋅ ⋅ \n ⋅ ⋅ │ ⋅ ⋅ " + + a = BlockSparseArray{elt,3,arrayt{elt,3}}(undef, [2, 2], [2, 2], [2, 2]) + @allowscalar a[1, 2, 1] = 121 + @test sprint(show, "text/plain", a) == + "$(summary(a)):\n[:, :, 1] =\n $(zero(eltype(a))) $(eltype(a)(121)) ⋅ ⋅ \n $(zero(eltype(a))) $(zero(eltype(a))) ⋅ ⋅ \n ⋅ ⋅ ⋅ ⋅ \n ⋅ ⋅ ⋅ ⋅ \n\n[:, :, 2] =\n $(zero(eltype(a))) $(zero(eltype(a))) ⋅ ⋅ \n $(zero(eltype(a))) $(zero(eltype(a))) ⋅ ⋅ \n ⋅ ⋅ ⋅ ⋅ \n ⋅ ⋅ ⋅ ⋅ \n\n[:, :, 3] =\n ⋅ ⋅ ⋅ ⋅ \n ⋅ ⋅ ⋅ ⋅ \n ⋅ ⋅ ⋅ ⋅ \n ⋅ ⋅ ⋅ ⋅ \n\n[:, :, 4] =\n ⋅ ⋅ ⋅ ⋅ \n ⋅ ⋅ ⋅ ⋅ \n ⋅ ⋅ ⋅ ⋅ \n ⋅ ⋅ ⋅ ⋅ " end end @testset "TypeParameterAccessors.position" begin