code: def test_shapes_and_gradients(
      self,
      event_shape,
      constraining_bijector,
      batch_shape,
      dtype,
      is_static,
  ):
      if not tf.executing_eagerly() and not is_static:
          self.skipTest(
              "tfb.Reshape requires statically known shapes in graph"
              " mode."
          )
      net = maf_lib.AutoregressiveNetwork(
          2, hidden_units=[4, 4], dtype=dtype
      )
      maf = maf_lib.MaskedAutoregressiveFlow(
          shift_and_log_scale_fn=net, validate_args=True
      )
  
      seed = test_util.test_seed_stream()
      surrogate_posterior = surrogate_posteriors.build_split_flow_surrogate_posterior(
          event_shape=tf.nest.map_structure(
              lambda s: self.maybe_static(  # pylint: disable=g-long-lambda
                  np.array(s, dtype=np.int32), is_static=is_static
              ),
              event_shape,
          ),
          constraining_bijector=constraining_bijector,
          batch_shape=batch_shape,
          trainable_bijector=maf,
          dtype=dtype,
          validate_args=True,
      )
  
      # Add an op to the graph so tf.Variables get created in graph mode.
      _ = surrogate_posterior.sample(seed=seed())
      self.evaluate(
          [
              v.initializer
              for v in surrogate_posterior.trainable_variables
          ]
      )
  
      self._test_shapes(
          surrogate_posterior,
          batch_shape=batch_shape,
          event_shape=event_shape,
          seed=seed(),
      )
      self._test_gradients(surrogate_posterior, seed=seed())
      self._test_dtype(surrogate_posterior, dtype, 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 SplitFlowSurrogatePosterior obj's underlying member method code with example usage: obj.test_shapes_and_gradients(event_shape, constraining_bijector, batch_shape, dtype, is_static) without return types