Skip to contents

Conditional execution of two branches. Unlike nv_ifelse(), which selects elements, this executes only one of the two branches depending on a scalar predicate.

Usage

nv_if(pred, true, false)

Arguments

pred

(tensorish of boolean type, scalar)
Predicate.

true

(expression)
Expression for the true branch (non-standard evaluation).

false

(expression)
Expression for the false branch (non-standard evaluation). Must return outputs with the same shapes as the true branch.

Value

Result of the executed branch.

See also

nvl_if() for the underlying primitive, nv_ifelse() for element-wise selection.

Examples

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