code: def test_works_correctly(self):
      x = tf.constant([-1e6, -100, -10, -1, 1, 10, 100, 1e6])
  
      # We use the prefex "efx" to mean "E_p[f(X)]".
      f = lambda u: u
  
      efx_true = x
  
      def e_fx_reparam(x):
          p = normal.Normal(loc=x, scale=1.0)
          samples = p.sample(int(1e5), seed=test_util.test_seed())
          return expectation.expectation(f, samples, p.log_prob)
  
      def e_fx_score(x):
          p = normal.Normal(loc=x, scale=1.0)
          samples = p.sample(int(1e5), seed=test_util.test_seed())
          return expectation.expectation(
              f, samples, p.log_prob, use_reparameterization=False
          )
  
      efx_true, efx_true_grad = gradient.value_and_gradient(
          lambda x: x, x
      )
      efx_reparam, efx_reparam_grad = gradient.value_and_gradient(
          e_fx_reparam, x
      )
      efx_score, efx_score_grad = gradient.value_and_gradient(
          e_fx_score, x
      )
  
      self.assertAllEqual(tf.ones_like(efx_true_grad), efx_true_grad)
  
      self.assertAllClose(efx_true, efx_reparam, rtol=0.01, atol=0.0)
      self.assertAllClose(efx_true, efx_score, rtol=0.01, atol=0.0)
  
      self.assertAllEqual(
          tf.ones_like(efx_true_grad, dtype=tf.bool),
          tf.math.is_finite(efx_reparam_grad),
      )
      self.assertAllEqual(
          tf.ones_like(efx_true_grad, dtype=tf.bool),
          tf.math.is_finite(efx_score_grad),
      )
  
      self.assertAllClose(
          efx_true_grad, efx_reparam_grad, rtol=0.03, atol=0.0
      )
      # Variance is too high to be meaningful, so we'll only check those which
      # converge.
      self.assertAllClose(
          efx_true_grad[2:-2], efx_score_grad[2:-2], rtol=0.05, atol=0.0
      )
  
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import bernoulli
  from tensorflow_probability.python.distributions import joint_distribution_named
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.internal.monte_carlo import _get_samples
  from tensorflow_probability.python.math import gradient
  from tensorflow_probability.python.monte_carlo import expectation
label_desc: Use image node_id 1 for calling the ExpectationTest obj's underlying member method code with example usage: obj.test_works_correctly() and returns: expectation, expectation