Trait Select

Source
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]);

Required Methods§

Source

fn select(self, true_values: T, false_values: T) -> T

🔬This is a nightly-only experimental API. (portable_simd)

Choose elements

Implementations on Foreign Types§

Source§

impl<T, const N: usize> Select<Mask<T, N>> for u64

Source§

fn select(self, true_values: Mask<T, N>, false_values: Mask<T, N>) -> Mask<T, N>

🔬This is a nightly-only experimental API. (portable_simd)
Source§

impl<T, const N: usize> Select<Simd<T, N>> for u64

Source§

fn select(self, true_values: Simd<T, N>, false_values: Simd<T, N>) -> Simd<T, N>

🔬This is a nightly-only experimental API. (portable_simd)

Implementors§

Source§

impl<T, U, const N: usize> Select<Mask<T, N>> for Mask<U, N>

Source§

impl<T, U, const N: usize> Select<Simd<T, N>> for Mask<U, N>