assert_rank: Confirm the rank of a tensor

View source: R/modeling.R

assert_rankR Documentation

Confirm the rank of a tensor

Description

Throws an error if the tensor rank is not of the expected rank.

Usage

assert_rank(tensor, expected_rank, name = NULL)

Arguments

tensor

A tf.Tensor to check the rank of.

expected_rank

Integer vector or list of integers, expected rank.

name

Optional name of the tensor for the error message.

Value

TRUE if the Tensor is of the expected rank (error otherwise).

Examples

## Not run: 
with(tensorflow::tf$variable_scope("examples",
  reuse = tensorflow::tf$AUTO_REUSE
), {
  ids <- tensorflow::tf$get_variable("x", dtype = "int32", shape = 10L)
  assert_rank(ids, 1)
  assert_rank(ids, 1:2)
  assert_rank(ids, 2)
})

## End(Not run)

jonathanbratt/RBERT documentation built on Jan. 26, 2023, 4:15 p.m.