Skip to main content

cond

Function cond 

Source
pub fn cond<B: Backend, S: Tree<B>, R: Tree<B>>(
    pred: Bool<B>,
    true_fn: impl Fn(S) -> R,
    false_fn: impl Fn(S) -> R,
    operand: S,
) -> R
Expand description

Calls true_fn(operand) if pred holds and false_fn(operand) otherwise (lax.cond). On Native this is a real branch.

ยงExamples

use ruxla_core::{Backend, F32, Native, lax};

fn relu<B: Backend>(x: F32<B>) -> F32<B> {
    lax::cond(x.gt(0.0), |x| x, |_| F32::new(0.0), x)
}
assert_eq!(relu::<Native>(F32::new(-2.0)).value(), 0.0);