Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support vectors of logicals as an argument to filter_bitset. #199

Merged
merged 3 commits into from
Jul 16, 2024

Conversation

plietar
Copy link
Member

@plietar plietar commented Jul 15, 2024

In addition to a vector of numerical indices and another bitset, the filter_bitset now accepts a vector of logicals (ie. booleans). Each set bit of the bitset is included in the return value only if the corresponding value in the logical vector is TRUE.

Given v a logical vector, filter_bitset(b, v) is equivalent to the already supported filter_bitset(v, which(v)) but is more performant. The new semantics also align with subsetting of R vectors, which similarly supports either a vector of indices or vector of logicals.

In addition to a vector of numerical indices and another bitset, the
filter_bitset now accepts a vector of logicals (ie. booleans). Each set
bit of the bitset is included in the return value only if the
corresponding value in the logical vector is TRUE.

Given `v` a logical vector, `filter_bitset(b, v)` is equivalent to the
already supported `filter_bitset(v, which(v))` but is more performant.
The new semantics also align with subsetting of R vectors, which
similarly supports either a vector of indices or vector of logicals.
@plietar plietar requested a review from giovannic July 15, 2024 16:15
tests/testthat/test-bitset.R Outdated Show resolved Hide resolved
R/bitset.R Outdated Show resolved Hide resolved
@plietar plietar merged commit 5376bc2 into mrc-ide:dev Jul 16, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants