tf_assert: tf_assert

Description Usage Arguments Examples

View source: R/tf_assert.R

Description

A thin wrapper around tf$Assert() that automatically constructs an informative error message (passed on to data argument), which includes the expression passed to condition, the values of the symbols found in the expression, as well as the full R call stack at the time the tf$Assert() node is created.

Usage

1
2
3
4
5
6
7
tf_assert(
  condition,
  ...,
  expr = substitute(condition),
  summarize = NULL,
  name = NULL
)

Arguments

condition

A boolean tensor

...

Additional elements passed on to data. (e.g, an informative error message as a string, additional tensor values that might be useful to have in the error message, etc.)

expr

A language object, provided in case condition is already computed prior to the call

summarize

Print this many entries of each tensor.

name

A name for this operation (optional).

Examples

1
2
3
4
5
## Not run: 
x <- tf$constant(-1)
try(tf_assert(x > 0, "oopsies! x must be greater than 0"))

## End(Not run)

tfautograph documentation built on Sept. 18, 2021, 1:07 a.m.