JuliaArrays / JuliaArrays/StaticArrays.jl

SVector{1,SVector{1,Float64}}( SVector{1,Float64}(1.0) ) Errors

Open
#954 3 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

In Julia v1.6.2 with StaticArrays v1.2.12 Running

using StaticArrays
SVector{1,SVector{1,Float64}}( SVector{1,Float64}(1.0) )

produces the error

ERROR: MethodError: Cannot `convert` an object of type Float64 to an object of type SVector{1, Float64}
Closest candidates are:
  convert(::Type{SA}, ::Tuple) where SA<:StaticArray at /home/jonas/.julia/packages/StaticArrays/vxjOO/src/convert.jl:13
  convert(::Type{SVector{N, T}}, ::CartesianIndex{N}) where {N, T} at /home/jonas/.julia/packages/StaticArrays/vxjOO/src/SVector.jl:46
  convert(::Type{T}, ::LinearAlgebra.Factorization) where T<:AbstractArray at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/factorization.jl:58
  ...
Stacktrace:
 [1] macro expansion
   @ ~/.julia/packages/StaticArrays/vxjOO/src/util.jl:11 [inlined]
 [2] convert_ntuple
   @ ~/.julia/packages/StaticArrays/vxjOO/src/util.jl:7 [inlined]
 [3] SVector{1, SVector{1, Float64}}(x::Tuple{Float64})
   @ StaticArrays ~/.julia/packages/StaticArrays/vxjOO/src/SArray.jl:28
 [4] SVector{1, SVector{1, Float64}}(a::SVector{1, Float64})
   @ StaticArrays ~/.julia/packages/StaticArrays/vxjOO/src/convert.jl:5
 [5] top-level scope
   @ REPL[2]:1

I'm not sure if I'm making a mistake in the construction, it works when the inner size is 2. For now I have circumvented the issue by declaring

Base.convert( ::Type{SVector{1,Float64}} , x::Float64 ) = SVector{1,Float64}( x )

A similar error occurs for trying to create a 1-element SVector containing a 1x1 SMatrix. I realize it seems a bit silly to store a single Float64 inside a nested SVector, but it's part of a more generic scheme I'm working with where the inner and/or outer sizes are usually not 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

Reproduce the nested SVector case in Julia 1.6.2 with StaticArrays 1.2.12, then inspect src/convert.jl, src/SArray.jl, and src/util.jl where the stack trace enters conversion. Compare the one-element case with the working inner-size-two case and confirm that both nested SVector and 1x1 SMatrix construction have the intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.