-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add paddle.tensor.math.prod #26351
Conversation
test=develop
Thanks for your contribution! |
✅ This PR's description meets the template requirements! |
test=develop
test=develop
python/paddle/tensor/math.py
Outdated
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
axis支持负数吗? 如果支持可以添加单测
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paddle.static.Executor
There was a problem hiding this comment.
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()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
尽量减少fluid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done.
test=develop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
New features
PR changes
APIs
Describe
Add new API : paddle.prod