From 1ec32cda9771ae05b205d2ed32ade372f9669be8 Mon Sep 17 00:00:00 2001 From: CompatHelper Julia Date: Fri, 18 Jul 2025 02:22:37 +0000 Subject: [PATCH 01/10] CompatHelper: bump compat for SparseArraysBase to 0.6, (keep existing compat) --- Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 318969d..fe24ed9 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.22" +version = "0.7.23" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" @@ -40,7 +40,7 @@ LinearAlgebra = "1.10" MacroTools = "0.5.13" MapBroadcast = "0.1.5" MatrixAlgebraKit = "0.2.2" -SparseArraysBase = "0.5" +SparseArraysBase = "0.5, 0.6" SplitApplyCombine = "1.2.3" TensorAlgebra = "0.3.2" Test = "1.10" From ac6d62a7dd4b5f09c6c0ef2daa1b173298a5ad7a Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Fri, 18 Jul 2025 08:18:25 -0400 Subject: [PATCH 02/10] Update Project.toml --- test/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index 6b6cd9a..0c62ddb 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -34,7 +34,7 @@ LinearAlgebra = "1" MatrixAlgebraKit = "0.2.5" Random = "1" SafeTestsets = "0.1" -SparseArraysBase = "0.5.11" +SparseArraysBase = "0.6" StableRNGs = "1" Suppressor = "0.2" TensorAlgebra = "0.3.2" From 748653bb2031eadf01b727ac336ee11e98b7de2f Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Fri, 18 Jul 2025 08:19:16 -0400 Subject: [PATCH 03/10] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index fe24ed9..794693a 100644 --- a/Project.toml +++ b/Project.toml @@ -40,7 +40,7 @@ LinearAlgebra = "1.10" MacroTools = "0.5.13" MapBroadcast = "0.1.5" MatrixAlgebraKit = "0.2.2" -SparseArraysBase = "0.5, 0.6" +SparseArraysBase = "0.6" SplitApplyCombine = "1.2.3" TensorAlgebra = "0.3.2" Test = "1.10" From f7754bc2438162b50771c395fdec3182a7e411b5 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Fri, 18 Jul 2025 16:14:35 -0400 Subject: [PATCH 04/10] Better names --- Project.toml | 2 +- src/blocksparsearray/blocksparsearray.jl | 4 +- .../getunstoredblock.jl | 39 ++++++++++--------- test/Project.toml | 2 +- test/test_basics.jl | 14 +++---- 5 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Project.toml b/Project.toml index 794693a..1e11238 100644 --- a/Project.toml +++ b/Project.toml @@ -40,7 +40,7 @@ LinearAlgebra = "1.10" MacroTools = "0.5.13" MapBroadcast = "0.1.5" MatrixAlgebraKit = "0.2.2" -SparseArraysBase = "0.6" +SparseArraysBase = "0.7" SplitApplyCombine = "1.2.3" TensorAlgebra = "0.3.2" Test = "1.10" diff --git a/src/blocksparsearray/blocksparsearray.jl b/src/blocksparsearray/blocksparsearray.jl index 70bd0b7..957828f 100644 --- a/src/blocksparsearray/blocksparsearray.jl +++ b/src/blocksparsearray/blocksparsearray.jl @@ -8,7 +8,7 @@ using BlockArrays: undef_blocks using DerivableInterfaces: @interface using Dictionaries: Dictionary -using SparseArraysBase: SparseArrayDOK +using SparseArraysBase: SparseArrayDOK, Unstored using TypeParameterAccessors: similartype """ @@ -25,7 +25,7 @@ and should be imported from that package to use it as an input to this construct function SparseArraysBase.SparseArrayDOK{T,N}( ::UndefBlocksInitializer, ax::Tuple{Vararg{AbstractUnitRange{<:Integer},N}} ) where {T,N} - return SparseArrayDOK{T,N}(undef, blocklength.(ax); getunstored=GetUnstoredBlock(ax)) + return SparseArrayDOK{T,N}(Unstored(ZeroBlocks{N,T}(ax))) end function SparseArraysBase.SparseArrayDOK{T,N}( ::UndefBlocksInitializer, ax::Vararg{AbstractUnitRange{<:Integer},N} diff --git a/src/blocksparsearrayinterface/getunstoredblock.jl b/src/blocksparsearrayinterface/getunstoredblock.jl index fcb0760..2ea3035 100644 --- a/src/blocksparsearrayinterface/getunstoredblock.jl +++ b/src/blocksparsearrayinterface/getunstoredblock.jl @@ -1,39 +1,40 @@ using BlockArrays: Block using DerivableInterfaces: zero! -struct GetUnstoredBlock{Axes} - axes::Axes +struct ZeroBlocks{ + N,A<:AbstractArray{<:Any,N},ParentAxes<:Tuple{Vararg{AbstractUnitRange{<:Integer},N}} +} <: AbstractArray{A,N} + parentaxes::ParentAxes +end +function ZeroBlocks{N,A}( + ax::Ax +) where {N,A<:AbstractArray{<:Any,N},Ax<:Tuple{Vararg{AbstractUnitRange{<:Integer},N}}} + return ZeroBlocks{N,A,Ax}(ax) +end +Base.size(a::ZeroBlocks) = map(blocklength, a.parentaxes) + +function Base.AbstractArray{A}(a::ZeroBlocks{N}) where {N,A} + return ZeroBlocks{N,A}(a.parentaxes) end -@inline function (f::GetUnstoredBlock)( - ::Type{<:AbstractArray{A,N}}, I::Vararg{Int,N} -) where {A,N} +@inline function Base.getindex(a::ZeroBlocks{N,A}, I::Vararg{Int,N}) where {N,A} ax = ntuple(N) do d - return only(axes(f.axes[d][Block(I[d])])) + return only(axes(a.parentaxes[d][Block(I[d])])) end !isconcretetype(A) && return zero!(similar(Array{eltype(A),N}, ax)) return zero!(similar(A, ax)) end -@inline function (f::GetUnstoredBlock)( - a::AbstractArray{<:Any,N}, I::Vararg{Int,N} -) where {N} - return f(typeof(a), I...) -end # TODO: Use `Base.to_indices`. -@inline function (f::GetUnstoredBlock)( - a::AbstractArray{<:Any,N}, I::CartesianIndex{N} -) where {N} - return f(a, Tuple(I)...) +@inline function Base.getindex(a::ZeroBlocks{N,A}, I::CartesianIndex{N}) where {N,A} + return a[Tuple(I)...] end # TODO: this is a hack and is also type-unstable using LinearAlgebra: Diagonal using TypeParameterAccessors: similartype -function (f::GetUnstoredBlock)( - ::Type{<:AbstractMatrix{<:Diagonal{<:Any,V}}}, I::Vararg{Int,2} -) where {V} +function Base.getindex(a::ZeroBlocks{2,A}, I::Vararg{Int,2}) where {V,A<:Diagonal{<:Any,V}} ax = ntuple(2) do d - return only(axes(f.axes[d][Block(I[d])])) + return only(axes(a.parentaxes[d][Block(I[d])])) end if allequal(I) return Diagonal(zero!(similar(V, first(ax)))) diff --git a/test/Project.toml b/test/Project.toml index 0c62ddb..ff3c891 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -34,7 +34,7 @@ LinearAlgebra = "1" MatrixAlgebraKit = "0.2.5" Random = "1" SafeTestsets = "0.1" -SparseArraysBase = "0.6" +SparseArraysBase = "0.7" StableRNGs = "1" Suppressor = "0.2" TensorAlgebra = "0.3.2" diff --git a/test/test_basics.jl b/test/test_basics.jl index a464fa3..536c7a2 100644 --- a/test/test_basics.jl +++ b/test/test_basics.jl @@ -399,7 +399,7 @@ arrayts = (Array, JLArray) a_dest = a1 * a2 @allowscalar @test Array(a_dest) ≈ Array(a1) * Array(a2) @test a_dest isa BlockSparseArray{elt} - @test blockstoredlength(a_dest) == 1 + @test_broken blockstoredlength(a_dest) == 1 end @testset "Matrix multiplication" begin a1 = dev(BlockSparseArray{elt}(undef, [2, 3], [2, 3])) @@ -430,23 +430,23 @@ arrayts = (Array, JLArray) a2[Block(1, 2)] = dev(randn(elt, size(@view(a2[Block(1, 2)])))) a_dest = cat(a1, a2; dims=1) - @test blockstoredlength(a_dest) == 2 + @test_broken blockstoredlength(a_dest) == 2 @test blocklengths.(axes(a_dest)) == ([2, 3, 2, 3], [2, 3]) - @test issetequal(eachblockstoredindex(a_dest), [Block(2, 1), Block(3, 2)]) + @test_broken issetequal(eachblockstoredindex(a_dest), [Block(2, 1), Block(3, 2)]) @test a_dest[Block(2, 1)] == a1[Block(2, 1)] @test a_dest[Block(3, 2)] == a2[Block(1, 2)] a_dest = cat(a1, a2; dims=2) - @test blockstoredlength(a_dest) == 2 + @test_broken blockstoredlength(a_dest) == 2 @test blocklengths.(axes(a_dest)) == ([2, 3], [2, 3, 2, 3]) - @test issetequal(eachblockstoredindex(a_dest), [Block(2, 1), Block(1, 4)]) + @test_broken issetequal(eachblockstoredindex(a_dest), [Block(2, 1), Block(1, 4)]) @test a_dest[Block(2, 1)] == a1[Block(2, 1)] @test a_dest[Block(1, 4)] == a2[Block(1, 2)] a_dest = cat(a1, a2; dims=(1, 2)) - @test blockstoredlength(a_dest) == 2 + @test_broken blockstoredlength(a_dest) == 2 @test blocklengths.(axes(a_dest)) == ([2, 3, 2, 3], [2, 3, 2, 3]) - @test issetequal(eachblockstoredindex(a_dest), [Block(2, 1), Block(3, 4)]) + @test_broken issetequal(eachblockstoredindex(a_dest), [Block(2, 1), Block(3, 4)]) @test a_dest[Block(2, 1)] == a1[Block(2, 1)] @test a_dest[Block(3, 4)] == a2[Block(1, 2)] end From c6d1d15fb393d9e993f1766ef1242ebabbd9326d Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 21 Jul 2025 13:40:57 -0400 Subject: [PATCH 05/10] Format --- .../blocksparsearrayinterface.jl | 4 +++- src/blocksparsearrayinterface/getunstoredblock.jl | 1 + test/Project.toml | 1 + test/test_basics.jl | 14 +++++++------- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/blocksparsearrayinterface/blocksparsearrayinterface.jl b/src/blocksparsearrayinterface/blocksparsearrayinterface.jl index 29d8324..9ca44e5 100644 --- a/src/blocksparsearrayinterface/blocksparsearrayinterface.jl +++ b/src/blocksparsearrayinterface/blocksparsearrayinterface.jl @@ -410,7 +410,9 @@ function SparseArraysBase.getunstoredindex( _perm(a.array), ) end -function SparseArraysBase.eachstoredindex(a::SparsePermutedDimsArrayBlocks) +function SparseArraysBase.eachstoredindex( + ::IndexCartesian, a::SparsePermutedDimsArrayBlocks +) return map(I -> _getindices(I, _perm(a.array)), eachstoredindex(blocks(parent(a.array)))) end ## TODO: Define `storedvalues` instead. diff --git a/src/blocksparsearrayinterface/getunstoredblock.jl b/src/blocksparsearrayinterface/getunstoredblock.jl index 2ea3035..d704f05 100644 --- a/src/blocksparsearrayinterface/getunstoredblock.jl +++ b/src/blocksparsearrayinterface/getunstoredblock.jl @@ -18,6 +18,7 @@ function Base.AbstractArray{A}(a::ZeroBlocks{N}) where {N,A} end @inline function Base.getindex(a::ZeroBlocks{N,A}, I::Vararg{Int,N}) where {N,A} + # TODO: Use `BlockArrays.eachblockaxes`. ax = ntuple(N) do d return only(axes(a.parentaxes[d][Block(I[d])])) end diff --git a/test/Project.toml b/test/Project.toml index ff3c891..e5b649d 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -8,6 +8,7 @@ DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f" DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527" JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb" +KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" diff --git a/test/test_basics.jl b/test/test_basics.jl index 536c7a2..a464fa3 100644 --- a/test/test_basics.jl +++ b/test/test_basics.jl @@ -399,7 +399,7 @@ arrayts = (Array, JLArray) a_dest = a1 * a2 @allowscalar @test Array(a_dest) ≈ Array(a1) * Array(a2) @test a_dest isa BlockSparseArray{elt} - @test_broken blockstoredlength(a_dest) == 1 + @test blockstoredlength(a_dest) == 1 end @testset "Matrix multiplication" begin a1 = dev(BlockSparseArray{elt}(undef, [2, 3], [2, 3])) @@ -430,23 +430,23 @@ arrayts = (Array, JLArray) a2[Block(1, 2)] = dev(randn(elt, size(@view(a2[Block(1, 2)])))) a_dest = cat(a1, a2; dims=1) - @test_broken blockstoredlength(a_dest) == 2 + @test blockstoredlength(a_dest) == 2 @test blocklengths.(axes(a_dest)) == ([2, 3, 2, 3], [2, 3]) - @test_broken issetequal(eachblockstoredindex(a_dest), [Block(2, 1), Block(3, 2)]) + @test issetequal(eachblockstoredindex(a_dest), [Block(2, 1), Block(3, 2)]) @test a_dest[Block(2, 1)] == a1[Block(2, 1)] @test a_dest[Block(3, 2)] == a2[Block(1, 2)] a_dest = cat(a1, a2; dims=2) - @test_broken blockstoredlength(a_dest) == 2 + @test blockstoredlength(a_dest) == 2 @test blocklengths.(axes(a_dest)) == ([2, 3], [2, 3, 2, 3]) - @test_broken issetequal(eachblockstoredindex(a_dest), [Block(2, 1), Block(1, 4)]) + @test issetequal(eachblockstoredindex(a_dest), [Block(2, 1), Block(1, 4)]) @test a_dest[Block(2, 1)] == a1[Block(2, 1)] @test a_dest[Block(1, 4)] == a2[Block(1, 2)] a_dest = cat(a1, a2; dims=(1, 2)) - @test_broken blockstoredlength(a_dest) == 2 + @test blockstoredlength(a_dest) == 2 @test blocklengths.(axes(a_dest)) == ([2, 3, 2, 3], [2, 3, 2, 3]) - @test_broken issetequal(eachblockstoredindex(a_dest), [Block(2, 1), Block(3, 4)]) + @test issetequal(eachblockstoredindex(a_dest), [Block(2, 1), Block(3, 4)]) @test a_dest[Block(2, 1)] == a1[Block(2, 1)] @test a_dest[Block(3, 4)] == a2[Block(1, 2)] end From 6864773333a48cafee984afc0560e84a0a24acd3 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 21 Jul 2025 16:43:20 -0400 Subject: [PATCH 06/10] Updates for SparseArraysBase v0.7.1 --- Project.toml | 2 +- src/blocksparsearray/blocksparsearray.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 1e11238..d8bcf14 100644 --- a/Project.toml +++ b/Project.toml @@ -40,7 +40,7 @@ LinearAlgebra = "1.10" MacroTools = "0.5.13" MapBroadcast = "0.1.5" MatrixAlgebraKit = "0.2.2" -SparseArraysBase = "0.7" +SparseArraysBase = "0.7.1" SplitApplyCombine = "1.2.3" TensorAlgebra = "0.3.2" Test = "1.10" diff --git a/src/blocksparsearray/blocksparsearray.jl b/src/blocksparsearray/blocksparsearray.jl index 957828f..15af2f7 100644 --- a/src/blocksparsearray/blocksparsearray.jl +++ b/src/blocksparsearray/blocksparsearray.jl @@ -25,7 +25,7 @@ and should be imported from that package to use it as an input to this construct function SparseArraysBase.SparseArrayDOK{T,N}( ::UndefBlocksInitializer, ax::Tuple{Vararg{AbstractUnitRange{<:Integer},N}} ) where {T,N} - return SparseArrayDOK{T,N}(Unstored(ZeroBlocks{N,T}(ax))) + return SparseArrayDOK{T,N}(undef, Unstored(ZeroBlocks{N,T}(ax))) end function SparseArraysBase.SparseArrayDOK{T,N}( ::UndefBlocksInitializer, ax::Vararg{AbstractUnitRange{<:Integer},N} From b65aebd908b065f5ffcce026ac3e118b84dd746c Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Mon, 21 Jul 2025 16:44:31 -0400 Subject: [PATCH 07/10] Update test/Project.toml --- test/Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index e5b649d..ff3c891 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -8,7 +8,6 @@ DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f" DiagonalArrays = "74fd4be6-21e2-4f6f-823a-4360d37c7a77" GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527" JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb" -KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" From 560d125b410a1d43039dfaf63abf010696b1f1da Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 21 Jul 2025 16:50:17 -0400 Subject: [PATCH 08/10] Mark as breaking --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index d8bcf14..7ac7a30 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.23" +version = "0.8.0" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" From a50d53fefc76a30020f2b30a5977923852afa28b Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 21 Jul 2025 16:52:09 -0400 Subject: [PATCH 09/10] Bump subdir versions --- docs/Project.toml | 2 +- examples/Project.toml | 2 +- test/Project.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/Project.toml b/docs/Project.toml index da8df1a..7885be6 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -6,6 +6,6 @@ Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" [compat] BlockArrays = "1" -BlockSparseArrays = "0.7" +BlockSparseArrays = "0.8" Documenter = "1" Literate = "2" diff --git a/examples/Project.toml b/examples/Project.toml index b7d9305..6c17bd7 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -5,5 +5,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] BlockArrays = "1" -BlockSparseArrays = "0.7" +BlockSparseArrays = "0.8" Test = "1" diff --git a/test/Project.toml b/test/Project.toml index ff3c891..52ef862 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -25,7 +25,7 @@ Adapt = "4" Aqua = "0.8" ArrayLayouts = "1" BlockArrays = "1" -BlockSparseArrays = "0.7" +BlockSparseArrays = "0.8" DerivableInterfaces = "0.5" DiagonalArrays = "0.3" GPUArraysCore = "0.2" From 6bc532b5ab448bbc07f42732d711e0e85b247222 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 21 Jul 2025 17:04:12 -0400 Subject: [PATCH 10/10] Try fixing tests --- test/Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index 52ef862..3759f5b 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -25,7 +25,6 @@ Adapt = "4" Aqua = "0.8" ArrayLayouts = "1" BlockArrays = "1" -BlockSparseArrays = "0.8" DerivableInterfaces = "0.5" DiagonalArrays = "0.3" GPUArraysCore = "0.2"