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.
g=tf.Graph()withg.as_default():a=tf.compat.v1.placeholder(tf.float32,[2])b=tf.compat.v1.placeholder(tf.float32,[2])result=tf.compat.v1.assert_less_equal(a,b,message='"a <= b" does not hold for the given inputs')withtf.compat.v1.control_dependencies([result]):sum_node=a+bsess=tf.compat.v1.Session(graph=g)val=sess.run(sum_node,feed_dict={a:[1,2],b:[1,3]})
TF2:
a=tf.Variable([1,2],dtype=tf.float32)b=tf.Variable([1,3],dtype=tf.float32)assert_op=tf.debugging.assert_less_equal(a,b,message='"a <= b" does not hold for the given inputs')# When working with tf.control_dependencieswithtf.control_dependencies([assert_op]):val=a+b
Description
This condition holds if for every pair of (possibly broadcast) elements
x[i], y[i], we have x[i] <= y[i].
If both x and y are empty, this is trivially satisfied.
When running in graph mode, you should add a dependency on this operation
to ensure that it runs. Example of adding a dependency to an operation:
Numeric Tensor, same dtype as and broadcastable to x.
data
The tensors to print out if the condition is False. Defaults to
error message and first few entries of x, y.
summarize
Print this many entries of each tensor.
message
A string to prefix to the default message.
name
A name for this operation (optional). Defaults to "assert_less_equal".
Returns
Op that raises InvalidArgumentError if x <= y is False.
Raises
InvalidArgumentError
if the check can be performed immediately and
x <= y is False. The check can be performed immediately during
eager execution or if x and y are statically known.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.compat.v1.assert_less_equal\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/check_ops.py#L968-L975) |\n\nAssert the condition `x \u003c= y` holds element-wise.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.debugging.assert_less_equal`](https://www.tensorflow.org/api_docs/python/tf/compat/v1/assert_less_equal)\n\n\u003cbr /\u003e\n\n tf.compat.v1.assert_less_equal(\n x, y, data=None, summarize=None, message=None, name=None\n )\n\n\u003cbr /\u003e\n\nMigrate to TF2\n--------------\n\n\u003cbr /\u003e\n\n| **Caution:** This API was designed for TensorFlow v1. Continue reading for details on how to migrate from this API to a native TensorFlow v2 equivalent. See the [TensorFlow v1 to TensorFlow v2 migration guide](https://www.tensorflow.org/guide/migrate) for instructions on how to migrate the rest of your code.\n\n[`tf.compat.v1.assert_less_equal`](../../../tf/compat/v1/assert_less_equal) is compatible with eager execution and\n[`tf.function`](../../../tf/function).\nPlease use [`tf.debugging.assert_less_equal`](../../../tf/debugging/assert_less_equal) instead when migrating to TF2. Apart\nfrom `data`, all arguments are supported with the same argument name.\n\nIf you want to ensure the assert statements run before the\npotentially-invalid computation, please use [`tf.control_dependencies`](../../../tf/control_dependencies),\nas tf.function auto-control dependencies are insufficient for assert\nstatements.\n\n#### Structural Mapping to Native TF2\n\nBefore: \n\n tf.compat.v1.assert_less_equal(\n x=x, y=y, data=data, summarize=summarize,\n message=message, name=name)\n\nAfter: \n\n tf.debugging.assert_less_equal(\n x=x, y=y, message=message,\n summarize=summarize, name=name)\n\n#### TF1 \\& TF2 Usage Example\n\nTF1: \n\n g = tf.Graph()\n with g.as_default():\n a = tf.compat.v1.placeholder(tf.float32, [2])\n b = tf.compat.v1.placeholder(tf.float32, [2])\n result = tf.compat.v1.assert_less_equal(a, b,\n message='\"a \u003c= b\" does not hold for the given inputs')\n with tf.compat.v1.control_dependencies([result]):\n sum_node = a + b\n sess = tf.compat.v1.Session(graph=g)\n val = sess.run(sum_node, feed_dict={a: [1, 2], b:[1, 3]})\n\nTF2: \n\n a = tf.Variable([1, 2], dtype=tf.float32)\n b = tf.Variable([1, 3], dtype=tf.float32)\n assert_op = tf.debugging.assert_less_equal(a, b, message=\n '\"a \u003c= b\" does not hold for the given inputs')\n # When working with tf.control_dependencies\n with tf.control_dependencies([assert_op]):\n val = a + b\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nDescription\n-----------\n\nThis condition holds if for every pair of (possibly broadcast) elements\n`x[i]`, `y[i]`, we have `x[i] \u003c= y[i]`.\nIf both `x` and `y` are empty, this is trivially satisfied.\n\nWhen running in graph mode, you should add a dependency on this operation\nto ensure that it runs. Example of adding a dependency to an operation: \n\n with tf.control_dependencies([tf.compat.v1.assert_less_equal(x, y)]):\n output = tf.reduce_sum(x)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|------------------------------------------------------------------------------------------------------------------|\n| `x` | Numeric `Tensor`. |\n| `y` | Numeric `Tensor`, same dtype as and broadcastable to `x`. |\n| `data` | The tensors to print out if the condition is False. Defaults to error message and first few entries of `x`, `y`. |\n| `summarize` | Print this many entries of each tensor. |\n| `message` | A string to prefix to the default message. |\n| `name` | A name for this operation (optional). Defaults to \"assert_less_equal\". |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| Op that raises `InvalidArgumentError` if `x \u003c= y` is False. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `InvalidArgumentError` | if the check can be performed immediately and `x \u003c= y` is False. The check can be performed immediately during eager execution or if `x` and `y` are statically known. |\n\n\u003cbr /\u003e"]]