Skip to content

Conversation

@GuoxiaWang
Copy link
Contributor

PR types

Bug fixes

PR changes

APIs

Describe

support bool dtype for paddle.sum

Test Code

import numpy as np
import torch
import paddle

for dtype in ['bool', 'float32', 'float64', 'int32', 'int64']:
    print('='*20)
    np_arr = np.ones((12, 3), dtype=dtype)
    print('input:')
    print(np_arr, np_arr.dtype)

    print('sum of numpy:')
    np_sum = np_arr.sum(0)
    print(np_sum, np_sum.dtype)

    pd_arr = paddle.to_tensor(np_arr)
    print('sum of paddle:')
    pd_sum = pd_arr.sum(0)
    print(pd_sum, pd_sum.dtype)

    pt_arr = torch.tensor(np_arr)
    print('sum of torch:')
    pt_sum = pt_arr.sum(0)
    print(pt_sum, pt_sum.dtype)

Outputs

====================
input:
[[ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]] bool
sum of numpy:
[12 12 12] int64
sum of paddle:
Tensor(shape=[3], dtype=int64, place=CUDAPlace(0), stop_gradient=True,
       [12, 12, 12]) paddle.int64
sum of torch:
tensor([12, 12, 12]) torch.int64
====================
input:
[[1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]] float32
sum of numpy:
[12. 12. 12.] float32
sum of paddle:
Tensor(shape=[3], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
       [12., 12., 12.]) paddle.float32
sum of torch:
tensor([12., 12., 12.]) torch.float32
====================
input:
[[1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]] float64
sum of numpy:
[12. 12. 12.] float64
sum of paddle:
Tensor(shape=[3], dtype=float64, place=CUDAPlace(0), stop_gradient=True,
       [12., 12., 12.]) paddle.float64
sum of torch:
tensor([12., 12., 12.], dtype=torch.float64) torch.float64
====================
input:
[[1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]] int32
sum of numpy:
[12 12 12] int64
sum of paddle:
Tensor(shape=[3], dtype=int64, place=CUDAPlace(0), stop_gradient=True,
       [12, 12, 12]) paddle.int64
sum of torch:
tensor([12, 12, 12]) torch.int64
====================
input:
[[1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]] int64
sum of numpy:
[12 12 12] int64
sum of paddle:
Tensor(shape=[3], dtype=int64, place=CUDAPlace(0), stop_gradient=True,
       [12, 12, 12]) paddle.int64
sum of torch:
tensor([12, 12, 12]) torch.int64

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@GuoxiaWang GuoxiaWang changed the title Feature sum support bool dtype for paddle.sum Jul 21, 2021
@GuoxiaWang GuoxiaWang changed the title support bool dtype for paddle.sum fix output dtype for paddle.sum Jul 30, 2021
Copy link

@sandyhouse sandyhouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for core.ops

@sandyhouse sandyhouse merged commit ff062a4 into PaddlePaddle:develop Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants