diff --git a/Project.toml b/Project.toml index 26b8341..60bfa8c 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.4.1" +version = "0.5.0" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" diff --git a/docs/Project.toml b/docs/Project.toml index d3db650..898915b 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -8,4 +8,4 @@ SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208" Dictionaries = "0.4.4" Documenter = "1.8.1" Literate = "2.20.1" -SparseArraysBase = "0.4.0" +SparseArraysBase = "0.5.0" diff --git a/examples/Project.toml b/examples/Project.toml index c115b65..01ec629 100644 --- a/examples/Project.toml +++ b/examples/Project.toml @@ -5,5 +5,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] Dictionaries = "0.4.4" -SparseArraysBase = "0.4.0" +SparseArraysBase = "0.5.0" Test = "<0.0.1, 1" diff --git a/src/abstractsparsearrayinterface.jl b/src/abstractsparsearrayinterface.jl index 606cf2e..414108f 100644 --- a/src/abstractsparsearrayinterface.jl +++ b/src/abstractsparsearrayinterface.jl @@ -35,23 +35,22 @@ end # Minimal interface for `SparseArrayInterface`. # Fallbacks for dense/non-sparse arrays. -@interface ::AbstractArrayInterface function isstored( - a::AbstractArray{<:Any,N}, I::Vararg{Int,N} -) where {N} +function isstored(a::AbstractArray{<:Any,N}, I::Vararg{Int,N}) where {N} @_propagate_inbounds_meta @boundscheck checkbounds(a, I...) return true end -@interface interface::AbstractArrayInterface function isstored(a::AbstractArray, I::Int) +function isstored(a::AbstractArray, I::Int) @_propagate_inbounds_meta - return @interface interface isstored(a, Tuple(CartesianIndices(a)[I])...) + return isstored(a, Tuple(CartesianIndices(a)[I])...) end -@interface interface::AbstractArrayInterface function isstored(a::AbstractArray, I::Int...) +function isstored(a::AbstractArray, I::Int...) @_propagate_inbounds_meta @boundscheck checkbounds(a, I...) I′ = ntuple(i -> I[i], ndims(a)) - return @inbounds @interface interface isstored(a, I′...) + return isstored(a, I′...) end + @interface ::AbstractArrayInterface eachstoredindex(a::AbstractArray) = eachindex(a) @interface ::AbstractArrayInterface getstoredindex(a::AbstractArray, I::Int...) = getindex(a, I...) @@ -111,7 +110,6 @@ end SparseArraysBase.eachstoredindex(::T...) SparseArraysBase.getstoredindex(::T, ::Int...) SparseArraysBase.getunstoredindex(::T, ::Int...) - SparseArraysBase.isstored(::T, ::Int...) SparseArraysBase.setstoredindex!(::T, ::Any, ::Int...) SparseArraysBase.setunstoredindex!(::T, ::Any, ::Int...) SparseArraysBase.storedlength(::T) diff --git a/src/sparsearraydok.jl b/src/sparsearraydok.jl index 9f72bdb..4578163 100644 --- a/src/sparsearraydok.jl +++ b/src/sparsearraydok.jl @@ -74,7 +74,7 @@ storage(a::SparseArrayDOK) = a.storage Base.size(a::SparseArrayDOK) = a.size storedvalues(a::SparseArrayDOK) = values(storage(a)) -function isstored(a::SparseArrayDOK, I::Int...) +function isstored(a::SparseArrayDOK{<:Any,N}, I::Vararg{Int,N}) where {N} return @interface interface(a) isstored(a, I...) end function eachstoredindex(a::SparseArrayDOK) diff --git a/src/wrappers.jl b/src/wrappers.jl index f35b1a1..23b4286 100644 --- a/src/wrappers.jl +++ b/src/wrappers.jl @@ -106,10 +106,6 @@ function storedparentvalues(a::SubArray) return StoredValues(parent(a), collect(eachstoredparentindex(a))) end -@interface ::AbstractArrayInterface function isstored(a::SubArray, I::Int...) - return isstored(parent(a), index_to_parentindex(a, I...)...) -end - using LinearAlgebra: Transpose function parentindex_to_index(a::Transpose, I::CartesianIndex{2}) return cartesianindex_reverse(I) @@ -124,13 +120,30 @@ function value_to_parentvalue(a::Transpose, value) return transpose(value) end +function isstored_wrapped(a::AbstractArray{<:Any,N}, I::Vararg{Int,N}) where {N} + return isstored(parent(a), index_to_parentindex(a, I...)...) +end + +function isstored(a::Adjoint, I::Vararg{Int,2}) + return isstored_wrapped(a, I...) +end +function isstored(a::PermutedDimsArray{<:Any,N}, I::Vararg{Int,N}) where {N} + return isstored_wrapped(a, I...) +end +function isstored(a::ReshapedArray{<:Any,N}, I::Vararg{Int,N}) where {N} + return isstored_wrapped(a, I...) +end +function isstored(a::SubArray{<:Any,N}, I::Vararg{Int,N}) where {N} + return isstored_wrapped(a, I...) +end +function isstored(a::Transpose, I::Vararg{Int,2}) + return isstored_wrapped(a, I...) +end + # TODO: Turn these into `AbstractWrappedSparseArrayInterface` functions? for type in (:Adjoint, :PermutedDimsArray, :ReshapedArray, :SubArray, :Transpose) @eval begin @interface ::AbstractSparseArrayInterface storedvalues(a::$type) = storedparentvalues(a) - @interface ::AbstractSparseArrayInterface function isstored(a::$type, I::Int...) - return isstored(parent(a), index_to_parentindex(a, I...)...) - end @interface ::AbstractSparseArrayInterface function eachstoredindex(a::$type) # TODO: Make lazy with `Iterators.map`. return map(collect(eachstoredparentindex(a))) do I @@ -180,8 +193,9 @@ end @interface ::AbstractArrayInterface eachstoredindex(D::Diagonal) = _diagind(D, IndexCartesian()) -@interface ::AbstractArrayInterface isstored(D::Diagonal, i::Int, j::Int) = - i == j && Base.checkbounds(Bool, D, i, j) +function isstored(D::Diagonal, i::Int, j::Int) + return i == j && checkbounds(Bool, D, i, j) +end @interface ::AbstractArrayInterface function getstoredindex(D::Diagonal, i::Int, j::Int) return D.diag[i] end diff --git a/test/Project.toml b/test/Project.toml index cccbcc1..9b46e23 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -23,7 +23,7 @@ JLArrays = "0.2.0" LinearAlgebra = "<0.0.1, 1" Random = "<0.0.1, 1" SafeTestsets = "0.1.0" -SparseArraysBase = "0.4.0" +SparseArraysBase = "0.5.0" StableRNGs = "1.0.2" Suppressor = "0.2.8" Test = "<0.0.1, 1"