Skip to content

Commit 895092c

Browse files
authored
[API Compatibility No.11、16、69、86] Add gcd, gcd_, lcm, lcm_ -part (#787)
* fix * add a new line
1 parent c93ce82 commit 895092c

3 files changed

Lines changed: 264 additions & 26 deletions

File tree

paconvert/api_mapping.json

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5401,19 +5401,7 @@
54015401
"Matcher": "ChangePrefixMatcher"
54025402
},
54035403
"torch.gcd": {
5404-
"Matcher": "GenericMatcher",
5405-
"paddle_api": "paddle.gcd",
5406-
"min_input_args": 2,
5407-
"args_list": [
5408-
"input",
5409-
"other",
5410-
"*",
5411-
"out"
5412-
],
5413-
"kwargs_change": {
5414-
"input": "x",
5415-
"other": "y"
5416-
}
5404+
"Matcher": "ChangePrefixMatcher"
54175405
},
54185406
"torch.ge": {
54195407
"Matcher": "ChangePrefixMatcher"
@@ -5851,19 +5839,7 @@
58515839
"Matcher": "ChangePrefixMatcher"
58525840
},
58535841
"torch.lcm": {
5854-
"Matcher": "GenericMatcher",
5855-
"paddle_api": "paddle.lcm",
5856-
"min_input_args": 2,
5857-
"args_list": [
5858-
"input",
5859-
"other",
5860-
"*",
5861-
"out"
5862-
],
5863-
"kwargs_change": {
5864-
"input": "x",
5865-
"other": "y"
5866-
}
5842+
"Matcher": "ChangePrefixMatcher"
58675843
},
58685844
"torch.ldexp": {
58695845
"Matcher": "ChangePrefixMatcher"

tests/test_gcd.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,135 @@ def test_case_6():
8888
"""
8989
)
9090
obj.run(pytorch_code, ["result", "out"])
91+
92+
93+
def test_case_7():
94+
"""Mixed positional and keyword arguments"""
95+
pytorch_code = textwrap.dedent(
96+
"""
97+
import torch
98+
a = torch.tensor([5, 10, 15])
99+
b = torch.tensor([3, 4, 5])
100+
result = torch.gcd(a, other=b)
101+
"""
102+
)
103+
obj.run(pytorch_code, ["result"])
104+
105+
106+
def test_case_8():
107+
"""2D tensor input"""
108+
pytorch_code = textwrap.dedent(
109+
"""
110+
import torch
111+
a = torch.tensor([[12, 18], [24, 36]])
112+
b = torch.tensor([[8, 6], [16, 12]])
113+
result = torch.gcd(a, b)
114+
"""
115+
)
116+
obj.run(pytorch_code, ["result"])
117+
118+
119+
def test_case_9():
120+
"""Negative values"""
121+
pytorch_code = textwrap.dedent(
122+
"""
123+
import torch
124+
a = torch.tensor([-5, 10, -15])
125+
b = torch.tensor([3, -4, -5])
126+
result = torch.gcd(a, b)
127+
"""
128+
)
129+
obj.run(pytorch_code, ["result"])
130+
131+
132+
def test_case_10():
133+
"""Broadcasting"""
134+
pytorch_code = textwrap.dedent(
135+
"""
136+
import torch
137+
a = torch.tensor([[12, 18, 24]])
138+
b = torch.tensor([6])
139+
result = torch.gcd(a, b)
140+
"""
141+
)
142+
obj.run(pytorch_code, ["result"])
143+
144+
145+
def test_case_11():
146+
"""Out parameter with positional args"""
147+
pytorch_code = textwrap.dedent(
148+
"""
149+
import torch
150+
a = torch.tensor([5, 10, 15])
151+
b = torch.tensor([3, 4, 5])
152+
out = torch.empty(3, dtype=torch.int64)
153+
result = torch.gcd(a, b, out=out)
154+
"""
155+
)
156+
obj.run(pytorch_code, ["result", "out"])
157+
158+
159+
def test_case_12():
160+
"""3D tensor input"""
161+
pytorch_code = textwrap.dedent(
162+
"""
163+
import torch
164+
a = torch.tensor([[[12, 18], [24, 36]], [[8, 14], [20, 28]]])
165+
b = torch.tensor([[[4, 6], [8, 12]], [[2, 7], [10, 14]]])
166+
result = torch.gcd(a, b)
167+
"""
168+
)
169+
obj.run(pytorch_code, ["result"])
170+
171+
172+
def test_case_13():
173+
"""int32 dtype"""
174+
pytorch_code = textwrap.dedent(
175+
"""
176+
import torch
177+
a = torch.tensor([5, 10, 15], dtype=torch.int32)
178+
b = torch.tensor([3, 4, 5], dtype=torch.int32)
179+
result = torch.gcd(a, b)
180+
"""
181+
)
182+
obj.run(pytorch_code, ["result"])
183+
184+
185+
def test_case_14():
186+
"""Variable arguments"""
187+
pytorch_code = textwrap.dedent(
188+
"""
189+
import torch
190+
x = torch.tensor([12, 18, 24])
191+
y = torch.tensor([8, 6, 16])
192+
result = torch.gcd(x, y)
193+
"""
194+
)
195+
obj.run(pytorch_code, ["result"])
196+
197+
198+
def test_case_15():
199+
"""Zero values"""
200+
pytorch_code = textwrap.dedent(
201+
"""
202+
import torch
203+
a = torch.tensor([0, 10, 0])
204+
b = torch.tensor([5, 0, 0])
205+
result = torch.gcd(a, b)
206+
"""
207+
)
208+
obj.run(pytorch_code, ["result"])
209+
210+
211+
def test_case_16():
212+
"""Expression as argument"""
213+
pytorch_code = textwrap.dedent(
214+
"""
215+
import torch
216+
a = torch.tensor([5, 10, 15])
217+
result = torch.gcd(a, torch.tensor([3, 4, 5]))
218+
"""
219+
)
220+
obj.run(pytorch_code, ["result"])
221+
222+
obj.run(pytorch_code, ["result"])

tests/test_lcm.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,133 @@ def test_case_7():
100100
"""
101101
)
102102
obj.run(pytorch_code, ["result", "out"])
103+
104+
105+
def test_case_8():
106+
"""Mixed positional and keyword arguments"""
107+
pytorch_code = textwrap.dedent(
108+
"""
109+
import torch
110+
a = torch.tensor([5, 10, 15])
111+
b = torch.tensor([3, 4, 5])
112+
result = torch.lcm(a, other=b)
113+
"""
114+
)
115+
obj.run(pytorch_code, ["result"])
116+
117+
118+
def test_case_9():
119+
"""2D tensor input"""
120+
pytorch_code = textwrap.dedent(
121+
"""
122+
import torch
123+
a = torch.tensor([[12, 18], [24, 36]])
124+
b = torch.tensor([[8, 6], [16, 12]])
125+
result = torch.lcm(a, b)
126+
"""
127+
)
128+
obj.run(pytorch_code, ["result"])
129+
130+
131+
def test_case_10():
132+
"""Negative values"""
133+
pytorch_code = textwrap.dedent(
134+
"""
135+
import torch
136+
a = torch.tensor([-5, 10, -15])
137+
b = torch.tensor([3, -4, -5])
138+
result = torch.lcm(a, b)
139+
"""
140+
)
141+
obj.run(pytorch_code, ["result"])
142+
143+
144+
def test_case_11():
145+
"""Broadcasting"""
146+
pytorch_code = textwrap.dedent(
147+
"""
148+
import torch
149+
a = torch.tensor([[12, 18, 24]])
150+
b = torch.tensor([6])
151+
result = torch.lcm(a, b)
152+
"""
153+
)
154+
obj.run(pytorch_code, ["result"])
155+
156+
157+
def test_case_12():
158+
"""Out parameter with positional args"""
159+
pytorch_code = textwrap.dedent(
160+
"""
161+
import torch
162+
a = torch.tensor([5, 10, 15])
163+
b = torch.tensor([3, 4, 5])
164+
out = torch.empty(3, dtype=torch.int64)
165+
result = torch.lcm(a, b, out=out)
166+
"""
167+
)
168+
obj.run(pytorch_code, ["result", "out"])
169+
170+
171+
def test_case_13():
172+
"""3D tensor input"""
173+
pytorch_code = textwrap.dedent(
174+
"""
175+
import torch
176+
a = torch.tensor([[[12, 18], [24, 36]], [[8, 14], [20, 28]]])
177+
b = torch.tensor([[[4, 6], [8, 12]], [[2, 7], [10, 14]]])
178+
result = torch.lcm(a, b)
179+
"""
180+
)
181+
obj.run(pytorch_code, ["result"])
182+
183+
184+
def test_case_14():
185+
"""int32 dtype"""
186+
pytorch_code = textwrap.dedent(
187+
"""
188+
import torch
189+
a = torch.tensor([5, 10, 15], dtype=torch.int32)
190+
b = torch.tensor([3, 4, 5], dtype=torch.int32)
191+
result = torch.lcm(a, b)
192+
"""
193+
)
194+
obj.run(pytorch_code, ["result"])
195+
196+
197+
def test_case_15():
198+
"""Variable arguments"""
199+
pytorch_code = textwrap.dedent(
200+
"""
201+
import torch
202+
x = torch.tensor([12, 18, 24])
203+
y = torch.tensor([8, 6, 16])
204+
result = torch.lcm(x, y)
205+
"""
206+
)
207+
obj.run(pytorch_code, ["result"])
208+
209+
210+
def test_case_16():
211+
"""Zero values"""
212+
pytorch_code = textwrap.dedent(
213+
"""
214+
import torch
215+
a = torch.tensor([0, 10, 0])
216+
b = torch.tensor([5, 0, 0])
217+
result = torch.lcm(a, b)
218+
"""
219+
)
220+
obj.run(pytorch_code, ["result"])
221+
222+
223+
def test_case_17():
224+
"""Expression as argument"""
225+
pytorch_code = textwrap.dedent(
226+
"""
227+
import torch
228+
a = torch.tensor([5, 10, 15])
229+
result = torch.lcm(a, torch.tensor([3, 4, 5]))
230+
"""
231+
)
232+
obj.run(pytorch_code, ["result"])

0 commit comments

Comments
 (0)