Change assertions to use the tensor 'x' rather than 'x.op.name'. This enables eager...
authorA. Unique TensorFlower <gardener@tensorflow.org>
Thu, 12 Apr 2018 23:51:43 +0000 (16:51 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Thu, 12 Apr 2018 23:53:36 +0000 (16:53 -0700)
PiperOrigin-RevId: 192693458

tensorflow/contrib/distributions/python/ops/bijectors/reshape.py
tensorflow/python/ops/distributions/util.py

index 82210cd..f21b982 100644 (file)
@@ -138,7 +138,7 @@ class Reshape(bijector_lib.Bijector):
     """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 = []
 
@@ -146,10 +146,10 @@ class Reshape(bijector_lib.Bijector):
     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():
@@ -157,12 +157,12 @@ class Reshape(bijector_lib.Bijector):
       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(
@@ -170,11 +170,11 @@ class Reshape(bijector_lib.Bijector):
                   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
 
index 0fe6aa3..2e067ea 100644 (file)
@@ -58,8 +58,7 @@ def assert_close(
   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:
@@ -95,7 +94,7 @@ def assert_integer_form(
     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 = {
@@ -123,13 +122,13 @@ def embed_check_nonnegative_integer_form(
     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)
 
@@ -434,7 +433,7 @@ def embed_check_integer_casting_closed(
         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:
@@ -683,7 +682,7 @@ def pick_vector(cond,
     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
@@ -692,8 +691,8 @@ def pick_vector(cond,
     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),