code: def test_distribution_init_apply(
      self, generator, expected_num_params, shape
  ):
      # Test passing arguments to the wrapper.
      init_fn, apply_fn = trainable_state_util.as_stateless_builder(
          generator
      )(shape)
  
      seed = test_util.test_seed(sampler_type="stateless")
      params = init_fn(seed)
      self.assertLen(params, expected_num_params)
  
      # Check that the distribution's samples have the expected shape.
      dist = apply_fn(params)
      x = dist.sample(seed=seed)
      self.assertAllEqualNested(
          shape, tf.nest.map_structure(ps.shape, x)
      )
  
      # Check that gradients are defined.
      _, grad = gradient.value_and_gradient(
          lambda *params: apply_fn(*params).log_prob(x), params
      )
      self.assertLen(grad, expected_num_params)
      self.assertAllNotNone(grad)
  
imports: import functools
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import identity
  from tensorflow_probability.python.bijectors import joint_map
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.distributions import deterministic
  from tensorflow_probability.python.distributions import joint_distribution_auto_batched
  from tensorflow_probability.python.distributions import joint_distribution_sequential
  from tensorflow_probability.python.distributions import lognormal
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.internal import tf_keras
  from tensorflow_probability.python.internal import trainable_state_util
  from tensorflow_probability.python.math import gradient
  from tensorflow_probability.python.math.minimize import minimize
  from tensorflow_probability.python.math.minimize import minimize_stateless
label_desc: Use image node_id 2 for calling the TestWrapGeneratorAsStateless obj's underlying member method code with example usage: obj.test_distribution_init_apply(generator, expected_num_params, shape) without return types