code: def testGradient(self):
      with self.test_session() as sess:
          x = tf.placeholder(tf.float64)
          quadratic_linear_boundary = 3
          loss = clipping_ops.huber_loss(x, quadratic_linear_boundary)
          xs = np.array(
              [
                  -5,
                  -4,
                  -3.1,
                  -3,
                  -2.9,
                  2,
                  -1,
                  0,
                  1,
                  2,
                  2.9,
                  3,
                  3.1,
                  4,
                  5,
              ]
          )
          grads = sess.run(
              tf.gradients([loss], [x]), feed_dict={x: xs}
          )[0]
  
      self.assertTrue(
          np.all(np.abs(grads) <= quadratic_linear_boundary)
      )
  
      # Everything <= -3 should have gradient -3.
      grads_lo = grads[xs <= -quadratic_linear_boundary]
      self.assertAllEqual(
          grads_lo, [-quadratic_linear_boundary] * grads_lo.shape[0]
      )
  
      # Everything >= 3 should have gradient 3.
      grads_hi = grads[xs >= quadratic_linear_boundary]
      self.assertAllEqual(
          grads_hi, [quadratic_linear_boundary] * grads_hi.shape[0]
      )
  
      # x in (-3, 3) should have gradient x.
      grads_mid = grads[np.abs(xs) <= quadratic_linear_boundary]
      xs_mid = xs[np.abs(xs) <= quadratic_linear_boundary]
      self.assertAllEqual(grads_mid, xs_mid)
  
file_path: trfl/trfl/clipping_ops_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import tensorflow.compat.v1
  from trfl import clipping_ops
label_desc: Use image node_id 2 for calling the HuberLossTest obj's underlying member method code with example usage: obj.testGradient() without return types