code: def testClipByValueGradient(self):
      def grad(x, y, z, clip_fn):
          x = constant_op.constant(x, dtype=dtypes.float32)
          y = constant_op.constant(y, dtype=dtypes.float32)
          z = constant_op.constant(z, dtype=dtypes.float32)
          with backprop.GradientTape() as tape:
              tape.watch(x)
              tape.watch(y)
              tape.watch(z)
              output = clip_fn(x, y, z)
          return tape.gradient(output, [x, y, z])
  
      for f in (clip_ops.clip_by_value, gen_math_ops._clip_by_value):
          with self.subTest(f=f):
              # Input: [Scalar, Scalar, Scalar]
              xg, yg, zg = grad(0, -1, 1, clip_fn=f)
              self.assertEqual(self.evaluate(xg), 1)
              self.assertEqual(self.evaluate(yg), 0)
              self.assertEqual(self.evaluate(zg), 0)
  
              # Input: [Scalar, Scalar, Scalar]
              xg, yg, zg = grad(2, -1, 1, clip_fn=f)
              self.assertEqual(self.evaluate(xg), 0)
              self.assertEqual(self.evaluate(yg), 0)
              self.assertEqual(self.evaluate(zg), 1)
  
              # Input: [Vector, Scalar, Scalar]
              xg, yg, zg = grad([0, -2, 2, -2], -1, 1, clip_fn=f)
              self.assertAllEqual(self.evaluate(xg), [1, 0, 0, 0])
              self.assertEqual(self.evaluate(yg), 2)
              self.assertEqual(self.evaluate(zg), 1)
  
              # Input: [Vector, Vector, Scalar]
              xg, yg, zg = grad(
                  [-1, -2, 0, 2], [-2, -1, -3, 0], 1, clip_fn=f
              )
              self.assertAllEqual(self.evaluate(xg), [1, 0, 1, 0])
              self.assertAllEqual(self.evaluate(yg), [0, 1, 0, 0])
              self.assertEqual(self.evaluate(zg), 1)
  
              # Input: [Vector, Vector, Vector]
              xg, yg, zg = grad(
                  [-1, -2, 0, 2],
                  [-2, -1, -3, 0],
                  [1, 2, -1, 1],
                  clip_fn=f,
              )
              self.assertAllEqual(self.evaluate(xg), [1, 0, 0, 0])
              self.assertAllEqual(self.evaluate(yg), [0, 1, 0, 0])
              self.assertAllEqual(self.evaluate(zg), [0, 0, 1, 1])
  
      # Only test the following with `clip_ops.clip_by_value`, as
      # `gen_math_ops._clip_by_value` requires the min and max values to be
      # scalar or the same shape as the input.
  
      # Input: [Matrix, Vector, Matrix]
      xg, yg, zg = grad(
          [[-2, 3], [2, -1]],
          [-1, -2],
          [[1, 2], [3, 4]],
          clip_fn=clip_ops.clip_by_value,
      )
      self.assertAllEqual(self.evaluate(xg), [[0, 0], [1, 1]])
      self.assertAllEqual(self.evaluate(yg), [1, 0])
      self.assertAllEqual(self.evaluate(zg), [[0, 1], [0, 0]])
  
imports: import numpy
  from tensorflow.python.eager import backprop
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import indexed_slices
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import clip_ops
  from tensorflow.python.ops import gen_math_ops
  from tensorflow.python.ops import gradients_impl
  from tensorflow.python.ops import math_ops
  from tensorflow.python.platform import test
label_desc: Use image node_id 6 for calling the ClipTest obj's underlying member method code with example usage: obj.testClipByValueGradient() and returns: tape