Skip to contents

Conditional execution of one of two branches based on a scalar boolean predicate. Unlike nvl_ifelse() which operates element-wise, this evaluates only the selected branch.

Usage

nvl_if(pred, true, false)

Arguments

pred

(tensorish)
Scalar boolean predicate that determines which branch to execute.

true, false

(NSE)
Expressions for the true and false branches. Both must return outputs with the same structure, dtypes, and shapes.

Value

Result of the executed branch.
An output is ambiguous if it is ambiguous in both branches.

Implemented Rules

  • stablehlo

  • backward

StableHLO

Lowers to stablehlo::hlo_if().

See also

Examples

jit_eval(nvl_if(nv_scalar(TRUE), nv_scalar(1), nv_scalar(2)))
#> AnvilTensor
#>  1
#> [ CPUf32{} ]