Skip to content

Commit ce2b524

Browse files
committed
[API Compatibility] block_diag/broadcast_tensors/cartesian_prod/copysign/index_fill/cross/dist/flip/pow Edit By AI
1 parent 009444b commit ce2b524

13 files changed

Lines changed: 401 additions & 115 deletions

paconvert/api_alias_mapping.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
"torch.functional.unique": "torch.unique",
105105
"torch.half": "torch.float16",
106106
"torch.hardshrink": "torch.nn.functional.hardshrink",
107-
"torch.i0": "torch.special.i0",
108107
"torch.igamma": "torch.special.gammainc",
109108
"torch.igammac": "torch.special.gammaincc",
110109
"torch.int": "torch.int32",

paconvert/api_mapping.json

Lines changed: 11 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -784,26 +784,10 @@
784784
"Matcher": "ChangePrefixMatcher"
785785
},
786786
"torch.Tensor.copysign": {
787-
"Matcher": "Num2TensorBinaryMatcher",
788-
"paddle_api": "paddle.Tensor.copysign",
789-
"min_input_args": 1,
790-
"args_list": [
791-
"other"
792-
],
793-
"kwargs_change": {
794-
"other": "y"
795-
}
787+
"Matcher": "ChangePrefixMatcher"
796788
},
797789
"torch.Tensor.copysign_": {
798-
"Matcher": "Num2TensorBinaryMatcher",
799-
"paddle_api": "paddle.Tensor.copysign_",
800-
"min_input_args": 1,
801-
"args_list": [
802-
"other"
803-
],
804-
"kwargs_change": {
805-
"other": "y"
806-
}
790+
"Matcher": "ChangePrefixMatcher"
807791
},
808792
"torch.Tensor.corrcoef": {
809793
"Matcher": "ChangePrefixMatcher"
@@ -1267,18 +1251,7 @@
12671251
}
12681252
},
12691253
"torch.Tensor.geometric_": {
1270-
"Matcher": "GenericMatcher",
1271-
"paddle_api": "paddle.Tensor.geometric_",
1272-
"min_input_args": 1,
1273-
"args_list": [
1274-
"p",
1275-
"*",
1276-
"generator"
1277-
],
1278-
"kwargs_change": {
1279-
"p": "probs",
1280-
"generator": ""
1281-
}
1254+
"Matcher": "ChangePrefixMatcher"
12821255
},
12831256
"torch.Tensor.geqrf": {},
12841257
"torch.Tensor.ger": {
@@ -1398,15 +1371,7 @@
13981371
}
13991372
},
14001373
"torch.Tensor.hypot_": {
1401-
"Matcher": "GenericMatcher",
1402-
"paddle_api": "paddle.Tensor.hypot_",
1403-
"min_input_args": 1,
1404-
"args_list": [
1405-
"other"
1406-
],
1407-
"kwargs_change": {
1408-
"other": "y"
1409-
}
1374+
"Matcher": "ChangePrefixMatcher"
14101375
},
14111376
"torch.Tensor.i0": {
14121377
"Matcher": "ChangePrefixMatcher"
@@ -1475,30 +1440,10 @@
14751440
]
14761441
},
14771442
"torch.Tensor.index_fill": {
1478-
"Matcher": "GenericMatcher",
1479-
"paddle_api": "paddle.Tensor.index_fill",
1480-
"min_input_args": 3,
1481-
"args_list": [
1482-
"dim",
1483-
"index",
1484-
"value"
1485-
],
1486-
"kwargs_change": {
1487-
"dim": "axis"
1488-
}
1443+
"Matcher": "ChangePrefixMatcher"
14891444
},
14901445
"torch.Tensor.index_fill_": {
1491-
"Matcher": "GenericMatcher",
1492-
"paddle_api": "paddle.Tensor.index_fill_",
1493-
"min_input_args": 3,
1494-
"args_list": [
1495-
"dim",
1496-
"index",
1497-
"value"
1498-
],
1499-
"kwargs_change": {
1500-
"dim": "axis"
1501-
}
1446+
"Matcher": "ChangePrefixMatcher"
15021447
},
15031448
"torch.Tensor.index_put": {
15041449
"Matcher": "ChangePrefixMatcher"
@@ -3828,15 +3773,7 @@
38283773
"Matcher": "ChangePrefixMatcher"
38293774
},
38303775
"torch.block_diag": {
3831-
"Matcher": "SimpleScalableVarMatcher",
3832-
"paddle_api": "paddle.block_diag",
3833-
"min_input_args": 1,
3834-
"args_list": [
3835-
"*tensors"
3836-
],
3837-
"kwargs_change": {
3838-
"tensors": "inputs"
3839-
}
3776+
"Matcher": "ChangePrefixMatcher"
38403777
},
38413778
"torch.bmm": {
38423779
"Matcher": "ChangePrefixMatcher"
@@ -3845,15 +3782,7 @@
38453782
"Matcher": "ChangePrefixMatcher"
38463783
},
38473784
"torch.broadcast_tensors": {
3848-
"Matcher": "ScalableVarMatcher",
3849-
"paddle_api": "paddle.broadcast_tensors",
3850-
"min_input_args": 1,
3851-
"args_list": [
3852-
"*tensors"
3853-
],
3854-
"kwargs_change": {
3855-
"tensors": "input"
3856-
}
3785+
"Matcher": "ChangePrefixMatcher"
38573786
},
38583787
"torch.broadcast_to": {
38593788
"Matcher": "ChangePrefixMatcher"
@@ -3869,15 +3798,7 @@
38693798
]
38703799
},
38713800
"torch.cartesian_prod": {
3872-
"Matcher": "SimpleScalableVarMatcher",
3873-
"paddle_api": "paddle.cartesian_prod",
3874-
"min_input_args": 1,
3875-
"args_list": [
3876-
"*tensors"
3877-
],
3878-
"kwargs_change": {
3879-
"tensors": "x"
3880-
}
3801+
"Matcher": "ChangePrefixMatcher"
38813802
},
38823803
"torch.cat": {
38833804
"Matcher": "ChangePrefixMatcher"
@@ -4063,19 +3984,7 @@
40633984
"Matcher": "ChangePrefixMatcher"
40643985
},
40653986
"torch.copysign": {
4066-
"Matcher": "GenericMatcher",
4067-
"paddle_api": "paddle.copysign",
4068-
"min_input_args": 2,
4069-
"args_list": [
4070-
"input",
4071-
"other",
4072-
"*",
4073-
"out"
4074-
],
4075-
"kwargs_change": {
4076-
"input": "x",
4077-
"other": "y"
4078-
}
3987+
"Matcher": "ChangePrefixMatcher"
40793988
},
40803989
"torch.corrcoef": {
40813990
"Matcher": "GenericMatcher",
@@ -6222,19 +6131,7 @@
62226131
]
62236132
},
62246133
"torch.index_fill": {
6225-
"Matcher": "GenericMatcher",
6226-
"paddle_api": "paddle.index_fill",
6227-
"min_input_args": 4,
6228-
"args_list": [
6229-
"input",
6230-
"dim",
6231-
"index",
6232-
"value"
6233-
],
6234-
"kwargs_change": {
6235-
"input": "x",
6236-
"dim": "axis"
6237-
}
6134+
"Matcher": "ChangePrefixMatcher"
62386135
},
62396136
"torch.index_put": {
62406137
"Matcher": "ChangePrefixMatcher"

tests/test_Tensor_copysign.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,29 @@ def _test_case_4():
6666
"""
6767
)
6868
obj.run(pytorch_code, ["result"])
69+
70+
71+
def test_case_5():
72+
"""Test with keyword arguments"""
73+
pytorch_code = textwrap.dedent(
74+
"""
75+
import torch
76+
a = torch.tensor([1.0, -2.0, 3.0])
77+
b = torch.tensor([-1.0, 1.0, -1.0])
78+
result = a.copysign(other=b)
79+
"""
80+
)
81+
obj.run(pytorch_code, ["result"])
82+
83+
84+
def test_case_6():
85+
"""Test with expression arguments"""
86+
pytorch_code = textwrap.dedent(
87+
"""
88+
import torch
89+
a = torch.tensor([1.0, 2.0, 3.0])
90+
b = torch.tensor([-1.0, 1.0, -1.0])
91+
result = a.copysign(b * 2)
92+
"""
93+
)
94+
obj.run(pytorch_code, ["result"])

tests/test_Tensor_copysign_.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,29 @@ def _test_case_4():
6666
"""
6767
)
6868
obj.run(pytorch_code, ["result"])
69+
70+
71+
def test_case_5():
72+
"""Test with keyword arguments"""
73+
pytorch_code = textwrap.dedent(
74+
"""
75+
import torch
76+
a = torch.tensor([1.0, -2.0, 3.0])
77+
b = torch.tensor([-1.0, 1.0, -1.0])
78+
result = a.copysign_(other=b)
79+
"""
80+
)
81+
obj.run(pytorch_code, ["result", "a"])
82+
83+
84+
def test_case_6():
85+
"""Test with expression arguments"""
86+
pytorch_code = textwrap.dedent(
87+
"""
88+
import torch
89+
a = torch.tensor([1.0, 2.0, 3.0])
90+
b = torch.tensor([-1.0, 1.0, -1.0])
91+
result = a.copysign_(b * 2)
92+
"""
93+
)
94+
obj.run(pytorch_code, ["result", "a"])

