# Does \`AbstractArray\` itself need to support indexing beyond 1-based?

**URL:** https://discourse.julialang.org/t/does-abstractarray-itself-need-to-support-indexing-beyond-1-based/83324
**Category:** Internals & Design
**Tags:** indexing
**Created:** [June 25, 2022, 1:26am UTC](https://discourse.julialang.org/t/does-abstractarray-itself-need-to-support-indexing-beyond-1-based/83324 "2022-06-25T01:26:43Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![JohnnyChen94](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnnychen94/32/29979_2.png) [@JohnnyChen94](https://discourse.julialang.org/u/JohnnyChen94)
#### Post date: [June 25, 2022, 2:13am UTC](https://discourse.julialang.org/t/does-abstractarray-itself-need-to-support-indexing-beyond-1-based/83324/2 "2022-06-25T02:13:59Z")

</div>

I’m not sure if I understand your proposal so my reply might not address your questions.

`OffsetArray` is only one of the many array types that might have non-1-based indexing, thus dispatching `my_alg(::OffsetArray)` is not a good solution.

Maybe letting `AbstractArray` contain static information in its types is a good idea (`AbstractArray{T,2,(1,1)}` where `(1,1)` indicates the offsets), but there will be too difficult to raise this discussion in Julia and get it merged – too many things will be involved to embrace this new interface. Thus I don’t think this will happen.

Even if we’ve managed to work through it, we’ll eventually find that parametrizing the offset values might not be very helpful in practice (speaking of performance):

> [@Offset array package with offsets in the type?](https://discourse.julialang.org/t/offset-array-package-with-offsets-in-the-type/81772/11):
>
> For a single getindex/setindex! const offset might help. But for most cases, we access the elements many times within a function. LLVM might not know the offset value, but it knows it won’t change. So the overhead could be ignored for most usecase.

Oh, and the secret to supporting generic programming without much headache is to [orthogonalize your design](https://docs.julialang.org/en/v1/manual/methods/#man-methods-orthogonalize). The `Base.require_one_based_indexing` is exactly such a tool to help orthogonalization.

---

_[View the full topic](https://discourse.julialang.org/t/does-abstractarray-itself-need-to-support-indexing-beyond-1-based/83324)._
