Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 2 additions & 26 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -5707,19 +5707,7 @@
"Matcher": "ChangePrefixMatcher"
},
"torch.gcd": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.gcd",
"min_input_args": 2,
"args_list": [
"input",
"other",
"*",
"out"
],
"kwargs_change": {
"input": "x",
"other": "y"
}
"Matcher": "ChangePrefixMatcher"
},
"torch.ge": {
"Matcher": "ChangePrefixMatcher"
Expand Down Expand Up @@ -6243,19 +6231,7 @@
"Matcher": "ChangePrefixMatcher"
},
"torch.lcm": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.lcm",
"min_input_args": 2,
"args_list": [
"input",
"other",
"*",
"out"
],
"kwargs_change": {
"input": "x",
"other": "y"
}
"Matcher": "ChangePrefixMatcher"
},
"torch.ldexp": {
"Matcher": "GenericMatcher",
Expand Down
130 changes: 130 additions & 0 deletions tests/test_gcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,133 @@ def test_case_6():
"""
)
obj.run(pytorch_code, ["result", "out"])


def test_case_7():
"""Mixed positional and keyword arguments"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([5, 10, 15])
b = torch.tensor([3, 4, 5])
result = torch.gcd(a, other=b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_8():
"""2D tensor input"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[12, 18], [24, 36]])
b = torch.tensor([[8, 6], [16, 12]])
result = torch.gcd(a, b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_9():
"""Negative values"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([-5, 10, -15])
b = torch.tensor([3, -4, -5])
result = torch.gcd(a, b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_10():
"""Broadcasting"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[12, 18, 24]])
b = torch.tensor([6])
result = torch.gcd(a, b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_11():
"""Out parameter with positional args"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([5, 10, 15])
b = torch.tensor([3, 4, 5])
out = torch.empty(3, dtype=torch.int64)
result = torch.gcd(a, b, out=out)
"""
)
obj.run(pytorch_code, ["result", "out"])


def test_case_12():
"""3D tensor input"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[[12, 18], [24, 36]], [[8, 14], [20, 28]]])
b = torch.tensor([[[4, 6], [8, 12]], [[2, 7], [10, 14]]])
result = torch.gcd(a, b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_13():
"""int32 dtype"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([5, 10, 15], dtype=torch.int32)
b = torch.tensor([3, 4, 5], dtype=torch.int32)
result = torch.gcd(a, b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_14():
"""Variable arguments"""
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([12, 18, 24])
y = torch.tensor([8, 6, 16])
result = torch.gcd(x, y)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_15():
"""Zero values"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([0, 10, 0])
b = torch.tensor([5, 0, 0])
result = torch.gcd(a, b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_16():
"""Expression as argument"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([5, 10, 15])
result = torch.gcd(a, torch.tensor([3, 4, 5]))
"""
)
obj.run(pytorch_code, ["result"])
130 changes: 130 additions & 0 deletions tests/test_lcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,133 @@ def test_case_7():
"""
)
obj.run(pytorch_code, ["result", "out"])


def test_case_8():
"""Mixed positional and keyword arguments"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([5, 10, 15])
b = torch.tensor([3, 4, 5])
result = torch.lcm(a, other=b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_9():
"""2D tensor input"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[12, 18], [24, 36]])
b = torch.tensor([[8, 6], [16, 12]])
result = torch.lcm(a, b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_10():
"""Negative values"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([-5, 10, -15])
b = torch.tensor([3, -4, -5])
result = torch.lcm(a, b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_11():
"""Broadcasting"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[12, 18, 24]])
b = torch.tensor([6])
result = torch.lcm(a, b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_12():
"""Out parameter with positional args"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([5, 10, 15])
b = torch.tensor([3, 4, 5])
out = torch.empty(3, dtype=torch.int64)
result = torch.lcm(a, b, out=out)
"""
)
obj.run(pytorch_code, ["result", "out"])


def test_case_13():
"""3D tensor input"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[[12, 18], [24, 36]], [[8, 14], [20, 28]]])
b = torch.tensor([[[4, 6], [8, 12]], [[2, 7], [10, 14]]])
result = torch.lcm(a, b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_14():
"""int32 dtype"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([5, 10, 15], dtype=torch.int32)
b = torch.tensor([3, 4, 5], dtype=torch.int32)
result = torch.lcm(a, b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_15():
"""Variable arguments"""
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([12, 18, 24])
y = torch.tensor([8, 6, 16])
result = torch.lcm(x, y)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_16():
"""Zero values"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([0, 10, 0])
b = torch.tensor([5, 0, 0])
result = torch.lcm(a, b)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_17():
"""Expression as argument"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([5, 10, 15])
result = torch.lcm(a, torch.tensor([3, 4, 5]))
"""
)
obj.run(pytorch_code, ["result"])