JuliaArrays / JuliaArrays/StaticArrays.jl

Strange behaviour with `@inline`d functions and `StaticArrays`

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

Nobody has claimed this yet.

Dominant language
Julia
Stars
844
Forks
159
Avg merge
3d 21h
Merged PRs (30d)
3

Description

Consider the following code

using StaticArrays
@inline fun(A, x::SVector) = A * x
@inline fun(A, x::Vector) = fun(A, SVector{2}(x))
A = MMatrix{1, 2}(0.2582836768895444, -0.7450543662661093)
x = [0.9349412115157324, 0.01823374719995763]
fun(A, x) == fun(A, SVector{2}(x))

The last equality does not hold on my machine (Julia 1.10.0-beta3 macOS x86, StaticArrays v1.6.5).
If fun(A, x::SVector) = A * x is no longer inline then the equality holds.
It also works if A is a SMatrix.
Since this works on Julia 1.9 it may be an upstream bug, but I posted it here because I cannot reproduce it without using StaticArrays.

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 running the reproducer in the issue with Julia 1.10.0-beta3 and StaticArrays v1.6.5, then compare it with Julia 1.9. Check the behavior when the SVector method is not inlined and when A is an SMatrix. Done means identifying the source of the differing equality result and determining whether the fix belongs in StaticArrays.jl or upstream Julia.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.