Skip to content

Introduce getunstoredindex_function #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SparseArraysBase"
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.6.0"
version = "0.6.1"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
9 changes: 7 additions & 2 deletions src/abstractsparsearrayinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ using DerivableInterfaces:

function eachstoredindex end
function getstoredindex end
function getunstoredindex end
function getunstoredindex_function end
function isstored end
function setstoredindex! end
function setunstoredindex! end
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
Expand Down Expand Up @@ -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
using DerivableInterfaces: DerivableInterfaces, zero!

Expand Down
3 changes: 2 additions & 1 deletion src/sparsearraydok.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading