code: def _replace_event_shape_in_shape_tensor(
      input_shape, event_shape_in, event_shape_out, validate_args
  ):
      """Replaces the rightmost dims in a `Tensor` representing a shape.
  
      Args:
        input_shape: a rank-1 `Tensor` of integers
        event_shape_in: the event shape expected to be present in rightmost dims
          of `shape_in`.
        event_shape_out: the event shape with which to replace `event_shape_in` in
          the rightmost dims of `input_shape`.
        validate_args: Python `bool` indicating whether arguments should
          be checked for correctness.
  
      Returns:
        output_shape: A rank-1 integer `Tensor` with the same contents as
          `input_shape` except for the event dims, which are replaced with
          `event_shape_out`.
      """
      (
          output_tensorshape,
          is_validated,
      ) = _replace_event_shape_in_tensorshape(
          tensorshape_util.constant_value_as_shape(input_shape),
          event_shape_in,
          event_shape_out,
      )
  
      if tensorshape_util.is_fully_defined(output_tensorshape) and (
          is_validated or not validate_args
      ):
          output_shape = ps.convert_to_shape_tensor(
              tensorshape_util.as_list(output_tensorshape),
              name="output_shape",
              dtype_hint=tf.int32,
          )
          return output_shape, output_tensorshape
  
      event_shape_in_ndims = (
          ps.size(event_shape_in)
          if tensorshape_util.num_elements(event_shape_in.shape) is None
          else tensorshape_util.num_elements(event_shape_in.shape)
      )
      input_non_event_shape, input_event_shape = ps.split(
          input_shape, num_or_size_splits=[-1, event_shape_in_ndims]
      )
  
      additional_assertions = []
      if is_validated:
          pass
      elif validate_args:
          # Check that `input_event_shape` and `event_shape_in` are compatible in the
          # sense that they have equal entries in any position that isn't a `-1` in
          # `event_shape_in`. Note that our validations at construction time ensure
          # there is at most one such entry in `event_shape_in`.
          mask = event_shape_in >= 0
          explicit_input_event_shape = tf.boolean_mask(
              input_event_shape, mask=mask
          )
          explicit_event_shape_in = tf.boolean_mask(
              event_shape_in, mask=mask
          )
          additional_assertions.append(
              assert_util.assert_equal(
                  explicit_input_event_shape,
                  explicit_event_shape_in,
                  message="Input `event_shape` does not match `event_shape_in`.",
              )
          )
          # We don't explicitly additionally verify
          # `tf.size(input_shape) > tf.size(event_shape_in)` since `tf.split`
          # already makes this assertion.
  
      with tf.control_dependencies(additional_assertions):
          output_shape = ps.concat(
              [input_non_event_shape, event_shape_out],
              axis=0,
              name="output_shape",
          )
  
      return output_shape, output_tensorshape
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import bijector
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.internal import tensorshape_util
label_desc: Use image node_id 1 for calling a global function with example usage: _replace_event_shape_in_shape_tensor(input_shape, event_shape_in, event_shape_out, validate_args) and returns: output_shape,  output_tensorshape, output_shape,  output_tensorshape