code: def testSqrtWithFiniteGradsHasCorrectGradients(self):
      self.assertTrue(
          np.isnan(self.evaluate(util.sqrt_with_finite_grads(-1.0)))
      )
      xs = tf.constant(np.linspace(1e-10, 10.0, 100))
      _, grad_tf_sqrt = value_and_gradient(tf.sqrt, xs)
      _, grad_safe_sqrt = value_and_gradient(
          util.sqrt_with_finite_grads, xs
      )
      self.assertAllEqual(
          *self.evaluate([grad_tf_sqrt, grad_safe_sqrt])
      )
  
      zero = tf.constant(0.0)
      _, grad_tf_sqrt = value_and_gradient(tf.sqrt, zero)
      _, grad_safe_sqrt = value_and_gradient(
          util.sqrt_with_finite_grads, zero
      )
      self.assertNotEqual(
          *self.evaluate([grad_tf_sqrt, grad_safe_sqrt])
      )
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math.gradient import value_and_gradient
  from tensorflow_probability.python.math.psd_kernels.internal import util
label_desc: Use image node_id 9 for calling the UtilTest obj's underlying member method code with example usage: obj.testSqrtWithFiniteGradsHasCorrectGradients() without return types