def METHOD_NAME(t, axis):
  """Add a new dimension to tensor `t` along `axis`.
  Args:
    t: A `tf.Tensor` or `tf.SparseTensor`.
    axis: A `0D` integer scalar.
  Returns:
    An expanded tensor.
  Raises:
    NotImplementedError: If `t` is a `SparseTensor` and `axis != 0`.
  """
  if isinstance(t, tf.SparseTensor):
    if tf.is_tensor(axis) or axis != 0:
      raise NotImplementedError(
          'Can only expand_dims on SparseTensor {} on static axis 0, '
          'but received axis {}'.format(t, axis)
      )
    n_elem = (
        t.indices.shape[0]
        or tf.get_static_shape(t.dense_shape)[0]
        or tf.shape(t.indices)[0]
    )
    shape_ = tf.cast(t.shape, tf.int64)
    return tf.SparseTensor(
        indices=tf.concat(
            (tf.zeros([n_elem, 1], dtype=tf.int64), t.indices), axis=1
        ),
        values=t.values,
        dense_shape=tf.concat(([1], shape_), axis=0),
    )
  else:
    return tf.METHOD_NAME(t, axis)