-
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
【Hackathon 5th No.14】Add combinations API to Paddle #57792
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
有中文RFC文档吗 |
|
Sorry to inform you that a02bc01's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
codestyle-check流水线失败。安装pre-commit后,重新提交。 |
def modify_setting(self): | ||
self.dtype_np = 'int64' | ||
self.x_shape = [10] | ||
self.r = 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.
缺少r>x_shape情况的单测
class TestIndexFillAPI2(TestCombinationsAPIBase): | ||
def modify_setting(self): | ||
self.dtype_np = 'int64' | ||
self.x_shape = [10] |
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.
缺少了输入为empty情况下的单测
增加了输入shape为[0]的测试同时r>x_shape的测试 |
python/paddle/tensor/math.py
Outdated
|
||
""" | ||
if len(x.shape) != 1: | ||
raise TypeError(f"Expect a 1-D vector, but got x shape {x.shape}") | ||
if not isinstance(r, int) or r < 0: | ||
raise ValueError(f"Expect a non-negative int, but got r={r}") | ||
|
||
if r == 0: | ||
if r == 0 or r > x.shape[0]: | ||
return paddle.empty([0], 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.
empty的形状设计好像有些问题,pytorch在不同情况下的empty的size是不同的。相关设计后续补充到rfc文档中。
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.
我之前错误理解empty表示输入形状为空的tensor了,已添加empty相关测试
Sorry to inform you that 7b45322's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
expected = paddle.empty([0, 4]) | ||
np.testing.assert_allclose(c, expected) | ||
|
||
# test empty imput |
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.
typo error
paddle.device.set_device(place) | ||
a = paddle.to_tensor([1, 2, 3]) | ||
c = paddle.combinations(a, r=4) | ||
expected = paddle.empty([0, 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.
一般是不推荐人为给定期望输入用来测试的,是否有其他类似库函数用于测试。
a = paddle.empty([0]) | ||
c1 = paddle.combinations(a) | ||
c2 = paddle.combinations(a, with_replacement=True) | ||
expected = paddle.empty([0, 2]) |
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.更改了测试的输入和输出 |
确认下coverage流水线没有通过的原因 |
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
""" | ||
Compute combinations of length r of the given tensor. The behavior is similar to python’s itertools.combinations | ||
when with_replacement is set to False, and itertools.combinations_with_replacement when with_replacement is set to True. | ||
Args: |
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.
Args: | |
Args: |
python/paddle/tensor/math.py
Outdated
Returns: | ||
out (Tensor): tensor concatenated by combinations, same dtype with x |
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.
Returns: | |
out (Tensor): tensor concatenated by combinations, same dtype with x | |
Returns: | |
out (Tensor). Tensor concatenated by combinations, same dtype with x. |
>>> import paddle | ||
>>> x = paddle.to_tensor([1, 2, 3], dtype='int32') | ||
>>> res = paddle.combinations(x) | ||
>>> print(res) | ||
Tensor(shape=[3, 2], dtype=int32, place=Place(gpu:0), stop_gradient=True, | ||
[[1, 2], | ||
[1, 3], | ||
[2, 3]]) |
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.
>>> import paddle | |
>>> x = paddle.to_tensor([1, 2, 3], dtype='int32') | |
>>> res = paddle.combinations(x) | |
>>> print(res) | |
Tensor(shape=[3, 2], dtype=int32, place=Place(gpu:0), stop_gradient=True, | |
[[1, 2], | |
[1, 3], | |
[2, 3]]) | |
>>> import paddle | |
>>> x = paddle.to_tensor([1, 2, 3], dtype='int32') | |
>>> res = paddle.combinations(x) | |
>>> print(res) | |
Tensor(shape=[3, 2], dtype=int32, place=Place(gpu:0), stop_gradient=True, | |
[[1, 2], | |
[1, 3], | |
[2, 3]]) |
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.
严格按照模板(包括空行)
Sorry to inform you that d96cb13's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
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 for docs
@Patrick-Star125 请处理下冲突 |
Done |
PR types
New features
PR changes
APIs
Description
Add combinations API to Paddle
Link
Rfc PR: PaddlePaddle/community#654
docs PR: PaddlePaddle/docs#6287
待完成