JuliaArrays / JuliaArrays/StaticArrays.jl

Inconsistencies with multi-argument constructors

Open
#518 21 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Given that Scalar <: SArray, the behavior of
https://github.com/JuliaArrays/StaticArrays.jl/blob/552bc7596c1639d1f66bf781084d3961b36dbd53/src/Scalar.jl#L10
is inconsistent with
https://github.com/JuliaArrays/StaticArrays.jl/blob/552bc7596c1639d1f66bf781084d3961b36dbd53/src/convert.jl#L5

Fortunately, in a few cases there's a very welcome ambiguity error:

julia> sa = Scalar((1,))
Scalar{Int64}((1,))

julia> Scalar(sa)
ERROR: MethodError: Scalar{T} where T(::Scalar{T}) is ambiguous. Candidates:
  (::Type{Scalar{T} where T})(a::AbstractArray{T,0} where T) in StaticArrays at /home/tim/.julia/dev/StaticArrays/src/Scalar.jl:11
  (::Type{Scalar{T} where T})(a::AbstractArray) in StaticArrays at /home/tim/.julia/dev/StaticArrays/src/Scalar.jl:10
  (::Type{SA})(a::StaticArray) where SA<:StaticArray in StaticArrays at /home/tim/.julia/dev/StaticArrays/src/convert.jl:4
Possible fix, define
  Scalar{T} where T(::StaticArray{S,T,0} where T where S<:Tuple)
Stacktrace:
 [1] top-level scope at none:0

but mostly this just silently does things differently for 0 dimensions than for any other dimension.

I don't think you can really have both. Can you choose which behavior you want to keep?

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

Read the constructor methods in src/Scalar.jl and src/convert.jl at the linked lines, then reproduce the Scalar((1,)) and Scalar(sa) examples in Julia. Resolve which multi-argument and conversion behavior should be retained, with consistent behavior for zero-dimensional and other-dimensional arrays as the completion criterion.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.