Skip to content

Commit bd91790

Browse files
committed
Update indexstyle for eachstoredindex
1 parent b4b2328 commit bd91790

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/indexing.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,18 @@ end
308308
end
309309
end
310310

311-
# required:
312-
@interface ::AbstractSparseArrayInterface eachstoredindex(style::IndexStyle, A::AbstractArray) = throw(
313-
MethodError(eachstoredindex, Tuple{typeof(style),typeof(A)})
314-
)
311+
# required: one implementation for canonical index style
312+
@interface ::AbstractSparseArrayInterface function eachstoredindex(style::IndexStyle, A::AbstractArray)
313+
if style == IndexStyle(A)
314+
throw(MethodError(eachstoredindex, Tuple{typeof(style),typeof(A)}))
315+
elseif style == IndexCartesian()
316+
return map(Base.Fix1(Base.getindex, CartesianIndices(A)), eachindex(A))
317+
elseif style == IndexLinear()
318+
return map(Base.Fix1(Base.getindex, LinearIndices(A)), eachindex(A))
319+
else
320+
throw(ArgumentError(lazy"unknown index style $style"))
321+
end
322+
end
315323

316324
# derived but may be specialized:
317325
@interface ::AbstractSparseArrayInterface function eachstoredindex(

src/oneelementarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ storedindex(a::OneElementArray) = getfield(a, :index)
287287
function isstored(a::OneElementArray, I::Int...)
288288
return I == storedindex(a)
289289
end
290-
function eachstoredindex(a::OneElementArray)
290+
function eachstoredindex(::IndexCartesian, a::OneElementArray)
291291
return Fill(CartesianIndex(storedindex(a)), 1)
292292
end
293293

0 commit comments

Comments
 (0)