class_docstr: Test class for utils_tf
class_docstr_tok: ["Test","class","for","utils_tf"]
docstr: test_clip_eta_goldilocks: Test that the clipping handles perturbations
  that are too small, just right, and too big correctly
docstr_tok: ["test_clip_eta_goldilocks",":","Test","that","the","clipping","handles","perturbations","that","are","too","small",",","just","right",",","and","too","big","correctly"]
code: def test_clip_eta_goldilocks(self):
      """test_clip_eta_goldilocks: Test that the clipping handles perturbations
      that are too small, just right, and too big correctly"""
      eta = tf.constant([[2.0], [3.0], [4.0]])
      self.assertTrue(eta.dtype == tf.float32, eta.dtype)
      eps = 3.0
      for ord_arg in [np.inf, 1, 2]:
          for sign in [-1.0, 1.0]:
              try:
                  clipped = utils_tf.clip_eta(eta * sign, ord_arg, eps)
              except NotImplementedError:
                  # Don't raise SkipTest, it skips the rest of the for loop
                  continue
              clipped_value = self.sess.run(clipped)
              gold = sign * np.array([[2.0], [3.0], [3.0]])
              self.assertClose(clipped_value, gold)
              (grad,) = tf.gradients(clipped, eta)
              grad_value = self.sess.run(grad)
              # Note: the second 1. is debatable (the left-sided derivative
              # and the right-sided derivative do not match, so formally
              # the derivative is not defined). This test makes sure that
              # we at least handle this oddity consistently across all the
              # argument values we test
              gold = sign * np.array([[1.0], [1.0], [0.0]])
              self.assertClose(grad_value, gold)
  
file_path: cleverhans/cleverhans_v3.1.0/tests_tf/test_utils_tf.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import numpy
  import tensorflow
  from cleverhans import utils_tf
  from cleverhans.devtools.checks import CleverHansTest
label_desc: Use image node_id 6 for calling the TestUtilsTF obj's underlying member method code with example usage: obj.test_clip_eta_goldilocks() without return types