-
Notifications
You must be signed in to change notification settings - Fork 179
feat: mask #1900
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
Merged
feat: mask #1900
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
6b3b101
feat: mask
danking c25b668
remove unnecssary clone
danking 26c4613
clippy again
danking 469f401
revert datetime-parts changes
danking 757d1b8
extension arrays are neither castable nor maskable
danking e7de227
Merge remote-tracking branch 'origin/develop' into dk/mask
danking 4bf1e0c
revert ALP mask for now
danking 2110ee2
use slice::fill instead of a loop
danking 373ae02
fix: non-nullable dict array needs a leading empty element
danking e6bf8f0
better error message when casting BoolArray to non-bool dtype.
danking bf2bbd2
test that changing name order is not allowed
danking 5b98893
remove DictArray mask for now
danking 6d5af14
fix varbin and varbinview casts
danking 732171e
Merge remote-tracking branch 'origin/develop' into dk/mask
danking af00e5c
clippy
danking 5c43574
clippy
danking fe393c0
clippy
danking 169fe33
Merge remote-tracking branch 'origin/develop' into dk/mask
danking 64b714d
remove cruft
danking cb0fabd
revert unused changes
danking 77740e8
cleanups
danking 4d909eb
validity array not supporting min is an error
danking ac41d69
lift validity failure before boolean buffer creation
danking efb9881
final fixups
danking 94c731c
Merge remote-tracking branch 'origin/develop' into dk/mask
danking 49d4a0d
Merge remote-tracking branch 'origin/develop' into dk/mask
danking 256f013
use new idioms for true count
danking 041e913
Merge remote-tracking branch 'origin/develop' into dk/mask
danking 3ec13c0
fixes
danking 554f492
test mask on dict array
danking 3445488
revert change
danking 5e2f415
StructArray children includes validity: must use fields()
danking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,58 @@ | ||
| use vortex_array::compute::{mask, MaskFn}; | ||
| use vortex_array::{Array, IntoArray}; | ||
| use vortex_error::VortexResult; | ||
| use vortex_mask::Mask; | ||
|
|
||
| use crate::{ALPRDArray, ALPRDEncoding}; | ||
|
|
||
| impl MaskFn<ALPRDArray> for ALPRDEncoding { | ||
| fn mask(&self, array: &ALPRDArray, filter_mask: Mask) -> VortexResult<Array> { | ||
| Ok(ALPRDArray::try_new( | ||
| array.dtype().as_nullable(), | ||
| mask(&array.left_parts(), filter_mask)?, | ||
| array.left_parts_dict(), | ||
| array.right_parts(), | ||
| array.right_bit_width(), | ||
| array.left_parts_patches(), | ||
| )? | ||
| .into_array()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use rstest::rstest; | ||
| use vortex_array::array::PrimitiveArray; | ||
| use vortex_array::compute::test_harness::test_mask; | ||
| use vortex_array::IntoArray as _; | ||
|
|
||
| use crate::{ALPRDFloat, RDEncoder}; | ||
|
|
||
| #[rstest] | ||
| #[case(0.1f32, 0.2f32, 3e25f32)] | ||
| #[case(0.1f64, 0.2f64, 3e100f64)] | ||
| fn test_mask_simple<T: ALPRDFloat>(#[case] a: T, #[case] b: T, #[case] outlier: T) { | ||
| test_mask( | ||
| RDEncoder::new(&[a, b]) | ||
| .encode(&PrimitiveArray::from_iter([a, b, outlier, b, outlier])) | ||
| .into_array(), | ||
| ); | ||
| } | ||
|
|
||
| #[rstest] | ||
| #[case(0.1f32, 3e25f32)] | ||
| #[case(0.5f64, 1e100f64)] | ||
| fn test_mask_with_nulls<T: ALPRDFloat>(#[case] a: T, #[case] outlier: T) { | ||
| test_mask( | ||
| RDEncoder::new(&[a]) | ||
| .encode(&PrimitiveArray::from_option_iter([ | ||
| Some(a), | ||
| None, | ||
| Some(outlier), | ||
| Some(a), | ||
| None, | ||
| ])) | ||
| .into_array(), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,59 @@ | ||
| #![allow(clippy::unwrap_used)] | ||
|
|
||
| use divan::Bencher; | ||
| use rand::rngs::StdRng; | ||
| use rand::{Rng, SeedableRng as _}; | ||
| use vortex_array::array::PrimitiveArray; | ||
| use vortex_array::compute::mask; | ||
| use vortex_array::IntoArray as _; | ||
| use vortex_dict::DictArray; | ||
| use vortex_mask::Mask; | ||
|
|
||
| fn main() { | ||
| divan::main(); | ||
| } | ||
|
|
||
| fn filter_mask(len: usize, fraction_masked: f64, rng: &mut StdRng) -> Mask { | ||
| let indices = (0..len) | ||
| .filter(|_| rng.gen_bool(fraction_masked)) | ||
| .collect::<Vec<usize>>(); | ||
| Mask::from_indices(len, indices) | ||
| } | ||
|
|
||
| #[divan::bench(args = [ | ||
| (0.9, 0.9), | ||
| (0.9, 0.5), | ||
| (0.9, 0.1), | ||
| (0.9, 0.01), | ||
| (0.5, 0.9), | ||
| (0.5, 0.5), | ||
| (0.5, 0.1), | ||
| (0.5, 0.01), | ||
| (0.1, 0.9), | ||
| (0.1, 0.5), | ||
| (0.1, 0.1), | ||
| (0.1, 0.01), | ||
| (0.01, 0.9), | ||
| (0.01, 0.5), | ||
| (0.01, 0.1), | ||
| (0.01, 0.01), | ||
| ])] | ||
| fn bench_dict_mask(bencher: Bencher, (fraction_valid, fraction_masked): (f64, f64)) { | ||
| let mut rng = StdRng::seed_from_u64(0); | ||
|
|
||
| let len = 65_535; | ||
| let codes = PrimitiveArray::from_iter((0..len).map(|_| { | ||
| if rng.gen_bool(fraction_valid) { | ||
| 1u64 | ||
| } else { | ||
| 0u64 | ||
| } | ||
| })) | ||
| .into_array(); | ||
| let values = PrimitiveArray::from_option_iter([None, Some(42i32)]).into_array(); | ||
| let array = DictArray::try_new(codes, values).unwrap().into_array(); | ||
| let filter_mask = filter_mask(len, fraction_masked, &mut rng); | ||
| bencher | ||
| .with_inputs(|| (&array, filter_mask.clone())) | ||
| .bench_values(|(array, filter_mask)| mask(array, filter_mask).unwrap()); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,13 @@ | ||
| use vortex_error::VortexResult; | ||
| use vortex_mask::Mask; | ||
|
|
||
| use crate::array::{BoolArray, BoolEncoding}; | ||
| use crate::compute::MaskFn; | ||
| use crate::{Array, IntoArray}; | ||
|
|
||
| impl MaskFn<BoolArray> for BoolEncoding { | ||
| fn mask(&self, array: &BoolArray, mask: Mask) -> VortexResult<Array> { | ||
| BoolArray::try_new(array.boolean_buffer(), array.validity().mask(&mask)?) | ||
| .map(IntoArray::into_array) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a useful microbenchmark but dict currently lacks a MaskFn so this just measures decompression time. I intend to follow up with a real MaskFn.