I was thinking about the thread (partially) about the incompatibility of some existing AbstractArray
methods with OffsetArray
s, and it got me wondering why AbstractArray
was extended beyond 1-based indexing. Sticking to 1-based indexing has worked for most users in practice, and this is reflected in many other languages not supporting arbitrary starting indices. Although Fortran supports arbitrary bounds, even it has a 1-based default and convention.
The argument I’ve heard is that some algorithms are simplified if an input array can have 0-based or rotated indices. However, it seems to me that it’s enough to wrap 1-based arrays in OffsetArray
(what happens in practice) to pass into such algorithms, and use no_offset_view
to get the 1-based array.
With this, only OffsetArray
s would require writing the more generic axes(A, i), eachindex(A), LinearIndices(A), begin, firstindex(A i), end, lastindex(A, i)
. For the vast 1-based majority of AbstractArray
s, OneTo
axes and UnitRange
/StepRange
subsets are easier to write and more intuitive in practice. Even OffsetArray
itself needs to be more complicated to wrap non-1-based arrays. Also, instead of having to check if AbstractArray
methods require_one_based_indexing
and can’t accept an OffsetArray
, the separation of okay-to-be-1-based algorithms and sometimes-cannot-be-1-based algorithms will be fully reflected in the type system, AbstractArray{T,N}
versus OffsetArray{T,N,AA<:AbstractArray{T,N}} # no supertype
.
So am I missing some advantages to the AbstractArray
interface’s ideal support for offset indices over a hypothetical separation of OffsetArray
from a not-so-hypothetically 1-based AbstractArray
?