JuliaArrays / JuliaArrays/StaticArrays.jl

Use `StaticInteger`s instead of `Tuple{1,2,3}` in `StaticArray` type parameter?

Open
#807 20 comments 8 reactions 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

StaticArray uses Tuple{1,2,3} to encode the size:

https://github.com/JuliaArrays/StaticArrays.jl/blob/cee335d3e7f08dcc72075ac5f18bb3a632e8b841/src/StaticArrays.jl#L73-L76

Arguably, the type parameters of Tuple should be types. Otherwise, such Tuple does not have an instance. It also confuses some users (including me when I first saw this): What does Tuple{3} mean in StaticArrays? - Usage / First steps - JuliaLang.

A better solution may be to use Tuple{StaticInteger{1},StaticInteger{2},StaticInteger{3}} instead of Tuple{1,2,3}. For example, a possible implementation of SArray would be

struct SArray{N, S <: NTuple{N,StaticInteger}, T, L} <: StaticArray{S, T, N}
    data::NTuple{L,T}
    size::S
end

const SVector{S, T} = SArray{1, Tuple{StaticInteger{S}}, T, S}
const SMatrix{S1, S2, T, L} = SArray{2, Tuple{StaticInteger{S1}, StaticInteger{S2}}, T, L}

(Early discussion in https://github.com/JuliaArrays/StaticArrays.jl/issues/806#issuecomment-655279036)

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 src/StaticArrays.jl at lines 73-76, then review the early discussion in issue #806 and the linked Julia Discourse thread. Compare the current Tuple-based size parameters with the proposed StaticInteger representation and determine whether the design is acceptable. Done requires an agreed representation and consistent implementation of the affected StaticArray types.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.