tf.compat.v1.assert_greater

Assert the condition x > y holds element-wise.

Migrate to TF2

tf.compat.v1.assert_greater is compatible with eager execution and tf.function. Please use tf.debugging.assert_greater instead when migrating to TF2. Apart from data, all arguments are supported with the same argument name.

If you want to ensure the assert statements run before the potentially-invalid computation, please use tf.control_dependencies, as tf.function auto-control dependencies are insufficient for assert statements.

Structural Mapping to Native TF2

Before:

tf.compat.v1.assert_greater(
  x=x, y=y, data=data, summarize=summarize,
  message=message, name=name)

After:

tf.debugging.assert_greater(
  x=x, y=y, message=message,
  summarize=summarize, name=name)

TF1 & TF2 Usage Example

TF1:

g = tf.Graph()
with g.as_default():
  a = tf.compat.v1.placeholder(tf.float32, [2])
  b = tf.compat.v1.placeholder(tf.float32, [2])
  result = tf.compat.v1.assert_greater(a, b,
    message='"a > b" does not hold for the given inputs')
  with tf.compat.v1.control_dependencies([result]):
    sum_node = a + b
sess = tf.compat.v1.Session(graph=g)
val = sess.run(sum_node, feed_dict={a: [1, 2], b:[0, 1]})

TF2:

a = tf.Variable([1, 2], dtype=tf.float32)
b = tf.Variable([0, 1], dtype=tf.float32)
assert_op = tf.debugging.assert_greater(a, b, message=
  '"a > b" does not hold for the given inputs')
# When working with tf.control_dependencies
with tf.control_dependencies([assert_op]):
  val = a + b