|
| 1 | +using Base: @_propagate_inbounds_meta |
1 | 2 | using DerivableInterfaces: DerivableInterfaces, @derive, @interface, AbstractArrayInterface
|
2 | 3 |
|
3 | 4 | # This is to bring `ArrayLayouts.zero!` into the namespace
|
|
37 | 38 | @interface ::AbstractArrayInterface function isstored(
|
38 | 39 | a::AbstractArray{<:Any,N}, I::Vararg{Int,N}
|
39 | 40 | ) where {N}
|
| 41 | + @_propagate_inbounds_meta |
40 | 42 | @boundscheck checkbounds(a, I...)
|
41 | 43 | return true
|
42 | 44 | end
|
43 |
| -@interface ::AbstractArrayInterface function isstored(a::AbstractArray, I::Int...) |
| 45 | +@interface interface::AbstractArrayInterface function isstored(a::AbstractArray, I::Int) |
| 46 | + @_propagate_inbounds_meta |
| 47 | + return @interface interface isstored(a, Tuple(CartesianIndices(a)[I])...) |
| 48 | +end |
| 49 | +@interface interface::AbstractArrayInterface function isstored(a::AbstractArray, I::Int...) |
| 50 | + @_propagate_inbounds_meta |
44 | 51 | @boundscheck checkbounds(a, I...)
|
45 | 52 | I′ = ntuple(i -> I[i], ndims(a))
|
46 |
| - return isstored(a, I′...) |
| 53 | + return @inbounds @interface interface isstored(a, I′...) |
47 | 54 | end
|
48 | 55 | @interface ::AbstractArrayInterface eachstoredindex(a::AbstractArray) = eachindex(a)
|
49 | 56 | @interface ::AbstractArrayInterface getstoredindex(a::AbstractArray, I::Int...) =
|
@@ -163,6 +170,12 @@ function Base.setindex!(a::StoredValues, value, I::Int)
|
163 | 170 | return setstoredindex!(a.array, value, a.storedindices[I])
|
164 | 171 | end
|
165 | 172 |
|
| 173 | +@interface ::AbstractSparseArrayInterface function isstored( |
| 174 | + a::AbstractArray{<:Any,N}, I::Vararg{Int,N} |
| 175 | +) where {N} |
| 176 | + return CartesianIndex(I) in eachstoredindex(a) |
| 177 | +end |
| 178 | + |
166 | 179 | @interface ::AbstractSparseArrayInterface storedvalues(a::AbstractArray) = StoredValues(a)
|
167 | 180 |
|
168 | 181 | @interface ::AbstractSparseArrayInterface function eachstoredindex(
|
|
0 commit comments