# Linearindexing, LinearFast and LinearSlow

**URL:** <https://discourse.julialang.org/t/linearindexing-linearfast-and-linearslow/4172>\
**Category:** General Usage\
**Created:** [June 9, 2017, 11:41am UTC](https://discourse.julialang.org/t/linearindexing-linearfast-and-linearslow/4172 "2017-06-09T11:41:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 9, 2017, 11:41am UTC](https://discourse.julialang.org/t/linearindexing-linearfast-and-linearslow/4172/1 "2017-06-09T11:41:56Z")

</div>

I have been trying to figure out when exactly is it clearly stupid not to define `linearindexing(::Type{T}) = Base.LinearFast()` for some (1D) indexable type T? So could someone please explain when to use Base.LinearFast and why I get the following errors even though all of Array, String and Tuple are indexable?

```julia
julia> Base.linearindexing(Array)
Base.LinearFast()

julia> Base.linearindexing(String)
ERROR: MethodError: no method matching linearindexing(::Type{String})
Closest candidates are:
  linearindexing(::Base.LinearFast, ::Base.LinearFast) at abstractarray.jl:239
  linearindexing(::Base.SparseArrays.CHOLMOD.Dense{T<:Union{Complex{Float64},Flo
at64}}) at sparse\cholmod.jl:1124
  linearindexing(::Base.SparseArrays.CHOLMOD.Sparse{Tv<:Union{Complex{Float64},F
loat64}}) at sparse\cholmod.jl:1145
  ...

julia> Base.linearindexing(Tuple)
ERROR: MethodError: no method matching linearindexing(::Type{Tuple})
Closest candidates are:
  linearindexing(::Base.LinearFast, ::Base.LinearFast) at abstractarray.jl:239
  linearindexing(::Base.SparseArrays.CHOLMOD.Dense{T<:Union{Complex{Float64},Flo
at64}}) at sparse\cholmod.jl:1124
  linearindexing(::Base.SparseArrays.CHOLMOD.Sparse{Tv<:Union{Complex{Float64},F
loat64}}) at sparse\cholmod.jl:1145
  ...

```

Also, when should I use Base.LinearSlow and how is it different from LinearFast in terms of speed difference and functionality?

Thank you!

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [June 9, 2017, 11:53am UTC](https://discourse.julialang.org/t/linearindexing-linearfast-and-linearslow/4172/2 "2017-06-09T11:53:45Z")

</div>

`linearindexing` is only used for `AbstractArray`, tuples and strings implement directly their own `getindex` methods.

See [the manual](https://docs.julialang.org/en/stable/manual/interfaces/#abstract-arrays) for an explanation. Basically it depends on what’s the most natural way to index into your custom array type.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 9, 2017, 12:24pm UTC](https://discourse.julialang.org/t/linearindexing-linearfast-and-linearslow/4172/3 "2017-06-09T12:24:30Z")

</div>

I see. So for 1D indexable types, linearindexing is never going to be used, which I suppose is why it was not defined for String or Tuple and only defined for AbstractArray. And when it said LinearSlow() is the default value for linearindexing(::Type), it was referring to types that are subtypes of AbstractArray, not in general. Thanks alot.

```julia
julia> Base.linearindexing(AbstractArray)
Base.LinearSlow()

```
