"""Check that a shape Tensor is int-type and otherwise sane."""
if not shape.dtype.is_integer:
raise TypeError("{} dtype ({}) should be `int`-like.".format(
- shape.op.name, shape.dtype.name))
+ shape, shape.dtype.name))
assertions = []
ndims_ = tensor_util.constant_value(ndims)
if ndims_ is not None and ndims_ > 1:
raise ValueError("`{}` rank ({}) should be <= 1.".format(
- shape.op.name, ndims_))
+ shape, ndims_))
elif validate_args:
assertions.append(check_ops.assert_less_equal(
- ndims, 1, message="`{}` rank should be <= 1.".format(shape.op.name)))
+ ndims, 1, message="`{}` rank should be <= 1.".format(shape)))
shape_ = tensor_util.constant_value_as_shape(shape)
if shape_.is_fully_defined():
if sum(es == -1) > 1:
raise ValueError(
"`{}` must have at most one `-1` (given {})"
- .format(shape.op.name, es))
+ .format(shape, es))
if np.any(es < -1):
raise ValueError(
"`{}` elements must be either positive integers or `-1`"
"(given {})."
- .format(shape.op.name, es))
+ .format(shape, es))
elif validate_args:
assertions.extend([
check_ops.assert_less_equal(
math_ops.cast(math_ops.equal(shape, -1), dtypes.int32)),
1,
message="`{}` elements must have at most one `-1`."
- .format(shape.op.name)),
+ .format(shape)),
check_ops.assert_greater_equal(
shape, -1,
message="`{}` elements must be either positive integers or `-1`."
- .format(shape.op.name)),
+ .format(shape)),
])
return assertions
if data is None:
data = [
message,
- "Condition x ~= y did not hold element-wise: x = ", x.name, x, "y = ",
- y.name, y
+ "Condition x ~= y did not hold element-wise: x = ", x, "y = ", y
]
if x.dtype.is_integer:
x = ops.convert_to_tensor(x, name="x")
if x.dtype.is_integer:
return control_flow_ops.no_op()
- message = message or "{} has non-integer components".format(x.op.name)
+ message = message or "{} has non-integer components".format(x)
if int_dtype is None:
try:
int_dtype = {
x = ops.convert_to_tensor(x, name="x")
assertions = [
check_ops.assert_non_negative(
- x, message="'{}' must be non-negative.".format(x.op.name)),
+ x, message="'{}' must be non-negative.".format(x)),
]
if not x.dtype.is_integer:
assertions += [
assert_integer_form(
x, message="'{}' cannot contain fractional components.".format(
- x.op.name)),
+ x)),
]
return control_flow_ops.with_dependencies(assertions, x)
and not _is_integer_like_by_dtype(target_dtype)):
raise TypeError("At least one of {}.dtype ({}) and target_dtype ({}) "
"must be integer-type.".format(
- x.op.name, x.dtype.name, target_dtype.name))
+ x, x.dtype.name, target_dtype.name))
assertions = []
if assert_nonnegative:
cond = ops.convert_to_tensor(cond, name="cond")
if cond.dtype != dtypes.bool:
raise TypeError("%s.dtype=%s which is not %s" %
- (cond.name, cond.dtype, dtypes.bool))
+ (cond, cond.dtype, dtypes.bool))
cond_value_static = tensor_util.constant_value(cond)
if cond_value_static is not None:
return true_vector if cond_value_static else false_vector
if true_vector.dtype != false_vector.dtype:
raise TypeError(
"%s.dtype=%s does not match %s.dtype=%s"
- % (true_vector.name, true_vector.dtype,
- false_vector.name, false_vector.dtype))
+ % (true_vector, true_vector.dtype,
+ false_vector, false_vector.dtype))
n = array_ops.shape(true_vector)[0]
return array_ops.slice(
array_ops.concat([true_vector, false_vector], 0),