code: def trace(x: Array, /, *, offset: int = 0) -> Array:
      """
      Array API compatible wrapper for :py:func:`np.trace <numpy.trace>`.
  
      See its docstring for more information.
      """
      if x.dtype not in _numeric_dtypes:
          raise TypeError("Only numeric dtypes are allowed in trace")
      # Note: trace always operates on the last two axes, whereas np.trace
      # operates on the first two axes by default
      return Array._new(
          np.asarray(
              np.trace(x._array, offset=offset, axis1=-2, axis2=-1)
          )
      )
  
imports: from __future__ import annotations
  import functools
  from ._dtypes import _floating_dtypes, _numeric_dtypes
  from ._manipulation_functions import reshape
  from ._array_object import Array
  from .._core.internal import _normalize_axis_indices
  from typing import TYPE_CHECKING
  from typing import NamedTuple
  import cupy
label_desc: Use image node_id 22 for calling a global function with example usage: trace() and returns: Array