Given v = [1,2,3,4,5] and inds = (1,2,3), how do you produce the view view(v, inds) without allocating memory?
Currently I am collecting the tuple into a vector with view(v, collect(inds)) but that seems unnecessary?
I am slightly surprised this works, but here's a concatenation of zero-dimensional views:
using LazyStack; stack(map(i -> view(v, i), inds))
This should also be zero-allocations:
using StaticArrays; view(v, SVector(inds...))
The StaticArrays.jl solution is the best in my use case that already depends on the package. I wonder if this should work with Tuple too? Perhaps an issue should be opened?
Yeah that seems like a reasonable thing to support in base
Last updated: Oct 27 2025 at 04:47 UTC