code: def sparse_cross_entropy(
      true: Union[ivy.Array, ivy.NativeArray],
      pred: Union[ivy.Array, ivy.NativeArray],
      /,
      *,
      axis: int = -1,
      epsilon: float = 1e-7,
      reduction: str = "mean",
      out: Optional[ivy.Array] = None,
  ) -> ivy.Array:
      """Compute sparse cross entropy between logits and labels.
  
      Parameters
      ----------
      true
       input array containing the true labels as logits.
      pred
       input array containing the predicted labels as logits.
      axis
       the axis along which to compute the cross-entropy. If axis is ``-1``, the
       cross-entropy will be computed along the last dimension. Default: ``-1``.
      epsilon
       a float in [0.0, 1.0] specifying the amount of smoothing when calculating the
       loss. If epsilon is ``0``, no smoothing will be applied. Default: ``1e-7``.
      out
       optional output array, for writing the result to. It must have a shape
       that the inputs broadcast to.
  
      Returns
      -------
      ret
          The sparse cross-entropy loss between the given distributions
  
      Examples
      --------
      With :class:`ivy.Array` input:
  
      >> x = ivy.array([2])
      >> y = ivy.array([0.1, 0.1, 0.7, 0.1])
      >> print(ivy.sparse_cross_entropy(x, y))
      ivy.array([0.35667494])
  
      >>> x = ivy.array([3])
      >>> y = ivy.array([0.1, 0.1, 0.7, 0.1])
      >>> print(ivy.cross_entropy(x, y))
      ivy.array(21.79329094)
  
      >>> x = ivy.array([2,3])
      >>> y = ivy.array([0.1, 0.1])
      >>> print(ivy.cross_entropy(x, y))
      ivy.array(11.512926)
  
      With :class:`ivy.NativeArray` input:
  
      >>> x = ivy.native_array([4])
      >>> y = ivy.native_array([0.1, 0.2, 0.1, 0.1, 0.5])
      >>> print(ivy.sparse_cross_entropy(x, y))
      ivy.array([0.693])
  
      With :class:`ivy.Container` input:
  
      >>> x = ivy.Container(a=ivy.array([4]))
      >>> y = ivy.Container(a=ivy.array([0.1, 0.2, 0.1, 0.1, 0.5]))
      >>> print(ivy.sparse_cross_entropy(x, y))
      {
          a: ivy.array([0.693])
      }
  
      With a mix of :class:`ivy.Array` and :class:`ivy.NativeArray` inputs:
  
      >>> x = ivy.array([0])
      >>> y = ivy.native_array([0.1, 0.2, 0.6, 0.1])
      >>> print(ivy.sparse_cross_entropy(x,y))
      ivy.array([2.3])
  
      With a mix of :class:`ivy.Array` and :class:`ivy.Container` inputs:
  
      >>> x = ivy.array([0])
      >>> y = ivy.Container(a=ivy.array([0.1, 0.2, 0.6, 0.1]))
      >>> print(ivy.sparse_cross_entropy(x,y))
      {
          a: ivy.array([2.3])
      }
  
      Instance Method Examples
      ~~~~~~~~~~~~~~~~~~~~~~~~
      With :class:`ivy.Array` input:
  
      >>> x = ivy.array([2])
      >>> y = ivy.array([0.1, 0.1, 0.7, 0.1])
      >>> print(x.sparse_cross_entropy(y))
      ivy.array([0.357])
  
      With :class:`ivy.Container` input:
  
      >>> x = ivy.Container(a=ivy.array([2]))
      >>> y = ivy.Container(a=ivy.array([0.1, 0.1, 0.7, 0.1]))
      >>> print(x.sparse_cross_entropy(y))
      {
          a: ivy.array([0.357])
      }
      """
      ivy.utils.assertions.check_elem_in_list(
          reduction, ["none", "sum", "mean"]
      )
      true = ivy.one_hot(true, pred.shape[axis])
      return ivy.cross_entropy(
          true,
          pred,
          axis=axis,
          epsilon=epsilon,
          reduction=reduction,
          out=out,
      )
  
file_path: ivy/ivy/functional/ivy/losses.py
imports: import ivy
  from typing import Optional, Union
  from ivy.func_wrapper import handle_array_function, handle_nestable, handle_array_like_without_promotion, inputs_to_ivy_arrays
  from ivy.utils.exceptions import handle_exceptions
label_desc: Use image node_id 4 for calling a global function with example usage: sparse_cross_entropy() and returns: ivy