@@ -656,7 +656,7 @@ def sum(x, axis=None, dtype=None, keepdim=False, name=None):
656656 Computes the sum of tensor elements over the given dimension.
657657
658658 Args:
659- x (Tensor): An N-D Tensor, the data type is float32, float64, int32 or int64.
659+ x (Tensor): An N-D Tensor, the data type is bool, float16, float32, float64, int32 or int64.
660660 axis (int|list|tuple, optional): The dimensions along which the sum is performed. If
661661 :attr:`None`, sum all elements of :attr:`x` and return a
662662 Tensor with a single element, otherwise must be in the
@@ -673,11 +673,10 @@ def sum(x, axis=None, dtype=None, keepdim=False, name=None):
673673
674674 Returns:
675675 Tensor: Results of summation operation on the specified axis of input Tensor `x`,
676- it's data type is the same as `x`.
676+ if `x.dtype='bool'`, `x.dtype='int32'`, it's data type is `'int64'`,
677+ otherwise it's data type is the same as `x`.
677678
678679 Raises:
679- ValueError: If the data type of `x` is float64, :attr:`dtype` can not be float32 or int32.
680- ValueError: If the data type of `x` is int64, :attr:`dtype` can not be int32.
681680 TypeError: The type of :attr:`axis` must be int, list or tuple.
682681
683682 Examples:
@@ -704,6 +703,16 @@ def sum(x, axis=None, dtype=None, keepdim=False, name=None):
704703 [[5, 6], [7, 8]]])
705704 out5 = paddle.sum(y, axis=[1, 2]) # [10, 26]
706705 out6 = paddle.sum(y, axis=[0, 1]) # [16, 20]
706+
707+ # x is a Tensor with following elements:
708+ # [[True, True, True, True]
709+ # [False, False, False, False]]
710+ # Each example is followed by the corresponding output tensor.
711+ x = paddle.to_tensor([[True, True, True, True],
712+ [False, False, False, False]])
713+ out7 = paddle.sum(x) # [4]
714+ out8 = paddle.sum(x, axis=0) # [1, 1, 1, 1]
715+ out9 = paddle.sum(x, axis=1) # [4, 0]
707716 """
708717 if axis is not None and not isinstance (axis , (list , tuple )):
709718 axis = [axis ]
0 commit comments