diff --git a/paconvert/api_mapping.json b/paconvert/api_mapping.json index 1d10fe946..f26b90350 100644 --- a/paconvert/api_mapping.json +++ b/paconvert/api_mapping.json @@ -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" @@ -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", diff --git a/tests/test_gcd.py b/tests/test_gcd.py index 751f17835..2dee39942 100644 --- a/tests/test_gcd.py +++ b/tests/test_gcd.py @@ -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"]) \ No newline at end of file diff --git a/tests/test_lcm.py b/tests/test_lcm.py index b30804eaa..3a6565212 100644 --- a/tests/test_lcm.py +++ b/tests/test_lcm.py @@ -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"])