# Arrays with no size and/or non-sequential integers

**URL:** <https://discourse.julialang.org/t/arrays-with-no-size-and-or-non-sequential-integers/41140>\
**Category:** New to Julia\
**Tags:** indexing, array\
**Created:** [June 10, 2020, 4:10pm UTC](https://discourse.julialang.org/t/arrays-with-no-size-and-or-non-sequential-integers/41140 "2020-06-10T16:10:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [June 10, 2020, 4:10pm UTC](https://discourse.julialang.org/t/arrays-with-no-size-and-or-non-sequential-integers/41140/1 "2020-06-10T16:10:05Z")

</div>

I just stumbled on two phrases in the manual that puzzle me:

In [Arrays · The Julia Language](https://docs.julialang.org/en/v1/base/arrays/#Base.size) it says

> Note that `size` may not be defined for arrays with non-standard indices, in which case [`axes`](https://docs.julialang.org/en/v1/base/arrays/#Base.axes-Tuple%7BAny%7D) may be useful. See the manual chapter on [arrays with custom indices](https://docs.julialang.org/en/v1/devdocs/offset-arrays/#man-custom-indices-1).

What kind of array doesn’t have a `size` defined? I can’t find an example, and the “chapter on arrays with custom indices” only says:

> In some cases it may also be helpful to temporarily disable `size` and `length` for your new array type, since code that makes incorrect assumptions frequently uses these functions.

which sounds more like a temporary debug thing than a real array without `size`.

The other phrase is at [Arrays with custom indices · The Julia Language](https://docs.julialang.org/en/v1/devdocs/offset-arrays/#Linear-indexing-(LinearIndices)-1) :

> For this reason, your best option may be to iterate over the array with `eachindex(A)` , or, if you require the indices to be sequential integers, to get the index range by calling `LinearIndices(A)` .

In which case would `eachindex(A)` give values that are not sequential integers?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [June 10, 2020, 4:31pm UTC](https://discourse.julialang.org/t/arrays-with-no-size-and-or-non-sequential-integers/41140/2 "2020-06-10T16:31:21Z")

</div>

The most common case I’m aware of involves arrays whose axes do not start at one (see [GitHub - JuliaArrays/OffsetArrays.jl: Fortran-like arrays with arbitrary, zero or negative starting indices.](https://github.com/JuliaArrays/OffsetArrays.jl) ). Disabling `size` and `length` can help avoid users accidentally trying to do:

```julia
for i in 1:size(offset_array, 1)
  do_something(offset_array[i, ...])
end

```

which wrongly assumes that `1:size(...)` is the correct set of indices.

Instead, users can be encouraged to do:

```julia
for i in axes(might_be_an_offset_array_or_not, 1)
  ...
end

```

which will work whether or not the array indices start at 1.
