pub fn select_with_operand<B: Backend, S: Clone, T: Tree<B>>(
pred: Bool<B>,
operand: S,
on_true: impl FnOnce(S) -> T,
on_false: impl FnOnce(S) -> T,
) -> TExpand description
select_with whose sides take operand: natively, the chosen side
gets it by value (so that it can update arrays in place, without the
copy that a shared array needs); traced, each side gets a copy, and the
results are selected (the same IR as lax.select of both sides in JAX).
ยงExamples
use ruxla_core::{Array, Bool, Native, lax};
let grid = Array::<Native, f32>::from_vec(vec![0.0; 4], [2, 2]);
let left = Bool::<Native>::new(true);
let grid = lax::select_with_operand(
left,
grid,
|g| g.into_at((.., 0i64)).set(1.0f32),
|g| g.into_at((.., 1i64)).set(1.0f32),
);
assert_eq!(grid.to_vec(), [1.0, 0.0, 1.0, 0.0]);