JuliaArrays / JuliaArrays/StaticArrayInterface.jl

Stack overflow when broadcasting results in StaticInt eltype

Open
#1 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
14
Forks
8
PR merge metrics
No merged PRs in 30d

Description

Found this...

julia> import ArrayInterface: StaticInt

julia> r = StaticInt(1):4
StaticInt{1}():StaticInt{1}():4

julia> broadcast(-, r, StaticInt(1))
ERROR: StackOverflowError:
Stacktrace:
 [1] UnitRange{StaticInt{0}}(::StaticInt{0}, ::StaticInt{3}) at /Users/zchristensen/.julia/packages/ArrayInterface/NbkVT/src/static.jl:108 (repeats 79984 times)

...and traced the issue back to Base._range assuming that UnitRange should be formed with an element type that is a StaticInt.

The easiest way to fix this would be our own Base._range(::StaticInt, ...), but I'm not sure if that's a good entry point since it's not public API.

Edit:
also found this

julia> (StaticInt(1):10)[1:2:6]
ERROR: MethodError: no method matching StepRange{StaticInt{1},Int64}(::StaticInt{1}, ::Int64, ::StaticInt{5})
Closest candidates are:
  StepRange{StaticInt{1},Int64}(::T, ::S, ::T) where {T, S} at range.jl:204
Stacktrace:
 [1] _rangestyle(::Base.Ordered, ::Base.ArithmeticWraps, ::StaticInt{1}, ::Int64, ::Int64) at ./range.jl:118
 [2] _range at ./range.jl:116 [inlined]
 [3] #range#43 at ./range.jl:91 [inlined]
 [4] getindex(::ArrayInterface.OptionallyStaticUnitRange{StaticInt{1},Int64}, ::StepRange{Int64,Int64}) at ./range.jl:713
 [5] top-level scope at REPL[26]:1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing both examples in Julia, then inspect src/static.jl:108 and Julia's base/range.jl around Base._range and lines 107-118. Trace how StaticInt ranges are constructed and how slicing reaches StepRange; done means broadcasting no longer overflows and the shown stepped-range expression no longer raises the reported MethodError.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.