parameters: (self, offset=0, axis1=0, axis2=1, dtype=None)
return_statement: return res.astype(dtype)
docstring: Return the sum along diagonals of the tensor.
  
          Args:
              offset (int, optional): Offset of the diagonal from the main diagonal.
                  Can be positive or negative. Defaults to main diagonal.
              axis1 (int, optional): Axis to be used as the first axis of the 2-D
                  sub-arrays from which the diagonals should be taken. Defaults to
                  first axis (0).
              axis2 (int, optional): Axis to be used as the second axis of the 2-D
                  sub-arrays from which the diagonals should be taken. Defaults to
                  second axis.
              dtype (:class:`mindspore.dtype`, optional): defaults to None. Overrides the dtype of the
                  output Tensor.
  
          Returns:
              Tensor, the sum along diagonals.
  
          Raises:
              ValueError: If the input tensor has less than two dimensions.
  
          Supported Platforms:
              ``Ascend`` ``GPU`` ``CPU``
  
          See also:
              :func:`mindspore.Tensor.diagonal`: Return specified diagonals.
  
          Examples:
              >>> import numpy as np
              >>> from mindspore import Tensor
              >>> x = Tensor(np.eye(3, dtype=np.float32))
              >>> print(x.trace())
              3.0
docstring_summary: Return the sum along diagonals of the tensor.
docstring_tokens: Return the sum along diagonals of the tensor .
function: def trace(self, offset=0, axis1=0, axis2=1, dtype=None):
          """
          Return the sum along diagonals of the tensor.
  
          Args:
              offset (int, optional): Offset of the diagonal from the main diagonal.
                  Can be positive or negative. Defaults to main diagonal.
              axis1 (int, optional): Axis to be used as the first axis of the 2-D
                  sub-arrays from which the diagonals should be taken. Defaults to
                  first axis (0).
              axis2 (int, optional): Axis to be used as the second axis of the 2-D
                  sub-arrays from which the diagonals should be taken. Defaults to
                  second axis.
              dtype (:class:`mindspore.dtype`, optional): defaults to None. Overrides the dtype of the
                  output Tensor.
  
          Returns:
              Tensor, the sum along diagonals.
  
          Raises:
              ValueError: If the input tensor has less than two dimensions.
  
          Supported Platforms:
              ``Ascend`` ``GPU`` ``CPU``
  
          See also:
              :func:`mindspore.Tensor.diagonal`: Return specified diagonals.
  
          Examples:
              >>> import numpy as np
              >>> from mindspore import Tensor
              >>> x = Tensor(np.eye(3, dtype=np.float32))
              >>> print(x.trace())
              3.0
          """
          d = self.diagonal(offset, axis1=axis1, axis2=axis2)
          shape = d.shape
          if dtype is None:
              dtype = d.dtype
          if shape[-1] == 0:
              return tensor_operator_registry.get('fill')(dtype, shape[:-1], 0)
          res = tensor_operator_registry.get('reduce_sum')(d.astype(mstype.float32), -1)
          return res.astype(dtype)
function_tokens: def trace ( self , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None ) : d = self . diagonal ( offset , axis1 = axis1 , axis2 = axis2 ) shape = d . shape if dtype is None : dtype = d . dtype if shape [ - 1 ] == 0 : return tensor_operator_registry . get ( 'fill' ) ( dtype , shape [ : - 1 ] , 0 ) res = tensor_operator_registry . get ( 'reduce_sum' ) ( d . astype ( mstype . float32 ) , - 1 ) return res . astype ( dtype )