tests/test_Tensor_geometric_.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,102 @@ def test_case_5():
7272
"""
7373
)
7474
obj.run(pytorch_code, ["result"], check_value=False)
75+
76+
77+
def test_case_6():
78+
"""2D tensor test"""
79+
pytorch_code = textwrap.dedent(
80+
"""
81+
import torch
82+
input = torch.tensor([[-0.6341, -1.4208], [-1.0900, 0.5826]])
83+
result = input.geometric_(0.5)
84+
"""
85+
)
86+
obj.run(pytorch_code, ["result"], check_value=False)
87+
88+
89+
def test_case_7():
90+
"""3D tensor test"""
91+
pytorch_code = textwrap.dedent(
92+
"""
93+
import torch
94+
input = torch.ones(2, 3, 4)
95+
result = input.geometric_(0.5)
96+
"""
97+
)
98+
obj.run(pytorch_code, ["result"], check_value=False)
99+
100+
101+
def test_case_8():
102+
"""Float64 dtype test"""
103+
pytorch_code = textwrap.dedent(
104+
"""
105+
import torch
106+
input = torch.tensor([-0.6341, -1.4208, -1.0900, 0.5826], dtype=torch.float64)
107+
result = input.geometric_(0.5)
108+
"""
109+
)
110+
obj.run(pytorch_code, ["result"], check_value=False)
111+
112+
113+
def test_case_9():
114+
"""Expression argument test"""
115+
pytorch_code = textwrap.dedent(
116+
"""
117+
import torch
118+
input = torch.tensor([-0.6341, -1.4208, -1.0900, 0.5826])
119+
result = input.geometric_(0.3 + 0.2)
120+
"""
121+
)
122+
obj.run(pytorch_code, ["result"], check_value=False)
123+
124+
125+
def test_case_10():
126+
"""Boundary value test: p = 0.1"""
127+
pytorch_code = textwrap.dedent(
128+
"""
129+
import torch
130+
input = torch.tensor([1.0, 2.0, 3.0, 4.0])
131+
result = input.geometric_(0.1)
132+
"""
133+
)
134+
obj.run(pytorch_code, ["result"], check_value=False)
135+
136+
137+
def test_case_11():
138+
"""Boundary value test: p = 0.9"""
139+
pytorch_code = textwrap.dedent(
140+
"""
141+
import torch
142+
input = torch.tensor([1.0, 2.0, 3.0, 4.0])
143+
result = input.geometric_(0.9)
144+
"""
145+
)
146+
obj.run(pytorch_code, ["result"], check_value=False)
147+
148+
149+
def test_case_12():
150+
"""In-place modification verification"""
151+
pytorch_code = textwrap.dedent(
152+
"""
153+
import torch
154+
input = torch.tensor([1.0, 2.0, 3.0, 4.0])
155+
original_id = id(input)
156+
result = input.geometric_(p=0.5)
157+
modified_id = id(result)
158+
same_object = (original_id == modified_id)
159+
"""
160+
)
161+
obj.run(pytorch_code, ["result", "same_object"], check_value=False)
162+
163+
164+
def test_case_13():
165+
"""Large tensor test"""
166+
pytorch_code = textwrap.dedent(
167+
"""
168+
import torch
169+
input = torch.ones(100, 100)
170+
result = input.geometric_(0.5)
171+
"""
172+
)
173+
obj.run(pytorch_code, ["result"], check_value=False)

tests/test_Tensor_hypot_.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,16 @@ def test_case_5():
7676
"""
7777
)
7878
obj.run(pytorch_code, ["result", "a"])
79+
80+
81+
def test_case_6():
82+
"""Test with keyword arguments and expression"""
83+
pytorch_code = textwrap.dedent(
84+
"""
85+
import torch
86+
a = torch.tensor([3., 4., 5.])
87+
b = torch.tensor([1., 2., 3.])
88+
result = a.hypot_(other=b*2)
89+
"""
90+
)
91+
obj.run(pytorch_code, ["result", "a"])

0 commit comments

Comments
 (0)