parameters: (x, axis=None, dtype=None, keepdims=False, initial=None)
return_statement: return res.astype(dtype)
docstring: Return sum of array elements over a given axis.
  
      Note:
          Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`, and
          `extobj` are not supported.
  
      Args:
          x (Union[int, float, bool, list, tuple, Tensor]): Elements to sum.
          axis (Union[None, int, tuple(int)]): Axis or axes along which a sum is performed. Default: None.
              If None, sum all of the elements of the input array.
              If axis is negative it counts from the last to the first axis.
              If axis is a tuple of ints, a sum is performed on all of the axes specified in the tuple
              instead of a single axis or all the axes as before.
          dtype (:class:`mindspore.dtype`, optional): defaults to None. Overrides the dtype of the
              output Tensor.
          keepdims (bool): If this is set to True, the axes which are reduced are left in the result as
              dimensions with size one. With this option, the result will broadcast correctly against the input array.
              If the default value is passed, then keepdims will not be passed through to the sum method of
              sub-classes of ndarray, however any non-default value will be. If the sub-class method does not
              implement keepdims any exceptions will be raised.
          initial (scalar): Starting value for the sum.
  
      Returns:
          Tensor. A tensor with the same shape as input, with the specified axis removed.
          If input tensor is a 0-d array, or if axis is None, a scalar is returned.
  
      Raises:
          TypeError: If input is not array_like or `axis` is not int or tuple of ints or
              `keepdims` is not integer or `initial` is not scalar.
          ValueError: If any axis is out of range or duplicate axes exist.
  
      Supported Platforms:
          ``Ascend`` ``GPU`` ``CPU``
  
      Examples:
          >>> import mindspore.numpy as np
          >>> input_x = np.array([-1, 0, 1]).astype('int32')
          >>> print(input_x.sum())
          0
          >>> input_x = np.arange(10).reshape(2, 5).astype('float32')
          >>> print(input_x.sum(axis=1))
          [10. 35.]
docstring_summary: Return sum of array elements over a given axis.
docstring_tokens: Return sum of array elements over a given axis .
function: def sum(x, axis=None, dtype=None, keepdims=False, initial=None): # pylint: disable=redefined-builtin
      """
      Return sum of array elements over a given axis.
  
      Note:
          Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`, and
          `extobj` are not supported.
  
      Args:
          x (Union[int, float, bool, list, tuple, Tensor]): Elements to sum.
          axis (Union[None, int, tuple(int)]): Axis or axes along which a sum is performed. Default: None.
              If None, sum all of the elements of the input array.
              If axis is negative it counts from the last to the first axis.
              If axis is a tuple of ints, a sum is performed on all of the axes specified in the tuple
              instead of a single axis or all the axes as before.
          dtype (:class:`mindspore.dtype`, optional): defaults to None. Overrides the dtype of the
              output Tensor.
          keepdims (bool): If this is set to True, the axes which are reduced are left in the result as
              dimensions with size one. With this option, the result will broadcast correctly against the input array.
              If the default value is passed, then keepdims will not be passed through to the sum method of
              sub-classes of ndarray, however any non-default value will be. If the sub-class method does not
              implement keepdims any exceptions will be raised.
          initial (scalar): Starting value for the sum.
  
      Returns:
          Tensor. A tensor with the same shape as input, with the specified axis removed.
          If input tensor is a 0-d array, or if axis is None, a scalar is returned.
  
      Raises:
          TypeError: If input is not array_like or `axis` is not int or tuple of ints or
              `keepdims` is not integer or `initial` is not scalar.
          ValueError: If any axis is out of range or duplicate axes exist.
  
      Supported Platforms:
          ``Ascend`` ``GPU`` ``CPU``
  
      Examples:
          >>> import mindspore.numpy as np
          >>> input_x = np.array([-1, 0, 1]).astype('int32')
          >>> print(input_x.sum())
          0
          >>> input_x = np.arange(10).reshape(2, 5).astype('float32')
          >>> print(input_x.sum(axis=1))
          [10. 35.]
      """
      input_x = x.astype(mstype.int32) if x.dtype == mstype.bool_ else x
      dtype = input_x.dtype if dtype is None else dtype
      if not isinstance(keepdims, int):
          const_utils.raise_type_error("integer argument expected")
      if initial is not None and not isinstance(initial, (int, float, bool)):
          const_utils.raise_type_error("initial argument should be a scalar.")
      if axis is None:
          axis = ()
      else:
          axis = check_and_canonicalize_axes(axis, x.ndim)
  
      if not check_type_support(input_x.dtype, 'GPU', (mstype.float64, mstype.float32, mstype.float16)):
          input_x = input_x.astype(mstype.float32)
      if 0 in x.shape:
          x = const_utils.make_tensor([0], x.dtype)
      if keepdims:
          res = _reduce_sum_keepdims(input_x, axis)
      else:
          res = _reduce_sum_default(input_x, axis)
      if initial is not None:
          res += initial
      return res.astype(dtype)
function_tokens: def sum ( x , axis = None , dtype = None , keepdims = False , initial = None ) : # pylint: disable=redefined-builtin input_x = x . astype ( mstype . int32 ) if x . dtype == mstype . bool_ else x dtype = input_x . dtype if dtype is None else dtype if not isinstance ( keepdims , int ) : const_utils . raise_type_error ( "integer argument expected" ) if initial is not None and not isinstance ( initial , ( int , float , bool ) ) : const_utils . raise_type_error ( "initial argument should be a scalar." ) if axis is None : axis = ( ) else : axis = check_and_canonicalize_axes ( axis , x . ndim ) if not check_type_support ( input_x . dtype , 'GPU' , ( mstype . float64 , mstype . float32 , mstype . float16 ) ) : input_x = input_x . astype ( mstype . float32 ) if 0 in x . shape : x = const_utils . make_tensor ( [ 0 ] , x . dtype ) if keepdims : res = _reduce_sum_keepdims ( input_x , axis ) else : res = _reduce_sum_default ( input_x , axis ) if initial is not None : res += initial return res . astype ( dtype )