CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
【BUPT】[Paddle Tensor 第二期 API 鲁棒性增强] paddle.atan2 API 鲁棒性增强 #70253
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
Conversation
…asting; Revised previous test code for paddle.meshgrid based on feedback from the last PR review
你的PR提交成功,感谢你对开源项目的贡献! |
paddle/phi/infermeta/binary.cc
Outdated
auto dim_x = x.dims(); | ||
auto dim_y = y.dims(); |
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.
dim_ --> _dims
paddle/phi/infermeta/binary.cc
Outdated
if (dim_x == dim_y) { | ||
out->share_meta(x); | ||
} else { | ||
int max_dim = std::max(dim_x.size(), dim_y.size()); |
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.
max_ndim
test/legacy_test/test_atan2_op.py
Outdated
def test_api_with_dygraph_empty_tensor_input(self): | ||
self._test_with_shapes([(100,), (100, 100)]) | ||
self._test_with_shapes([(), (5, 17, 6)]) | ||
self._test_with_shapes([(111, 222, 333), (222, 333)]) | ||
|
||
def _test_api_with_static_empty_tensor_input(self, place): | ||
self._test_with_shapes([(100,), (100, 100)], place) | ||
self._test_with_shapes([(), (5, 17, 6)], place) | ||
self._test_with_shapes([(111, 222, 333), (222, 333)], place) | ||
|
||
def test_api_with_static_empty_tensor_input(self): | ||
for place in self._get_places(): | ||
self._test_api_with_static_empty_tensor_input(place) | ||
|
||
|
||
class TestAtan2EmptyTensorInput(TestAtan2Broadcasting): | ||
def test_api_with_dygraph_empty_tensor_input(self): | ||
self._test_with_shapes([(), (0,)]) | ||
self._test_with_shapes([(0,), (0, 0)]) | ||
self._test_with_shapes([(0, 0, 0), (0,)]) | ||
|
||
def _test_api_with_static_empty_tensor_input(self, place): | ||
self._test_with_shapes([(), (0,)], place) | ||
self._test_with_shapes([(0,), (0, 0)], place) | ||
self._test_with_shapes([(0, 0, 0), (0,)], 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.
单测再丰富一些,比如([5, 17, 6], [5, 0, 17, 6])之类的
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.
好的
…ity based on feedback from the PR review
paddle/phi/infermeta/binary.cc
Outdated
if (x.dtype() == DataType::INT32 || x.dtype() == DataType::INT64 || | ||
y.dtype() == DataType::INT32 || y.dtype() == DataType::INT64) { | ||
out->set_dtype(DataType::FLOAT64); | ||
} else { | ||
out->set_dtype(x.dtype()); |
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.
这个dtype不要修改,如果输入的x和y都是int,那么输出的dtype也应该是float
if (x.numel() == 0 || y.numel() == 0) { | ||
ctx.template Alloc<typename Atan2Out<T>::type>(out); | ||
return; | ||
} |
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.
这里要计算出out的真实形状,然后进行Resize一下,否则仅靠infermeta可能形状会有-1。
paddle/phi/infermeta/binary.cc
Outdated
if (x.numel() == 0 || y.numel() == 0) { | ||
std::replace(out_dims_array.begin(), out_dims_array.end(), -1, 0); | ||
} |
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.
这里为什么要将-1替换成0呢?感觉不需要吧?
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.
因为 funcs::GetBroadcastDimsArrays
对 0-size tensor 的处理就是返回 -1,下面是 funcs::GetBroadcastDimsArrays
的相关代码:
if ((x_dims_array[i] > 1 || y_dims_array[i] > 1) ||
(x_dims_array[i] == 1 && y_dims_array[i] == 1)) {
out_dims_array[i] = (std::max)(x_dims_array[i], y_dims_array[i]);
} else {
out_dims_array[i] = -1;
}
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.
因为
funcs::GetBroadcastDimsArrays
对 0-size tensor 的处理就是返回 -1,下面是funcs::GetBroadcastDimsArrays
的相关代码:if ((x_dims_array[i] > 1 || y_dims_array[i] > 1) || (x_dims_array[i] == 1 && y_dims_array[i] == 1)) { out_dims_array[i] = (std::max)(x_dims_array[i], y_dims_array[i]); } else { out_dims_array[i] = -1; }
- infermeta没必要替换
- kernel里-1应该替换成实际值
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.
好的
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 Category
User Experience
PR Types
Bug fixes
Description
paddle.atan2
的前向广播支持经过上述更改后,

paddle.atan2
可以通过 'array_api_tests/test_operators_and_elementwise_functions.py::test_atan2' 测试