tf_case {tfautograph} | R Documentation |
tf.case
Description
This is a minimal wrapper around tf.case()
that allows you to supply the
pred_fn_pairs
using the ~
.
Usage
tf_case(
...,
pred_fn_pairs = list(...),
default = NULL,
exclusive = FALSE,
name = "case"
)
Arguments
... , pred_fn_pairs |
a list |
default |
a function, optionally specified with the |
exclusive |
bool, whether to evaluate all |
name |
a string, passed on to |
Value
The result from tf$case()
Examples
## Not run:
fizz_buzz_one <- function(x) {
tf_case(
x %% 15 == 0 ~ "FizzBuzz",
x %% 5 == 0 ~ "Buzz",
x %% 3 == 0 ~ "Fizz",
default = ~ tf$as_string(x, precision = 0L)
)
}
fn <- tf_function(autograph(function(n) {
for(e in tf$range(n))
tf$print(fizz_buzz_one(e))
}))
x <- tf$constant(16)
fn(x)
## End(Not run)
[Package tfautograph version 0.3.2 Index]