@@ -308,19 +308,28 @@ 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
- style:: IndexStyle , A:: AbstractArray
318
+ style:: IndexCartesian , 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))
321
- else
322
- throw (ArgumentError (lazy " unknown index style $style" ))
323
- end
320
+ error_if_canonical_eachstoredindex (style, A)
321
+ inds = eachstoredindex (A)
322
+ eltype (inds) === CartesianIndex{ndims (A)} && return inds
323
+ return map (Base. Fix1 (Base. getindex, CartesianIndices (A)), inds)
324
+ end
325
+
326
+ @interface :: AbstractSparseArrayInterface function eachstoredindex (
327
+ style:: IndexLinear , A:: AbstractArray
328
+ )
329
+ error_if_canonical_eachstoredindex (style, A)
330
+ inds = eachstoredindex (A)
331
+ eltype (inds) === Int && return inds
332
+ return map (Base. Fix1 (Base. getindex, LinearIndices (A)), inds)
324
333
end
325
334
326
335
# derived but may be specialized:
0 commit comments