-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(rust, python): speedup boolean apply (#10073)
- Loading branch information
Showing
4 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use arrow::bitmap::utils::{BitChunkIterExact, BitChunksExact}; | ||
use arrow::bitmap::{chunk_iter_to_vec, Bitmap}; | ||
|
||
/// Apply a bitwise operation `op` to one input and return the result as a [`Bitmap`]. | ||
pub fn unary_mut<F>(lhs: &Bitmap, op: F) -> Bitmap | ||
where | ||
F: FnMut(u64) -> u64, | ||
{ | ||
let (slice, offset, length) = lhs.as_slice(); | ||
if offset == 0 { | ||
let iter = BitChunksExact::<u64>::new(slice, length); | ||
unary_impl(iter, op, lhs.len()) | ||
} else { | ||
let iter = lhs.chunks::<u64>(); | ||
unary_impl(iter, op, lhs.len()) | ||
} | ||
} | ||
|
||
fn unary_impl<F, I>(iter: I, mut op: F, length: usize) -> Bitmap | ||
where | ||
I: BitChunkIterExact<u64>, | ||
F: FnMut(u64) -> u64, | ||
{ | ||
let rem = op(iter.remainder()); | ||
|
||
// TODO! this can be done without chaining | ||
let iterator = iter.map(op).chain(std::iter::once(rem)); | ||
|
||
let buffer = chunk_iter_to_vec(iterator); | ||
|
||
Bitmap::from_u8_vec(buffer, length) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
mod arity; | ||
pub mod mutable; | ||
|
||
pub use arity::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters