code: def test_works_with_structured_samples(self):
      # Check that we don't accidentally destroy the structure of `samples` when
      # it's a dict or other non-Tensor object from a joint distribution.
      p = jdn.JointDistributionNamed(
          {"x": normal.Normal(0.0, 1.0), "y": normal.Normal(0.0, 1.0)}
      )
  
      seed = test_util.test_seed()
      total_variance_with_reparam = expectation.expectation(
          f=lambda d: d["x"] ** 2 + d["y"] ** 2,
          samples=p.sample(1000, seed=seed),
          log_prob=p.log_prob,
          use_reparameterization=True,
      )
      total_variance_without_reparam = expectation.expectation(
          f=lambda d: d["x"] ** 2 + d["y"] ** 2,
          samples=p.sample(1000, seed=seed),
          log_prob=p.log_prob,
          use_reparameterization=False,
      )
      [
          total_variance_with_reparam_,
          total_variance_without_reparam_,
      ] = self.evaluate(
          [total_variance_with_reparam, total_variance_without_reparam]
      )
      self.assertAllClose(total_variance_with_reparam_, 2.0, atol=0.2)
      self.assertAllClose(
          total_variance_without_reparam_, 2.0, atol=0.2
      )
  
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 4 for calling the ExpectationTest obj's underlying member method code with example usage: obj.test_works_with_structured_samples() without return types