code: def sum_rightmost_ndims_preserving_shape(x, ndims):
      """Return `Tensor` with right-most ndims summed.
  
      Args:
        x: the `Tensor` whose right-most `ndims` dimensions to sum
        ndims: number of right-most dimensions to sum.
  
      Returns:
        A `Tensor` resulting from calling `reduce_sum` on the `ndims` right-most
        dimensions. If the shape of `x` is statically known, the result will also
        have statically known shape. Otherwise, the resulting shape will only be
        known at runtime.
      """
      x = tf.convert_to_tensor(x)
      x_ndims = ps.rank(x)
      return tf.reduce_sum(x, axis=ps.range(x_ndims - ndims, x_ndims))
  
file_path: probability/tensorflow_probability/python/math/psd_kernels/internal/util.py
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensorshape_util
label_desc: Use image node_id 2 for calling a global function with example usage: sum_rightmost_ndims_preserving_shape(x, ndims) and returns: tf