Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add paddle.tensor.math.prod #26351

Merged
merged 5 commits into from
Aug 20, 2020
Merged

Add paddle.tensor.math.prod #26351

merged 5 commits into from
Aug 20, 2020

Conversation

gfwm2013
Copy link
Contributor

@gfwm2013 gfwm2013 commented Aug 17, 2020

PR types

New features

PR changes

APIs

Describe

Add new API : paddle.prod
180 76 141 178_documentation_docs_en_api_tensor_math_prod html

@paddle-bot-old
Copy link

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

@paddle-bot-old
Copy link

paddle-bot-old bot commented Aug 17, 2020

✅ This PR's description meets the template requirements!
Please wait for other CI results.

Compute the product of tensor elements over the given axis.

Args:
x(Tensor): Input of prod operator. The data type is float32, float64, int32, int64.
Copy link
Member

Choose a reason for hiding this comment

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

The data type is float32, float64, int32, or int64

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

if not fluid.core.is_compiled_with_cuda():
return

paddle.disable_static(place=paddle.fluid.CUDAPlace(4))
Copy link
Member

Choose a reason for hiding this comment

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

Why is it 4? Please set to 0 to avoid some CI machines only have 2 GPU cards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

result4 = paddle.prod(input, axis=1, dtype='int64')
result5 = paddle.prod(input, axis=1, keepdim=True, dtype='int64')

place = fluid.CUDAPlace(4) if use_gpu else fluid.CPUPlace()
Copy link
Member

Choose a reason for hiding this comment

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

Why is it 4? Please set to 0 to avoid some CI machines only have 2 GPU cards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

self.assertTrue(np.allclose(static_result[3], expected_result))
expected_result = np.prod(self.input, axis=1, dtype=np.int64)
self.assertTrue(np.allclose(static_result[4], expected_result))
expected_result = np.prod(
Copy link
Contributor

Choose a reason for hiding this comment

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

axis支持负数吗? 如果支持可以添加单测

Copy link
Contributor Author

@gfwm2013 gfwm2013 Aug 18, 2020

Choose a reason for hiding this comment

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

Thanks, done.

result5 = paddle.prod(input, axis=1, keepdim=True, dtype='int64')

place = fluid.CUDAPlace(4) if use_gpu else fluid.CPUPlace()
exe = fluid.Executor(place)
Copy link
Contributor

Choose a reason for hiding this comment

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

paddle.static.Executor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

self.run_imperative()
paddle.enable_static()

with fluid.program_guard(fluid.Program()):
Copy link
Contributor

Choose a reason for hiding this comment

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

尽量减少fluid

Copy link
Contributor Author

@gfwm2013 gfwm2013 Aug 18, 2020

Choose a reason for hiding this comment

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

Thanks, done.

@gfwm2013 gfwm2013 changed the title Add paddle.or.math.prod Add paddle.tensor.math.prod Aug 18, 2020
Copy link
Member

@zhhsplendid zhhsplendid 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
Member

@zhhsplendid zhhsplendid left a comment

Choose a reason for hiding this comment

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

LGTM

@gfwm2013 gfwm2013 merged commit bb7fd09 into PaddlePaddle:develop Aug 20, 2020
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.

None yet

3 participants