From f2b53e96cb03f6497889e1a468bcc11a5f813dc1 Mon Sep 17 00:00:00 2001 From: Haoliang Zhang Date: Wed, 10 Jul 2019 10:22:24 -0700 Subject: [PATCH] Add missing description (auto-generated) in TF MLIR ops specs. PiperOrigin-RevId: 257430295 --- .../mlir/tensorflow/ir/tf_generated_ops.td | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/tensorflow/compiler/mlir/tensorflow/ir/tf_generated_ops.td b/tensorflow/compiler/mlir/tensorflow/ir/tf_generated_ops.td index 05c87af9e11..6b7be4435b4 100644 --- a/tensorflow/compiler/mlir/tensorflow/ir/tf_generated_ops.td +++ b/tensorflow/compiler/mlir/tensorflow/ir/tf_generated_ops.td @@ -79,6 +79,12 @@ def TF_AddNOp : TF_Op<"AddN", [Commutative, NoSideEffect]> { let summary = "Add all input tensors element wise."; let description = [{ +Inputs must be of same size and shape. + + ```python + x = [9, 7, 10] + tf.math.add_n(x) ==> 26 + ``` }]; let arguments = (ins @@ -467,6 +473,15 @@ def TF_CosOp : TF_Op<"Cos", [NoSideEffect, SameOperandsAndResultType]> { let summary = "Computes cos of x element-wise."; let description = [{ +Given an input tensor, this function computes cosine of every + element in the tensor. Input range is `(-inf, inf)` and + output range is `[-1,1]`. If input lies outside the boundary, `nan` + is returned. + + ```python + x = tf.constant([-float("inf"), -9, -0.5, 1, 1.2, 200, 10000, float("inf")]) + tf.math.cos(x) ==> [nan -0.91113025 0.87758255 0.5403023 0.36235774 0.48718765 -0.95215535 nan] + ``` }]; let arguments = (ins @@ -1027,6 +1042,43 @@ Invert (flip) each bit of supported types; for example, type `uint8` value 01010 let description = [{ Flip each bit of supported types. For example, type `int8` (decimal 2) binary 00000010 becomes (decimal -3) binary 11111101. This operation is performed on each element of the tensor argument `x`. + +Example: +```python +import tensorflow as tf +from tensorflow.python.ops import bitwise_ops + +# flip 2 (00000010) to -3 (11111101) +tf.assert_equal(-3, bitwise_ops.invert(2)) + +dtype_list = [dtypes.int8, dtypes.int16, dtypes.int32, dtypes.int64, + dtypes.uint8, dtypes.uint16, dtypes.uint32, dtypes.uint64] + +inputs = [0, 5, 3, 14] +for dtype in dtype_list: + # Because of issues with negative numbers, let's test this indirectly. + # 1. invert(a) and a = 0 + # 2. invert(a) or a = invert(0) + input_tensor = tf.constant([0, 5, 3, 14], dtype=dtype) + not_a_and_a, not_a_or_a, not_0 = [bitwise_ops.bitwise_and( + input_tensor, bitwise_ops.invert(input_tensor)), + bitwise_ops.bitwise_or( + input_tensor, bitwise_ops.invert(input_tensor)), + bitwise_ops.invert( + tf.constant(0, dtype=dtype))] + + expected = tf.constant([0, 0, 0, 0], dtype=tf.float32) + tf.assert_equal(tf.cast(not_a_and_a, tf.float32), expected) + + expected = tf.cast([not_0] * 4, tf.float32) + tf.assert_equal(tf.cast(not_a_or_a, tf.float32), expected) + + # For unsigned dtypes let's also check the result directly. + if dtype.is_unsigned: + inverted = bitwise_ops.invert(input_tensor) + expected = tf.constant([dtype.max - x for x in inputs], dtype=tf.float32) + tf.assert_equal(tf.cast(inverted, tf.float32), tf.cast(expected, tf.float32)) +``` }]; let arguments = (ins @@ -1394,7 +1446,6 @@ pad(t, paddings) ==> [[2, 1, 1, 2, 3, 3, 2] TF_DerivedOperandTypeAttr Tpaddings = TF_DerivedOperandTypeAttr<1>; } - def TF_MulOp : TF_Op<"Mul", [Broadcastable, Commutative, NoSideEffect]>, WithBroadcastableBinOpBuilder { let summary = "Returns x * y element-wise."; @@ -2241,9 +2292,17 @@ Specifically, `y = 1 / (1 + exp(-x))`. } def TF_SinOp : TF_Op<"Sin", [NoSideEffect, SameOperandsAndResultType]> { - let summary = "Computes sin of x element-wise."; + let summary = "Computes sine of x element-wise."; let description = [{ +Given an input tensor, this function computes sine of every + element in the tensor. Input range is `(-inf, inf)` and + output range is `[-1,1]`. + + ```python + x = tf.constant([-float("inf"), -9, -0.5, 1, 1.2, 200, 10, float("inf")]) + tf.math.sin(x) ==> [nan -0.4121185 -0.47942555 0.84147096 0.9320391 -0.87329733 -0.54402107 nan] + ``` }]; let arguments = (ins