View source: R/tf-ctrl-flow-wrappers.R
tf_case | R Documentation |
This is a minimal wrapper around tf.case()
that allows you to supply the
pred_fn_pairs
using the ~
.
tf_case(
...,
pred_fn_pairs = list(...),
default = NULL,
exclusive = FALSE,
name = "case"
)
..., pred_fn_pairs |
a list |
default |
a function, optionally specified with the |
exclusive |
bool, whether to evaluate all |
name |
a string, passed on to |
The result from tf$case()
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.