code: def test_constrained_affine_from_distributions(
      self,
      dist_classes,
      event_shape,
      operators,
      initial_loc,
      implicit_batch_shape,
      bijector,
      dtype,
      is_static,
      is_stateless=JAX_MODE,
  ):
      if not tf.executing_eagerly() and not is_static:
          self.skipTest(
              "tfb.Reshape requires statically known shapes in graph"
              " mode."
          )
  
      (
          init_seed,
          grads_seed,
          shapes_seed,
          dtype_seed,
      ) = samplers.split_seed(
          test_util.test_seed(sampler_type="stateless"), n=4
      )
  
      # pylint: disable=g-long-lambda
      initial_loc = tf.nest.map_structure(
          lambda s: self.maybe_static(
              np.array(s, dtype=dtype), is_static=is_static
          ),
          initial_loc,
      )
      distributions = nest.map_structure_up_to(
          dist_classes,
          lambda d, loc, s: independent.Independent(
              d(loc=loc, scale=1.0),
              reinterpreted_batch_ndims=ps.rank_from_shape(s),
          ),
          dist_classes,
          initial_loc,
          event_shape,
      )
      # pylint: enable=g-long-lambda
  
      surrogate_posterior = self._initialize_surrogate(
          "build_affine_surrogate_posterior_from_base_distribution",
          is_stateless=is_stateless,
          seed=init_seed,
          base_distribution=distributions,
          operators=operators,
          bijector=bijector,
          validate_args=True,
      )
  
      event_shape = nest.map_structure(
          lambda d: d.event_shape_tensor(), distributions
      )
      if bijector is not None:
          event_shape = nest.map_structure(
              lambda b, s: s
              if b is None
              else b.forward_event_shape_tensor(s),
              bijector,
              event_shape,
          )
  
      self._test_shapes(
          surrogate_posterior,
          batch_shape=implicit_batch_shape,
          event_shape=event_shape,
          seed=shapes_seed,
      )
      self._test_dtype(surrogate_posterior, dtype, dtype_seed)
      if not is_stateless:
          self._test_gradients(surrogate_posterior, seed=grads_seed)
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import exp
  from tensorflow_probability.python.bijectors import fill_triangular
  from tensorflow_probability.python.bijectors import identity
  from tensorflow_probability.python.bijectors import joint_map
  from tensorflow_probability.python.bijectors import masked_autoregressive
  from tensorflow_probability.python.bijectors import sigmoid
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.distributions import deterministic
  from tensorflow_probability.python.distributions import exponential
  from tensorflow_probability.python.distributions import gamma
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import joint_distribution_coroutine
  from tensorflow_probability.python.distributions import joint_distribution_named
  from tensorflow_probability.python.distributions import joint_distribution_sequential
  from tensorflow_probability.python.distributions import laplace
  from tensorflow_probability.python.distributions import logistic
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import sample
  from tensorflow_probability.python.distributions import student_t
  from tensorflow_probability.python.experimental.vi import surrogate_posteriors
  from tensorflow_probability.python.internal import nest_util
  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.vi import optimization
  from tensorflow.python.util import nest
label_desc: Use image node_id 1 for calling the AffineSurrogatePosterior obj's underlying member method code with example usage: obj.test_constrained_affine_from_distributions(dist_classes, event_shape, operators, initial_loc, implicit_batch_shape, bijector, dtype, is_static, is_stateless) without return types