Subvector of SVector

In this code snippet:

  using StaticArrays
  
  Vec2f = SVector{2, Float32}
  Vec3f = SVector{3, Float32}
  a = Vec3f(1, 2, 3)
  b = a[1:2]
  c = a[[true, false, true]]    

b and c type is Array{Float32,1}. How do I make these transformations to get b and c of type Vec2f?

you can try to use @view to do what you need to do.

or, given what you already have,

Vec2f(a[1:2])

works

1 Like
b = a[StaticArrays.SUnitRange(1, 2)]

Cf
https://github.com/JuliaArrays/StaticArrays.jl/issues/620

2 Likes