library(tfautograph)
<- function(x) {
fizz_buzz_one tf_case(
%% 15 == 0 ~ "FizzBuzz",
x %% 5 == 0 ~ "Buzz",
x %% 3 == 0 ~ "Fizz",
x default = ~ tf$as_string(x, precision = 0L)
)
}
<- tf_function(autograph(function(n) {
fn for(e in tf$range(n))
$print(fizz_buzz_one(e))
tf
}))
<- tf$constant(16)
x fn(x)
tf_case
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
Arguments | Description |
---|---|
…, pred_fn_pairs | a list pred_fn_pairs supplied with the ~ like so: pred ~ fn_body |
default | a function, optionally specified with the ~ , (or something coercible to a function via as.function() ) |
exclusive | bool, whether to evaluate all preds and ensure only one is true. If FALSE (the default), then the preds are evaluated in the order supplied until the first TRUE value is encountered (effectively, acting as an if()... else if() ... else if() ... chain) |
name | a string, passed on to tf.case() |
Value
The result from tf$case()