# Custom vector type causes runtime dispatch when used as view slicing indices

**URL:** <https://discourse.julialang.org/t/custom-vector-type-causes-runtime-dispatch-when-used-as-view-slicing-indices/97470>\
**Category:** General Usage\
**Created:** [April 14, 2023, 11:46am UTC](https://discourse.julialang.org/t/custom-vector-type-causes-runtime-dispatch-when-used-as-view-slicing-indices/97470 "2023-04-14T11:46:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [April 14, 2023, 11:46am UTC](https://discourse.julialang.org/t/custom-vector-type-causes-runtime-dispatch-when-used-as-view-slicing-indices/97470/1 "2023-04-14T11:46:07Z")

</div>

In my code there’s a custom vector type (`SkipVec`) that is used for indexing a matrix with `@view`. I recently realized (due to JET.jl) that it seems to cause runtime dispatch for some reason: [src/SkipVectors.jl · main · Neven Sajko / FindMinimaxPolynomial.jl · GitLab](https://gitlab.com/nsajko/FindMinimaxPolynomial.jl/-/blob/main/src/SkipVectors.jl)

```julia
struct SkipVec{E <: Any, V <: AbstractVector{E}} <: AbstractVector{E}
  v::V
  skip_index::Int

  function SkipVec(v::V, i::Int) where {E <: Any, V <: AbstractVector{E}}
    (length(v) < 1) && error("vec too small")
    (i ∈ axes(v, 1)) || error("index out of bounds")
    new{E, V}(v, i)
  end
end

Base.size(s::SkipVec) = (length(s.v) - 1,)

Base.IndexStyle(::Type{<:SkipVec}) = IndexLinear()

Base.getindex(s::SkipVec, i::Int) =
  (i < s.skip_index) ? s.v[i] : s.v[i + 1]

```

I realized that the type shouldn’t have a `Base.axes` method as it only supports one-based indexing, but removing that method definition just produces more JET.jl noise.

The motivation for creating the type is needing to compute some minors of a matrix, so the type comes in handy in an expression like this: `det(@view matrix[indices1, indices2])`, where both `indices1` and `indices2` are `SkipVec`. For example:

```julia
using JET, LinearAlgebra

matrix = rand(Float64, 4, 4)
inds1 = SkipVec(1:4, 3) 
inds2 = SkipVec(1:4, 2) 
d = det(@view matrix[inds1, inds2])
@report_opt det(@view matrix[inds1, inds2])

```

How to fix `SkipVec`?
