Is there a non-allocating version of findall?

As you have shown, collecting a generator into an SVector does not allocate, i.e., this works for finding the indices as well:

julia> find5(flag) = SVector{5}(i for (i, b) in enumerate(flag) if b);

julia> @btime SVector{5}(@view $dat[find5($flag)]);
  40.874 ns (0 allocations: 0 bytes)

# Seems like the indices being a static vector also gives a static result
julia> @btime $dat[find5($flag)];
  34.445 ns (0 allocations: 0 bytes)
1 Like