Ordinal Indexing as a Language Feature

Indeed OffsetArrays.no_offset_view produces exactly this idea, but that doesn’t solve the issue that gets some people to ponder whether OffsetArrays.jl is a poison pill. Namely, we would ideally have something in Base which offers assurance that 1-based indices will work on an arbitrary AbstractArray.

This is exactly what OrdinalIndices.jl provides by offering an ordinal index type. I’m toying with the alternative approach of using an ordinally indexed view, that ordinal(A) will be a 1-based-indexed view of A.

Apparently this idea was already pondered here but deserves more exploration imo. It would be really easy to add it to the AbstractArray specification, and the fallback method is the easiest thing in the world.

ordinal(A::AbstractArray) = A

this would place the burden on OffsetArrays to add the method:

ordinal(A::OffsetArray) = ordinal(OffsetArrays.no_offset_view(A))
1 Like