pub trait Select<T> {
// Required method
fn select(self, true_values: T, false_values: T) -> T;
}
🔬This is a nightly-only experimental API. (
portable_simd
)Expand description
Choose elements from two vectors using a mask.
For each element in the mask, choose the corresponding element from true_values
if
that element mask is true, and false_values
if that element mask is false.
If the mask is u64
, it’s treated as a bitmask with the least significant bit
corresponding to the first element.
§Examples
§Selecting values from Simd
let a = Simd::from_array([0, 1, 2, 3]);
let b = Simd::from_array([4, 5, 6, 7]);
let mask = Mask::<i32, 4>::from_array([true, false, false, true]);
let c = mask.select(a, b);
assert_eq!(c.to_array(), [0, 5, 6, 3]);
§Selecting values from Mask
let a = Mask::<i32, 4>::from_array([true, true, false, false]);
let b = Mask::<i32, 4>::from_array([false, false, true, true]);
let mask = Mask::<i32, 4>::from_array([true, false, false, true]);
let c = mask.select(a, b);
assert_eq!(c.to_array(), [true, false, true, false]);
§Selecting with a bitmask
let a = Mask::<i32, 4>::from_array([true, true, false, false]);
let b = Mask::<i32, 4>::from_array([false, false, true, true]);
let mask = 0b1001;
let c = mask.select(a, b);
assert_eq!(c.to_array(), [true, false, true, false]);