Skip to main content

Select

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 #86656)
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 #86656)

Choose elements

Dyn Compatibilityยง

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementorsยง

Sourceยง

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

Sourceยง

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

Sourceยง

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

Sourceยง

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