@@ -308,18 +308,25 @@ end
308
308
end
309
309
end
310
310
311
+ @noinline function error_if_canonical_eachstoredindex (style:: IndexStyle , A:: AbstractArray )
312
+ style === IndexStyle (A) && throw (Base. CanonicalIndexError (" eachstoredindex" , typeof (A)))
313
+ return nothing
314
+ end
315
+
311
316
# required: one implementation for canonical index style
312
317
@interface :: AbstractSparseArrayInterface function eachstoredindex (
313
318
style:: IndexStyle , A:: AbstractArray
314
319
)
315
- if style == IndexStyle (A)
316
- throw (MethodError (eachstoredindex, Tuple{typeof (style),typeof (A)}))
317
- elseif style == IndexCartesian ()
318
- return map (Base. Fix1 (Base. getindex, CartesianIndices (A)), eachindex (A))
319
- elseif style == IndexLinear ()
320
- return map (Base. Fix1 (Base. getindex, LinearIndices (A)), eachindex (A))
320
+ error_if_canonical_eachstoredindex (style, A)
321
+ inds = eachstoredindex (A)
322
+ if style === IndexCartesian ()
323
+ eltype (inds) === CartesianIndex{ndims (A)} && return inds
324
+ return map (Base. Fix1 (Base. getindex, CartesianIndices (A)), inds)
325
+ elseif style === IndexLinear ()
326
+ eltype (inds) === Int && return inds
327
+ return map (Base. Fix1 (Base. getindex, LinearIndices (A)), inds)
321
328
else
322
- throw ( ArgumentError ( lazy "unknown index style $style" ) )
329
+ error ( lazy "unkown index style $style" )
323
330
end
324
331
end
325
332
0 commit comments