You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It was recently asked on Slack if there is an inplace equivalent of my_vector = my_vector[my_mask], where we assume that the user already needs the mask and does not want to essentially recompute it with filter!. I took a glance at the implementation of filter! in Base and saw that it could be easily adapted to this use-case:
functionmask!(a::AbstractVector, m::AbstractVector{Bool})
j =firstindex(a)
for i ineachindex(a, m)
@inboundsbegin
ai = a[i]
mi = m[i]
a[j] = ai
end
j =ifelse(mi, nextind(a, j), j)
end
j >lastindex(a) &&return a
if a isa Vector
resize!(a, j-1)
sizehint!(a, j-1)
elsedeleteat!(a, j:lastindex(a))
endreturn a
end
julia>let a = [:a, :b, :c], m = [true, false, true]
mask!(a, m)
end2-element Vector{Symbol}::a:c
Is this something that would be worth putting in Base? If so, I can whip up a PR, but don't want to waste my time if it's something that's already been discussed. I tried searching around but didn't find anything, but perhaps I missed a discussion.
The text was updated successfully, but these errors were encountered:
It was recently asked on Slack if there is an inplace equivalent of
my_vector = my_vector[my_mask]
, where we assume that the user already needs the mask and does not want to essentially recompute it withfilter!
. I took a glance at the implementation offilter!
in Base and saw that it could be easily adapted to this use-case:Is this something that would be worth putting in Base? If so, I can whip up a PR, but don't want to waste my time if it's something that's already been discussed. I tried searching around but didn't find anything, but perhaps I missed a discussion.
The text was updated successfully, but these errors were encountered: