Function filter

Source
pub fn filter(array: &dyn Array, mask: &Mask) -> VortexResult<ArrayRef>
Expand description

Keep only the elements for which the corresponding mask value is true.

§Examples

use vortex_array::{Array, IntoArray};
use vortex_array::arrays::{BoolArray, PrimitiveArray};
use vortex_array::compute::{scalar_at, filter, mask};
use vortex_mask::Mask;
use vortex_scalar::Scalar;

let array =
    PrimitiveArray::from_option_iter([Some(0i32), None, Some(1i32), None, Some(2i32)]);
let mask = Mask::try_from(
    &BoolArray::from_iter([true, false, false, false, true]),
)
.unwrap();

let filtered = filter(&array, &mask).unwrap();
assert_eq!(filtered.len(), 2);
assert_eq!(scalar_at(&filtered, 0).unwrap(), Scalar::from(Some(0_i32)));
assert_eq!(scalar_at(&filtered, 1).unwrap(), Scalar::from(Some(2_i32)));

§Performance

This function attempts to amortize the cost of copying

§Panics

The predicate must receive an Array with type non-nullable bool, and will panic if this is not the case.