This is a minimal wrapper around tf$cond() that allows you to supply
true_fn and false_fn as lambda functions defined using the tilde ~.
tf_cond(pred, true_fn, false_fn, name = NULL)
| pred | R logical or a tensor. |
|---|---|
| true_fn, false_fn | a |
| name | a string, passed on to |
if cond is a tensor, then the result of tf.cond(). Otherwise, if
pred is an EagerTensor or an R logical, then the result of either
true_fn() or false_fn()
in Tensorflow version 1, the strict keyword argument is supplied with
a value of TRUE (different from the default)
if (FALSE) { ## square if positive # using tf$cond directly: raw <- function(x) tf$cond(x > 0, function() x * x, function() x) # using tf_cond() wrapper tilde <- function(x) tf_cond(x > 0, ~ x * x, ~ x) }