Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should SArray constructor create an SVector by default? #1099

Open
jonniediegelman opened this issue Oct 6, 2022 · 2 comments
Open

Should SArray constructor create an SVector by default? #1099

jonniediegelman opened this issue Oct 6, 2022 · 2 comments

Comments

@jonniediegelman
Copy link

jonniediegelman commented Oct 6, 2022

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
@jonniediegelman jonniediegelman changed the title SArray constructor should create an SVector by default? Should SArray constructor create an SVector by default? Oct 6, 2022
@hyrodium
Copy link
Collaborator

hyrodium commented Oct 6, 2022

This issue will be fixed with #1086, but I'm not sure we will have an additional dependency in this package.

julia> using ConstructionBase

julia> T = constructorof(typeof(SA[0.0, 0.0, 0.0]))
SVector (alias for SArray{Tuple{S}, T, 1, S} where {S, T})

julia> T(0,0,0)
3-element SVector{3, Int64} with indices SOneTo(3):
 0
 0
 0

@mateuszbaran
Copy link
Collaborator

I think SArray creating SVector by default wouldn't be particularly robust. There just needs to be a package that implements ConstructionBase for StaticArrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants