Trait Select

pub trait Select<T>

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

# #![feature(portable_simd)]
# #[cfg(feature = "as_crate")] use core_simd::simd;
# #[cfg(not(feature = "as_crate"))] use core::simd;
# use simd::{Simd, Mask, Select};
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

# #![feature(portable_simd)]
# #[cfg(feature = "as_crate")] use core_simd::simd;
# #[cfg(not(feature = "as_crate"))] use core::simd;
# use simd::{Mask, Select};
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

# #![feature(portable_simd)]
# #[cfg(feature = "as_crate")] use core_simd::simd;
# #[cfg(not(feature = "as_crate"))] use core::simd;
# use simd::{Mask, Select};
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

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

Choose elements

Implementors