Skip to content

Type instability in axes(arr,dim) #116

@jishnub

Description

@jishnub

The method returns an IdOffsetRange or a Base.OneTo depending on whether the value of dim is less than ndims(arr). For example:

julia> a = OffsetVector(rand(3),-1:1);

julia> @code_warntype axes(a,1)
Variables
  #self#::Core.Compiler.Const(axes, false)
  A::OffsetArray{Float64,1,Array{Float64,1}}
  d::Int64

Body::Union{Base.OneTo{Int64}, OffsetArrays.IdOffsetRange{Int64,Base.OneTo{Int64}}}
1nothing%2  = OffsetArrays.ndims(A)::Core.Compiler.Const(1, false)
│   %3  = (d <= %2)::Bool
└──       goto #3 if not %3
2%5  = OffsetArrays.parent(A)::Array{Float64,1}%6  = OffsetArrays.axes(%5, d)::Base.OneTo{Int64}%7  = Base.getproperty(A, :offsets)::Tuple{Int64}%8  = Base.getindex(%7, d)::Int64%9  = OffsetArrays.IdOffsetRange(%6, %8)::OffsetArrays.IdOffsetRange{Int64,Base.OneTo{Int64}}
└──       return %9
3%11 = Base.OneTo::Core.Compiler.Const(Base.OneTo, false)
│   %12 = (%11)(1)::Core.Compiler.Const(Base.OneTo(1), false)
└──       return %12

Perhaps this might return an IdOffsetRange in each case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions