Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.5.5"
version = "0.5.6"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
83 changes: 47 additions & 36 deletions src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Obtain `getindex(A, I...)` with the guarantee that there is a stored entry at th

Similar to `Base.getindex`, new definitions should be in line with `IndexStyle(A)`.
"""
@inline getstoredindex(A::AbstractArray, I...) =
@interface interface(A) getstoredindex(A, I...)
@inline getstoredindex(A::AbstractArray, I...) = @interface interface(A) getstoredindex(
A, I...
)

"""
getunstoredindex(A::AbstractArray, I...) -> eltype(A)
Expand All @@ -25,8 +26,9 @@ instantiated object.

Similar to `Base.getindex`, new definitions should be in line with `IndexStyle(A)`.
"""
@inline getunstoredindex(A::AbstractArray, I...) =
@interface interface(A) getunstoredindex(A, I...)
@inline getunstoredindex(A::AbstractArray, I...) = @interface interface(A) getunstoredindex(
A, I...
)

"""
isstored(A::AbstractArray, I...) -> Bool
Expand All @@ -46,8 +48,9 @@ Similar to `Base.getindex`, new definitions should be in line with `IndexStyle(A

Similar to `Base.setindex!`, new definitions should be in line with `IndexStyle(A)`.
"""
@inline setstoredindex!(A::AbstractArray, v, I...) =
@interface interface(A) setstoredindex!(A, v, I...)
@inline setstoredindex!(A::AbstractArray, v, I...) = @interface interface(A) setstoredindex!(
A, v, I...
)

"""
setunstoredindex!(A::AbstractArray, v, I...) -> A
Expand All @@ -56,8 +59,9 @@ Similar to `Base.setindex!`, new definitions should be in line with `IndexStyle(

Similar to `Base.setindex!`, new definitions should be in line with `IndexStyle(A)`.
"""
@inline setunstoredindex!(A::AbstractArray, v, I...) =
@interface interface(A) setunstoredindex!(A, v, I...)
@inline setunstoredindex!(A::AbstractArray, v, I...) = @interface interface(A) setunstoredindex!(
A, v, I...
)

# Indices interface
# -----------------
Expand Down Expand Up @@ -150,14 +154,16 @@ for f in (:isstored, :getunstoredindex, :getstoredindex)
end

# errors
$_f(::IndexStyle, A::AbstractArray, I...) =
error("`$f` for $("$(typeof(A))") with types $("$(typeof(I))") is not supported")

$error_if_canonical(::IndexLinear, A::AbstractArray, ::Int) =
throw(Base.CanonicalIndexError("$($f)", typeof(A)))
$error_if_canonical(
::IndexCartesian, A::AbstractArray{<:Any,N}, ::Vararg{Int,N}
) where {N} = throw(Base.CanonicalIndexError("$($f)", typeof(A)))
$_f(::IndexStyle, A::AbstractArray, I...) = error(
"`$f` for $("$(typeof(A))") with types $("$(typeof(I))") is not supported"
)

$error_if_canonical(::IndexLinear, A::AbstractArray, ::Int) = throw(
Base.CanonicalIndexError("$($f)", typeof(A))
)
$error_if_canonical(::IndexCartesian, A::AbstractArray{<:Any,N}, ::Vararg{Int,N}) where {N} = throw(
Base.CanonicalIndexError("$($f)", typeof(A))
)
$error_if_canonical(::IndexStyle, A::AbstractArray, ::Any...) = nothing
end
end
Expand Down Expand Up @@ -193,14 +199,16 @@ for f! in (:setunstoredindex!, :setstoredindex!)
end

# errors
$_f!(::IndexStyle, A::AbstractArray, I...) =
error("`$f!` for $("$(typeof(A))") with types $("$(typeof(I))") is not supported")

$error_if_canonical(::IndexLinear, A::AbstractArray, ::Int) =
throw(Base.CanonicalIndexError("$($(string(f!)))", typeof(A)))
$error_if_canonical(
::IndexCartesian, A::AbstractArray{<:Any,N}, ::Vararg{Int,N}
) where {N} = throw(Base.CanonicalIndexError("$($f!)", typeof(A)))
$_f!(::IndexStyle, A::AbstractArray, I...) = error(
"`$f!` for $("$(typeof(A))") with types $("$(typeof(I))") is not supported"
)

$error_if_canonical(::IndexLinear, A::AbstractArray, ::Int) = throw(
Base.CanonicalIndexError("$($(string(f!)))", typeof(A))
)
$error_if_canonical(::IndexCartesian, A::AbstractArray{<:Any,N}, ::Vararg{Int,N}) where {N} = throw(
Base.CanonicalIndexError("$($f!)", typeof(A))
)
$error_if_canonical(::IndexStyle, A::AbstractArray, ::Any...) = nothing
end
end
Expand All @@ -227,14 +235,16 @@ end
@inline
return setindex!(A, v, I...)
end
@interface ::AbstractArrayInterface setunstoredindex!(A::AbstractArray, v, I::Int...) =
error("setunstoredindex! for $(typeof(A)) is not supported")
@interface ::AbstractArrayInterface setunstoredindex!(A::AbstractArray, v, I::Int...) = error(
"setunstoredindex! for $(typeof(A)) is not supported"
)

@interface ::AbstractArrayInterface eachstoredindex(A::AbstractArray, B::AbstractArray...) =
eachstoredindex(IndexStyle(A, B...), A, B...)
@interface ::AbstractArrayInterface eachstoredindex(
style::IndexStyle, A::AbstractArray, B::AbstractArray...
) = eachindex(style, A, B...)
@interface ::AbstractArrayInterface eachstoredindex(A::AbstractArray, B::AbstractArray...) = eachstoredindex(
IndexStyle(A, B...), A, B...
)
@interface ::AbstractArrayInterface eachstoredindex(style::IndexStyle, A::AbstractArray, B::AbstractArray...) = eachindex(
style, A, B...
)

@interface ::AbstractArrayInterface storedvalues(A::AbstractArray) = values(A)
@interface ::AbstractArrayInterface storedpairs(A::AbstractArray) = pairs(A)
Expand Down Expand Up @@ -299,9 +309,9 @@ end
end

# required:
@interface ::AbstractSparseArrayInterface eachstoredindex(
style::IndexStyle, A::AbstractArray
) = throw(MethodError(eachstoredindex, Tuple{typeof(style),typeof(A)}))
@interface ::AbstractSparseArrayInterface eachstoredindex(style::IndexStyle, A::AbstractArray) = throw(
MethodError(eachstoredindex, Tuple{typeof(style),typeof(A)})
)

# derived but may be specialized:
@interface ::AbstractSparseArrayInterface function eachstoredindex(
Expand Down Expand Up @@ -379,8 +389,9 @@ for f! in (:setstoredindex!, :setunstoredindex!)
end
end

@interface ::AbstractSparseArrayInterface storedlength(A::AbstractArray) =
length(storedvalues(A))
@interface ::AbstractSparseArrayInterface storedlength(A::AbstractArray) = length(
storedvalues(A)
)
@interface ::AbstractSparseArrayInterface function storedpairs(A::AbstractArray)
return Iterators.map(I -> (I => A[I]), eachstoredindex(A))
end
Expand Down
5 changes: 3 additions & 2 deletions src/wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ else
return view(CartesianIndices(x), LinearAlgebra.diagind(x))
end
end
@interface ::AbstractArrayInterface eachstoredindex(D::Diagonal) =
_diagind(D, IndexCartesian())
@interface ::AbstractArrayInterface eachstoredindex(D::Diagonal) = _diagind(
D, IndexCartesian()
)

@interface ::AbstractArrayInterface function isstored(D::Diagonal, i::Int, j::Int)
return i == j && checkbounds(Bool, D, i, j)
Expand Down
6 changes: 4 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ const GROUP = uppercase(
)

"match files of the form `test_*.jl`, but exclude `*setup*.jl`"
istestfile(fn) =
function istestfile(fn)
endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup")
end
"match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl`"
isexamplefile(fn) =
function isexamplefile(fn)
endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup")
end

@time begin
# tests in groups based on folder structure
Expand Down