code: def trace(
      x: torch.Tensor,
      /,
      *,
      offset: int = 0,
      axis1: int = 0,
      axis2: int = 1,
      out: Optional[torch.Tensor] = None,
  ) -> torch.Tensor:
      if len(x) == 0:
          return ivy.array([])
      ret = torch.diagonal(x, offset=offset, dim1=axis1, dim2=axis2)
      ret = torch.sum(ret, dim=-1)
      return ret
  
imports: import torch
  from typing import Union, Optional, Tuple, Literal, List, NamedTuple, Sequence
  from collections import namedtuple
  import ivy
  from ivy import inf
  from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes
  from .None import backend_version
  from .elementwise import _cast_for_unary_op
label_desc: Use image node_id 24 for calling a global function with example usage: trace() and returns: ret, ivy