def _check_multiple_of(value, multiple_of):
"""Checks that value `value` is a non-zero multiple of `multiple_of`.
Args:
value: an int32 scalar Tensor.
multiple_of: an int or int32 scalar Tensor.
Returns:
new_value: an int32 scalar Tensor matching `value`, but which includes an
assertion that `value` is a multiple of `multiple_of`.
"""
assert isinstance(value, ops.Tensor)
with ops.control_dependencies([
control_flow_ops.Assert(
math_ops.logical_and(
math_ops.equal(math_ops.mod(value, multiple_of), 0),
math_ops.not_equal(value, 0)),
[string_ops.string_join(
["Tensor %s should be a multiple of: " % value.name,
string_ops.as_string(multiple_of),
", but saw value: ",
string_ops.as_string(value),
". Consider setting pad=True."])])]):
new_value = array_ops.identity(
value, name="multiple_of_checked")
return new_value
评论列表
文章目录