JuliaArrays / JuliaArrays/StaticArrays.jl

Length inferred a[3:end]?

Open
#824 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I'm wishing to do things like a[3:end] but have it return an SVector. I found a way to do this:

julia> a = SVector(1,2,3,4)
4-element SArray{Tuple{4},Int64,1,4} with indices SOneTo(4):
 1
 2
 3
 4

julia> a[3:end] # Length not inferred
2-element Array{Int64,1}:
 3
 4

julia> reverse(reverse(a)[SOneTo(2)]) # Length inferred
2-element SArray{Tuple{2},Int64,1,2} with indices SOneTo(2):
 3
 4

Is there an establish idiom for this? Would it be worth adding this to the package say as a special type (a[SToEnd(3)])?

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 reviewing StaticArrays.jl's existing indexing behavior, including the SOneTo example in the issue. Determine whether an established idiom already provides a statically sized result or whether a new API is warranted; done requires a settled approach and an agreed scope for implementation and tests.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.