Skip to content

add keepat! (the opposite of deleteat!)#36229

Merged
oscardssmith merged 6 commits intomasterfrom
rf/keepat
May 27, 2021
Merged

add keepat! (the opposite of deleteat!)#36229
oscardssmith merged 6 commits intomasterfrom
rf/keepat

Conversation

@rfourquet
Copy link
Copy Markdown
Member

It feels like I'm missing something, but I asked on slack and this functionality doesn't seem to exist yet in Base.
keepat!(vector, indices) deletes items at all indices of vector except those which are specified in indices.
In other words, after keepat!(a, inds), a is equal to the array which would have been obtained by a[inds].

I'm not sure about the name, it could be maybe getindex!, or the feature could be incorporated in deleteat! with a keyword.

@rfourquet rfourquet added arrays [a, r, r, a, y, s] needs compat annotation Add !!! compat "Julia x.y" to the docstring needs docs Documentation for this change is required needs news A NEWS entry is required for this change needs tests Unit tests are required for this change labels Jun 11, 2020
@StefanKarpinski
Copy link
Copy Markdown
Member

Maybe better expressed with https://github.com/mbauman/InvertedIndices.jl and deleteat!?

@rfourquet
Copy link
Copy Markdown
Member Author

Maybe better expressed with https://github.com/mbauman/InvertedIndices.jl and deleteat!?

Maybe! Someone pointed out this package to me and I forgot to mention it here. But it's quite less discoverable than deleteat!, while the operation of "keeping only these indices" doesn't seem to be any less fundamental than "delete all these indices". Although it might be less often needed given that this feature isn't in Base yet and doesn't seem to have been requested before. But given how often the non-mutating equivalent vector[inds] is used, I'm quite surprised by this fact.

@rfourquet rfourquet added the design Design of APIs or of the language itself label Jun 12, 2020
@vtjnash vtjnash changed the title [WIP/RFC] add keepat! the opposite of deleteat! add keepat! (the opposite of deleteat!) Apr 16, 2021
Copy link
Copy Markdown
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable to me. I think the implementation can be generalized, but otherwise, lgtm conceptually. I'd merge if you finish it :)

@rfourquet rfourquet removed needs compat annotation Add !!! compat "Julia x.y" to the docstring needs docs Documentation for this change is required needs news A NEWS entry is required for this change needs tests Unit tests are required for this change labels Apr 22, 2021
@oscardssmith oscardssmith merged commit 4cdcdb8 into master May 27, 2021
@oscardssmith oscardssmith deleted the rf/keepat branch May 27, 2021 20:13
shirodkara pushed a commit to shirodkara/julia that referenced this pull request Jun 9, 2021
johanmon pushed a commit to johanmon/julia that referenced this pull request Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrays [a, r, r, a, y, s] design Design of APIs or of the language itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants