From 6b862701da54c86e72e9c3664ae8063ea4792a8e Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 17 Jul 2025 18:15:14 -0400 Subject: [PATCH] Introduce getunstoredindex_function --- Project.toml | 2 +- src/abstractsparsearrayinterface.jl | 9 +++++++-- src/sparsearraydok.jl | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 7f585fd..b45de75 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SparseArraysBase" uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208" authors = ["ITensor developers and contributors"] -version = "0.5.11" +version = "0.6.1" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" diff --git a/src/abstractsparsearrayinterface.jl b/src/abstractsparsearrayinterface.jl index 6af80e6..e7b9bca 100644 --- a/src/abstractsparsearrayinterface.jl +++ b/src/abstractsparsearrayinterface.jl @@ -4,7 +4,7 @@ using DerivableInterfaces: function eachstoredindex end function getstoredindex end -function getunstoredindex end +function getunstoredindex_function end function isstored end function setstoredindex! end function setunstoredindex! end @@ -12,6 +12,11 @@ function storedlength end function storedpairs end function storedvalues end +@inline function getunstoredindex(a::AbstractArray{<:Any,N}, I::Vararg{Int,N}) where {N} + @boundscheck checkbounds(a, I...) + return getunstoredindex_function(a)(a, I...) +end + # Replace the function for accessing # unstored values. function set_getunstoredindex end @@ -90,7 +95,7 @@ end a::AbstractArray, T::Type, size::Tuple{Vararg{Int}} ) # TODO: Define `default_similartype` or something like that? - return SparseArrayDOK{T}(undef, size) + return SparseArrayDOK{T}(undef, size; getunstored=getunstoredindex_function(a)) end # map over a specified subset of indices of the inputs. diff --git a/src/sparsearraydok.jl b/src/sparsearraydok.jl index 8d123dc..78eac00 100644 --- a/src/sparsearraydok.jl +++ b/src/sparsearraydok.jl @@ -87,9 +87,10 @@ end @boundscheck checkbounds(a, I...) return storage(a)[CartesianIndex(I)] end +@inline getunstoredindex_function(a::SparseArrayDOK) = a.getunstored @inline function getunstoredindex(a::SparseArrayDOK{<:Any,N}, I::Vararg{Int,N}) where {N} @boundscheck checkbounds(a, I...) - return a.getunstored(a, I...) + return getunstoredindex_function(a)(a, I...) end @inline function setstoredindex!( a::SparseArrayDOK{<:Any,N}, value, I::Vararg{Int,N}