code: def testCompareGradientToTfRandomGammaGradientWithNonLinearity(self):
      # Test that the gradient is correctly computed through a non-linearity.
  
      n_concentration = 4
      concentration_v = tf.constant(
          np.array(
              [np.arange(1, n_concentration + 1, dtype=np.float32)]
          )
      )
      n_rate = 2
      rate_v = tf.constant(
          np.array([np.arange(1, n_rate + 1, dtype=np.float32)]).T
      )
      num_samples = int(1e5)
  
      def tfp_gamma(a, b):
          return tf.math.square(
              gamma_lib.Gamma(
                  concentration=a, rate=b, validate_args=True
              ).sample(num_samples, seed=test_util.test_seed())
          )
  
      _, [grad_concentration, grad_rate] = self.evaluate(
          gradient.value_and_gradient(
              tfp_gamma, [concentration_v, rate_v]
          )
      )
  
      def tf_gamma(a, b):
          return tf.math.square(
              tf.random.gamma(
                  shape=[num_samples],
                  alpha=a,
                  beta=b,
                  seed=test_util.test_seed(),
              )
          )
  
      _, [grad_concentration_tf, grad_rate_tf] = self.evaluate(
          gradient.value_and_gradient(
              tf_gamma, [concentration_v, rate_v]
          )
      )
  
      self.assertEqual(
          grad_concentration.shape, grad_concentration_tf.shape
      )
      self.assertEqual(grad_rate.shape, grad_rate_tf.shape)
      self.assertAllClose(
          grad_concentration, grad_concentration_tf, rtol=2e-2
      )
      self.assertAllClose(grad_rate, grad_rate_tf, rtol=2e-2)
  
imports: import functools
  from absl.testing import parameterized
  import numpy
  from scipy import misc
  from scipy import special
  from scipy import stats
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import exp
  from tensorflow_probability.python.distributions import gamma
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions.internal import statistical_testing
  from tensorflow_probability.python.internal import implementation_selection
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
label_desc: Use image node_id 22 for calling the GammaTest obj's underlying member method code with example usage: obj.testCompareGradientToTfRandomGammaGradientWithNonLinearity() and returns: tf, tf