JuliaArrays / JuliaArrays/StaticArrays.jl

Should `SArray` constructor create an `SVector` by default?

Open
#1,099 2 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

julia> args = (0.0, 0.0, 0.0)
(0.0, 0.0, 0.0)

julia> SArray(args...)
ERROR: DimensionMismatch: No precise constructor for SArray found. Length of input was 3.
Stacktrace:
 [1] _no_precise_size(SA::Type, x::Tuple{Float64, Float64, Float64})
   @ StaticArrays ~/.julia/packages/StaticArrays/PUoe1/src/convert.jl:156
 [2] _no_precise_size(SA::Type, x::StaticArrays.Args{Tuple{Float64, Float64, Float64}})
   @ StaticArrays ~/.julia/packages/StaticArrays/PUoe1/src/convert.jl:155
 [3] adapt_size(#unused#::Type{SArray}, x::StaticArrays.Args{Tuple{Float64, Float64, Float64}})
   @ StaticArrays ~/.julia/packages/StaticArrays/PUoe1/src/convert.jl:112
 [4] construct_type(#unused#::Type{SArray}, x::StaticArrays.Args{Tuple{Float64, Float64, Float64}})
   @ StaticArrays ~/.julia/packages/StaticArrays/PUoe1/src/convert.jl:87
 [5] SArray(::Float64, ::Vararg{Float64})
   @ StaticArrays ~/.julia/packages/StaticArrays/PUoe1/src/convert.jl:160
 [6] top-level scope
   @ REPL[6]:1

This makes it hard to robustly recreate things from their types. ConstructionBase.jl, for example, uses nameof the type to get a constructor that will be robust to things like reconstructing with different eltypes.

julia> using ConstructionBase

julia> T = constructorof(typeof(SA[0.0, 0.0, 0.0]))
SArray

julia T(0, 0, 0)
# Same error

Versions I'm using:

(jl_VtnNO2) pkg> st
Status `/private/var/folders/4z/x1xvpm1d3jd0x24qgrlk9ksm0000gp/T/jl_VtnNO2/Project.toml`
  [187b0558] ConstructionBase v1.4.1
  [90137ffa] StaticArrays v1.5.9

julia> versioninfo()
Julia Version 1.8.1
Commit afb6c60d69a (2022-09-06 15:09 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin21.4.0)
  CPU: 16 × Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
  Threads: 1 on 8 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 
  JULIA_PKG_DEVDIR = /Users/jonnie.diegelman/dev

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 reading StaticArrays' convert.jl around _no_precise_size, adapt_size, and construct_type, as shown in the stack trace, and compare the SArray and SVector constructor behavior. Done means the reported tuple construction works as requested and the existing constructor behavior remains covered by regression tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Feature
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.