code: def _update_forward_min_event_ndims(
      bij,
      downstream_quantities,
      get_forward_min_event_ndims=lambda b: b.forward_min_event_ndims,
      get_inverse_min_event_ndims=lambda b: b.inverse_min_event_ndims,
      inverse_event_ndims_fn=lambda b, nd: b.inverse_event_ndims(nd),
  ):
      """Step backwards through the graph to infer `forward_min_event_ndims`.
  
      Args:
        bij: local tfb.Bijector instance at the current graph node.
        downstream_quantities: Instance of `MinEventNdimsDownstreamQuantities`
          namedtuple, containing event_ndims that satisfy the bijector(s)
          downstream from `bij` in the graph. May be `None` if there are no such
          bijectors.
        get_forward_min_event_ndims: callable; may be overridden to swap
          forward/inverse direction.
        get_inverse_min_event_ndims: callable; may be overridden to swap
          forward/inverse direction.
        inverse_event_ndims_fn: callable; may be overridden to swap
          forward/inverse direction.
      Returns:
        downstream_quantities: Instance of `MinEventNdimsDownstreamQuantities`
          namedtuple containing event_ndims that satisfy `bij` and all downstream
          bijectors.
      """
      if downstream_quantities is None:  # This is a leaf bijector.
          return MinEventNdimsInferenceDownstreamQuantities(
              forward_min_event_ndims=get_forward_min_event_ndims(bij),
              parts_interact=bij._parts_interact,
          )  # pylint: disable=protected-access
  
      inverse_min_event_ndims = get_inverse_min_event_ndims(bij)
      downstream_min_event_ndims = nest_util.coerce_structure(
          inverse_min_event_ndims,
          downstream_quantities.forward_min_event_ndims,
      )
  
      # Update the min_event_ndims that is a valid input to downstream bijectors
      # to also be a valid *output* of this bijector, or equivalently, a valid
      # input to `bij.inverse`.
      rank_mismatches = tf.nest.flatten(
          tf.nest.map_structure(
              lambda dim, min_dim: dim - min_dim,
              downstream_min_event_ndims,
              inverse_min_event_ndims,
          )
      )
      if downstream_quantities.parts_interact:
          # If downstream bijectors involve interaction between parts,
          # then a valid input to the downstream bijectors must augment the
          # `downstream_min_event_ndims` by the
          # same rank for every part (otherwise we would induce event shape
          # broadcasting). Hopefully, this will also avoid event-shape broadcasting
          # at the current bijector---if not, the composition is invalid, and the call
          # to `bij.inverse_event_ndims(valid_inverse_min_event_ndims)` below will
          # raise an exception.
          maximum_rank_deficiency = -ps.reduce_min(
              [0] + rank_mismatches
          )
          valid_inverse_min_event_ndims = tf.nest.map_structure(
              lambda ndims: maximum_rank_deficiency + ndims,
              downstream_min_event_ndims,
          )
      else:
          if bij._parts_interact:  # pylint: disable=protected-access
              # If this bijector does *not* operate independently on its parts, then a
              # valid input to `inverse` cannot require event shape broadcasting. That
              # is, each part must have the same 'excess rank' above the local
              # inverse_min_event_ndims; we ensure this by construction.
              maximum_excess_rank = ps.reduce_max([0] + rank_mismatches)
              valid_inverse_min_event_ndims = tf.nest.map_structure(
                  lambda ndims: maximum_excess_rank + ndims,
                  inverse_min_event_ndims,
              )
          else:
              # If all parts are independent, can take the pointwise max event_ndims.
              valid_inverse_min_event_ndims = tf.nest.map_structure(
                  ps.maximum,
                  downstream_min_event_ndims,
                  inverse_min_event_ndims,
              )
  
      return MinEventNdimsInferenceDownstreamQuantities(
          # Pull the desired output ndims back through the bijector, to get
          # the ndims of a valid *input*.
          forward_min_event_ndims=inverse_event_ndims_fn(
              bij, valid_inverse_min_event_ndims
          ),
          parts_interact=(
              downstream_quantities.parts_interact
              or bij._parts_interact
          ),
      )
  
imports: import collections
  import functools
  import sys
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import bijector
  from tensorflow_probability.python.bijectors import ldj_ratio
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import nest_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow.python.ops import control_flow_util
  from tensorflow.python.util import nest
label_desc: Use image node_id 6 for calling a global function with example usage: _update_forward_min_event_ndims(bij, downstream_quantities, get_forward_min_event_ndims, get_inverse_min_event_ndims, inverse_event_ndims_fn) and returns: MinEventNdimsInferenceDownstreamQuantities, MinEventNdimsInferenceDownstreamQuantities