diff --git a/Project.toml b/Project.toml index 318969d5..7ac7a301 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.8.0" [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.7.1" SplitApplyCombine = "1.2.3" TensorAlgebra = "0.3.2" Test = "1.10" diff --git a/docs/Project.toml b/docs/Project.toml index da8df1ab..7885be60 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 b7d93053..6c17bd70 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/src/blocksparsearray/blocksparsearray.jl b/src/blocksparsearray/blocksparsearray.jl index 70bd0b7b..15af2f77 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}(undef, Unstored(ZeroBlocks{N,T}(ax))) end function SparseArraysBase.SparseArrayDOK{T,N}( ::UndefBlocksInitializer, ax::Vararg{AbstractUnitRange{<:Integer},N} diff --git a/src/blocksparsearrayinterface/blocksparsearrayinterface.jl b/src/blocksparsearrayinterface/blocksparsearrayinterface.jl index 29d83242..9ca44e5a 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 fcb07604..d704f05a 100644 --- a/src/blocksparsearrayinterface/getunstoredblock.jl +++ b/src/blocksparsearrayinterface/getunstoredblock.jl @@ -1,39 +1,41 @@ 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} + # TODO: Use `BlockArrays.eachblockaxes`. 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 6b6cd9aa..3759f5b4 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -25,7 +25,6 @@ Adapt = "4" Aqua = "0.8" ArrayLayouts = "1" BlockArrays = "1" -BlockSparseArrays = "0.7" DerivableInterfaces = "0.5" DiagonalArrays = "0.3" GPUArraysCore = "0.2" @@ -34,7 +33,7 @@ LinearAlgebra = "1" MatrixAlgebraKit = "0.2.5" Random = "1" SafeTestsets = "0.1" -SparseArraysBase = "0.5.11" +SparseArraysBase = "0.7" StableRNGs = "1" Suppressor = "0.2" TensorAlgebra = "0.3.2"