code: def map_fn_over_parameters_with_event_ndims(
      batch_object,
      fn,
      bijector_x_event_ndims=None,
      require_static=False,
      **parameter_kwargs,
  ):
      """Maps `fn` over an object's parameters and corresponding param event_ndims.
  
      Args:
        batch_object: Python object, typically a `tfd.Distribution` or
          `tfb.Bijector`. This must implement the method
          `batched_object.parameter_properties()` and expose a dict
          `batched_object.parameters` of the parameters passed to its constructor.
        fn: Python `callable` with signature `result = fn(param, param_event_ndims)`
          to be applied to the parameters of `batch_object`.
        bijector_x_event_ndims: If `batch_object` is a bijector, this is the
          (structure of) integer(s) value of `x_event_ndims` in the current context
          (for example, as passed to `experimental_batch_shape`). Otherwise, this
          argument should be `None`.
          Default value: `None`.
        require_static: Python `bool`, whether to use only statically available
          `event_ndims` information. If `True`, this function will perform
          no Tensor operations (other than any performed by `fn` itself), but may
          invoke `fn` with `param_event_ndims=None`.
          Default value: `False`.
        **parameter_kwargs: Optional keyword arguments overriding the parameter
          values in `batch_object.parameters`. Typically this is used to avoid
          multiple Tensor conversions of the same value.
  
      Returns:
        results: Dictionary with parameter names (Python `str` values) as
          keys, containing results returned by `fn`. Parameters whose value is
          `None` or that have undefined `event_ndims` will be omitted.
      """
      results = {}
      parameter_properties = type(batch_object).parameter_properties()
  
      for kwarg in parameter_kwargs:
          if kwarg not in parameter_properties:
              logging.warning(
                  "Keyword argument `%s` was not expected and will be ignored. "
                  "Expected any of the parameters: %s. Any of "
                  "these not passed as arguments will be read from "
                  "`self.parameters`, resulting in redundant Tensor "
                  "conversions if they were not already specified as Tensors.",
                  kwarg,
                  parameter_properties.keys(),
              )
  
      for param_name, param in dict(
          batch_object.parameters, **parameter_kwargs
      ).items():
          if param is None:
              continue
          if param_name not in parameter_properties:
              continue
  
          # Ndims of base shape used for a *minimal* event.
          properties = parameter_properties[param_name]
  
          from tensorflow_probability.python.internal import (
              parameter_properties as pp,
          )  # pylint:disable=g-import-not-at-top
  
          if (
              properties.event_ndims is None
              or properties.event_ndims is pp.NO_EVENT_NDIMS
          ):
              continue
          if bijector_x_event_ndims is not None:
              param_event_ndims = (
                  properties.bijector_instance_event_ndims(
                      batch_object,
                      x_event_ndims=bijector_x_event_ndims,
                      require_static=require_static,
                  )
              )
          else:
              param_event_ndims = properties.instance_event_ndims(
                  batch_object, require_static=require_static
              )
  
          if param_event_ndims is pp.NO_EVENT_NDIMS:
              continue
  
          if param_name not in parameter_kwargs:
              # Values from `batch_object.parameters` have not been converted to
              # Tensor, so may be lists or other literals with unexpected structure.
              # First, try to get the param's public attribute, since this will
              # typically have been converted to Tensor if applicable.
              if hasattr(batch_object, param_name):
                  param = getattr(batch_object, param_name)
              elif (
                  properties.is_tensor
                  and not tf.is_tensor(param)
                  and not tf.nest.is_nested(param_event_ndims)
              ):
                  # As a last resort, try an explicit conversion.
                  param = tensor_util.convert_nonref_to_tensor(
                      param, name=param_name
                  )
  
          results[param_name] = nest.map_structure_up_to(
              param, fn, param, param_event_ndims
          )
      return results
  
file_path: probability/tensorflow_probability/python/internal/batch_shape_lib.py
imports: import functools
  from absl import logging
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow.python.util import nest
label_desc: Use image node_id 10 for calling a global function with example usage: map_fn_over_parameters_with_event_ndims(batch_object, fn, bijector_x_event_ndims, require_static) and returns: results