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

update torch.quantile, torch.nanquantile and corresponding tensor methods #383

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -2466,10 +2466,7 @@
],
"kwargs_change": {
"dim": "axis"
},
"unsupport_args": [
"interpolation"
]
}
},
"torch.Tensor.nansum": {
"Matcher": "GenericMatcher",
Expand Down Expand Up @@ -2785,7 +2782,9 @@
"args_list": [
"q",
"dim",
"keepdim"
"keepdim",
"*",
"interpolation"
],
"kwargs_change": {
"dim": "axis"
Expand Down Expand Up @@ -8747,10 +8746,7 @@
"kwargs_change": {
"input": "x",
"dim": "axis"
},
"unsupport_args": [
"interpolation "
]
}
},
"torch.nansum": {
"Matcher": "GenericMatcher",
Expand Down Expand Up @@ -13500,10 +13496,7 @@
"kwargs_change": {
"input": "x",
"dim": "axis"
},
"unsupport_args": [
"interpolation "
]
}
},
"torch.rad2deg": {
"Matcher": "GenericMatcher",
Expand Down
17 changes: 15 additions & 2 deletions tests/test_Tensor_nanquantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ def test_case_7():
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="Paddle not support this parameter",
)


# generated by validate_unittest autofix, based on test_case_7
def test_case_8():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[0]], dtype=torch.float64)
result = x.nanquantile(interpolation='higher', keepdim=True, dim=1, q=0.3)
Copy link
Collaborator

Choose a reason for hiding this comment

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

可以针对 interpolation 多测几个不同的值,验收下interpolation的不同取值是不是都完全写对了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

"""
)
obj.run(
pytorch_code,
["result"],
)
7 changes: 3 additions & 4 deletions tests/test_Tensor_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,12 @@ def test_case_10():
obj.run(pytorch_code, ["result"])


# torch.Tensor.quantile not support interpolation
def _test_case_11():
def test_case_11():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[ 0.0795, -1.2117, 0.9765], [ 1.1707, 0.6706, 0.4884]],dtype=torch.float64)
result=x.quantile(q=0.6, dim=1, keepdim=False, interpolation='linear')
x = torch.tensor([[ 0.0795, -1.2117, 0.9765], [ 1.1707, 0.6706, 0.4884]], dtype=torch.float64)
result = x.quantile(q=0.6, dim=1, keepdim=False, interpolation='linear')
"""
)
obj.run(pytorch_code, ["result"])
21 changes: 15 additions & 6 deletions tests/test_nanquantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,21 @@ def test_case_9():
"""
import torch
x = torch.tensor([[0]], dtype=torch.float64)
result = torch.nanquantile(x=x, q=0.3, dim=1, keepdim=True, interpolation='higher')
out = torch.tensor([[1]], dtype=torch.float64)
result = torch.nanquantile(input=x, q=0.3, dim=1, keepdim=True, interpolation='higher', out=out)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="Paddle not support this parameter",
obj.run(pytorch_code, ["result", "out"])


# generated by validate_unittest autofix, based on test_case_9
def test_case_10():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[0]], dtype=torch.float64)
out = torch.tensor([[1]], dtype=torch.float64)
result = torch.nanquantile(out=out, interpolation='higher', keepdim=True, dim=1, q=0.3, input=x)
"""
)
obj.run(pytorch_code, ["result", "out"])
39 changes: 35 additions & 4 deletions tests/test_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,43 @@ def test_case_7():
"""
import torch
x = torch.tensor([[ 0.0795, -1.2117, 0.9765], [ 1.1707, 0.6706, 0.4884]], dtype=torch.float64)
result = torch.quantile(x=x, q=0.3, dim=1, keepdim=True, interpolation='higher')
out = torch.tensor([], dtype=torch.float64)
result = torch.quantile(input=x, q=0.3, dim=1, keepdim=True, interpolation='higher', out=out)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="Paddle not support this parameter",
["result", "out"],
)


# generated by validate_unittest autofix, based on test_case_7
def test_case_8():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[ 0.0795, -1.2117, 0.9765], [ 1.1707, 0.6706, 0.4884]], dtype=torch.float64)
out = torch.tensor([], dtype=torch.float64)
result = torch.quantile(x, 0.3, 1, True)
"""
)
obj.run(
pytorch_code,
["result", "out"],
)


# generated by validate_unittest autofix, based on test_case_7
def test_case_9():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[ 0.0795, -1.2117, 0.9765], [ 1.1707, 0.6706, 0.4884]], dtype=torch.float64)
out = torch.tensor([], dtype=torch.float64)
result = torch.quantile(out=out, interpolation='higher', keepdim=True, dim=1, q=0.3, input=x)
"""
)
obj.run(
pytorch_code,
["result", "out"],
)