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)
This item is validated for IEC 61508 (SIL 2) and ISO 26262 (ASIL B).

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,