docstr: Test the gradients of the samples w.r.t. loc and scale.
docstr_tok: ["Test","the","gradients","of","the","samples","w.r.t",".","loc","and","scale","."]
code: def testDifferentiableSampleAnalytically(self):
      """Test the gradients of the samples w.r.t. loc and scale."""
      n = 10
      sample_shape = [n, n]
      n_samples = np.prod(sample_shape)
  
      n_params = 20
      loc = tf.constant(
          np.linspace(-3.0, stop=3.0, num=n_params), dtype=self.dtype
      )
      scale = tf.constant(
          np.linspace(0.1, stop=10.0, num=n_params), dtype=self.dtype
      )
      skewness = tf.constant(
          np.linspace(0.75, stop=1.33, num=n_params), dtype=self.dtype
      )
  
      seed = test_util.test_seed()
  
      def get_exp_samples(loc, scale):
          dist = two_piece_normal.TwoPieceNormal(
              loc=loc,
              scale=scale,
              skewness=skewness,
              validate_args=True,
          )
          return tf.math.exp(dist.sample(sample_shape, seed=seed))
  
      exp_samples, dsamples = gradient.value_and_gradient(
          get_exp_samples, [loc, scale]
      )
      dloc_auto, dscale_auto = [grad / n_samples for grad in dsamples]
  
      dloc_calc = tf.reduce_mean(exp_samples, axis=[0, 1])
      dscale_calc = tf.reduce_mean(
          (tf.math.log(exp_samples) - loc) / scale * exp_samples,
          axis=[0, 1],
      )
  
      self.assertAllClose(dloc_auto, dloc_calc)
      self.assertAllClose(dscale_auto, dscale_calc)
  
imports: import itertools
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import two_piece_normal
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
label_desc: Use image node_id 21 for calling the _TwoPieceNormalTest obj's underlying member method code with example usage: obj.testDifferentiableSampleAnalytically() and returns: tf