TensorArgValidator

class tfsnippet.utils.TensorArgValidator(name)

Bases: object

Class to validate argument values of tensors.

Methods Summary

require_int32(value) Require value to be an 32-bit integer.
require_non_negative(value) Require value to be non-negative, i.e., value >= 0.
require_positive(value) Require value to be positive, i.e., value > 0.

Methods Documentation

require_int32(value)

Require value to be an 32-bit integer.

Parameters:value – Value to be validated. If is_tensor_object(value) == True, it will be casted into a tf.Tensor with dtype as tf.int32. If otherwise is_integer(value) == True, the type will not be casted, but its value will be checked to ensure it falls between -2**31 ~ 2**31-1.
Returns:The validated value.
Raises:TypeError – If specified value cannot be casted into int32, or the value is out of range.
require_non_negative(value)

Require value to be non-negative, i.e., value >= 0.

Parameters:value – Value to be validated. If is_tensor_object(value) == True, additional assertion will be added to value. Otherwise it will be validated against value >= 0 immediately.
Returns:The validated value.
Raises:ValueError – If specified value is not non-negative.
require_positive(value)

Require value to be positive, i.e., value > 0.

Parameters:value – Value to be validated. If is_tensor_object(value) == True, additional assertion will be added to value. Otherwise it will be validated against value > 0 immediately.
Returns:The validated value.
Raises:ValueError – If specified value is not non-negative.