Skip to content

Commit ebf83a2

Browse files
committed
Update indexing for wrappers
1 parent 1e30cee commit ebf83a2

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/wrappers.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
parentvalue_to_value(a::AbstractArray, value) = value
22
value_to_parentvalue(a::AbstractArray, value) = value
3-
eachstoredparentindex(a::AbstractArray) = eachstoredindex(parent(a))
3+
eachstoredparentindex(a::AbstractArray) = eachstoredparentindex(IndexStyle(a), a)
4+
function eachstoredparentindex(style::IndexStyle, a::AbstractArray)
5+
return eachstoredindex(style, parent(a))
6+
end
47
storedparentvalues(a::AbstractArray) = storedvalues(parent(a))
58

69
function parentindex_to_index(a::AbstractArray{<:Any,N}, I::CartesianIndex{N}) where {N}
@@ -71,8 +74,8 @@ function index_to_parentindex(a::ReshapedArray, I::CartesianIndex)
7174
return CartesianIndices(parent(a))[LinearIndices(size(a))[I]]
7275
end
7376

74-
function eachstoredparentindex(a::SubArray)
75-
return filter(eachstoredindex(parent(a))) do I
77+
function eachstoredparentindex(style::IndexStyle, a::SubArray)
78+
return filter(eachstoredindex(style, parent(a))) do I
7679
return all(d -> I[d] parentindices(a)[d], 1:ndims(parent(a)))
7780
end
7881
end
@@ -144,9 +147,11 @@ end
144147
for type in (:Adjoint, :PermutedDimsArray, :ReshapedArray, :SubArray, :Transpose)
145148
@eval begin
146149
@interface ::AbstractSparseArrayInterface storedvalues(a::$type) = storedparentvalues(a)
147-
@interface ::AbstractSparseArrayInterface function eachstoredindex(a::$type)
150+
@interface ::AbstractSparseArrayInterface function eachstoredindex(
151+
style::IndexStyle, a::$type
152+
)
148153
# TODO: Make lazy with `Iterators.map`.
149-
return map(collect(eachstoredparentindex(a))) do I
154+
return map(eachstoredparentindex(style, a)) do I
150155
return parentindex_to_index(a, I)
151156
end
152157
end
@@ -193,7 +198,7 @@ end
193198
@interface ::AbstractArrayInterface eachstoredindex(D::Diagonal) =
194199
_diagind(D, IndexCartesian())
195200

196-
function isstored(D::Diagonal, i::Int, j::Int)
201+
@interface ::AbstractArrayInterface function isstored(D::Diagonal, i::Int, j::Int)
197202
return i == j && checkbounds(Bool, D, i, j)
198203
end
199204
@interface ::AbstractArrayInterface function getstoredindex(D::Diagonal, i::Int, j::Int)

0 commit comments

Comments
 (0)