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

(arrayish of boolean type, scalar)
Predicate.

true

(function())
Zero-argument function for the true branch.

false

(function())
Zero-argument function for the false branch. Must return outputs with the same shapes as the true branch.

Value

Result of the executed branch.

See also

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

Examples

nv_if(nv_scalar(TRUE), \() nv_scalar(1), \() nv_scalar(2))
#> AnvlArray
#>  1
#> [ CPUf32{} ]