Selects elements from true_value or false_value based on pred,
analogous to R's ifelse().
Arguments
- pred
(
arrayishof boolean type)
Predicate array. Must be scalar or have the same shape as the non-scalar arguments.- true_value, false_value
(
arrayish)
Values to return wherepredisTRUE/FALSE.true_valueandfalse_valueare promoted to a common data type. Scalars (includingpred) are broadcast to the shape of the non-scalar arguments.
Value
arrayish
Has the common data type of true_value and false_value and the
shape of the non-scalar arguments.
See also
prim_ifelse() for the underlying primitive.
Examples
pred <- nv_array(c(TRUE, FALSE, TRUE))
nv_ifelse(pred, nv_array(c(1, 2, 3)), nv_array(c(4, 5, 6)))
#> AnvlArray
#> 1
#> 5
#> 3
#> [ CPUf32{3} ]
# scalar branches are broadcast and promoted to a common dtype
nv_ifelse(pred, nv_scalar(1L), nv_scalar(0.5))
#> AnvlArray
#> 1.0000
#> 0.5000
#> 1.0000
#> [ CPUf32{3} ]