-
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
【Paddle Tensor 第二期】使paddle.all支持0-size输入 #70228
base: develop
Are you sure you want to change the base?
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
const int64_t* dims_data = out->dims().Get(); | ||
int num_dims = out->dims().size(); | ||
std::vector<int64_t> vec_dims(dims_data, dims_data + num_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.
out_dims_vec = common::vectorize(out->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.
已更改
} | ||
|
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.
删除
test/legacy_test/test_reduce_op.py
Outdated
def calculate_expected_result(self, axis, keepdim): | ||
if axis is None: | ||
expected_result = np.array(True) | ||
elif isinstance(axis, int): | ||
if keepdim: | ||
expected_shape = list(self.shape) | ||
expected_shape[axis] = 1 | ||
expected_result = np.ones(expected_shape, dtype=bool) | ||
else: | ||
expected_shape = list(self.shape) | ||
del expected_shape[axis] | ||
expected_result = np.ones(expected_shape, dtype=bool) | ||
# axis is tuple | ||
else: | ||
if keepdim: | ||
expected_shape = list(self.shape) | ||
for i in axis: | ||
expected_shape[i] = 1 | ||
expected_result = np.ones(expected_shape, dtype=bool) | ||
else: | ||
expected_shape = list(self.shape) | ||
for i in sorted(axis, reverse=True): | ||
del expected_shape[i] | ||
expected_result = np.ones(expected_shape, dtype=bool) | ||
|
||
return expected_result |
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.
这里是不是能直接用np.all代替?
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.
确实,可以直接用np.all
test/legacy_test/test_reduce_op.py
Outdated
|
||
x = paddle.to_tensor(x_np) | ||
dygraph_result = paddle.all(x, axis=axis, keepdim=keepdim).numpy() | ||
expected_result = self.calculate_expected_result(axis, keepdim) |
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.
这里直接用np.all就行了吧,不用自己手写一个
PR Category
User ExperiencePR Types
ImprovementsDescription
初始paddle.all输入0-size的情况:
修复完成后,再次运行同一个代码:
复现代码