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
117 changes: 9 additions & 108 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -2119,18 +2119,7 @@
]
},
"torch.Tensor.select_scatter": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.Tensor.select_scatter",
"min_input_args": 3,
"args_list": [
"src",
"dim",
"index"
],
"kwargs_change": {
"src": "values",
"dim": "axis"
}
"Matcher": "ChangePrefixMatcher"
},
"torch.Tensor.set_": {
"Matcher": "TensorSetMatcher",
Expand Down Expand Up @@ -2352,12 +2341,7 @@
"Matcher": "ChangePrefixMatcher"
},
"torch.Tensor.take": {
"Matcher": "TensorTakeMatcher",
"paddle_api": "paddle.Tensor.take",
"min_input_args": 1,
"args_list": [
"index"
]
"Matcher": "ChangePrefixMatcher"
},
"torch.Tensor.take_along_dim": {
"Matcher": "ChangePrefixMatcher"
Expand Down Expand Up @@ -10627,20 +10611,7 @@
]
},
"torch.select_scatter": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.select_scatter",
"min_input_args": 4,
"args_list": [
"input",
"src",
"dim",
"index"
],
"kwargs_change": {
"input": "x",
"src": "values",
"dim": "axis"
}
"Matcher": "ChangePrefixMatcher"
},
"torch.selu": {
"Matcher": "GenericMatcher",
Expand Down Expand Up @@ -10719,17 +10690,7 @@
}
},
"torch.sgn": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.sgn",
"min_input_args": 1,
"args_list": [
"input",
"*",
"out"
],
"kwargs_change": {
"input": "x"
}
"Matcher": "ChangePrefixMatcher"
},
"torch.sigmoid": {
"Matcher": "ChangePrefixMatcher"
Expand Down Expand Up @@ -10934,17 +10895,7 @@
}
},
"torch.signbit": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.signbit",
"min_input_args": 1,
"args_list": [
"input",
"*",
"out"
],
"kwargs_change": {
"input": "x"
}
"Matcher": "ChangePrefixMatcher"
},
"torch.sin": {
"Matcher": "ChangePrefixMatcher"
Expand Down Expand Up @@ -11531,16 +11482,7 @@
"Matcher": "ChangePrefixMatcher"
},
"torch.take": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.take",
"min_input_args": 2,
"args_list": [
"input",
"index"
],
"kwargs_change": {
"input": "x"
}
"Matcher": "ChangePrefixMatcher"
},
"torch.take_along_dim": {
"Matcher": "ChangePrefixMatcher"
Expand All @@ -11558,20 +11500,7 @@
"Matcher": "ChangePrefixMatcher"
},
"torch.tensordot": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.tensordot",
"min_input_args": 2,
"args_list": [
"a",
"b",
"dims",
"out"
],
"kwargs_change": {
"a": "x",
"b": "y",
"dims": "axes"
}
"Matcher": "ChangePrefixMatcher"
},
"torch.testing.assert_allclose": {
"Matcher": "Assert_AllcloseMatcher",
Expand Down Expand Up @@ -11656,42 +11585,14 @@
"Matcher": "ChangePrefixMatcher"
},
"torch.tril_indices": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.tril_indices",
"min_input_args": 2,
"args_list": [
"row",
"col",
"offset",
"*",
"dtype",
"device",
"layout"
],
"kwargs_change": {
"dtype": "dtype"
}
"Matcher": "ChangePrefixMatcher"
},
"torch.triplet_margin_loss": {},
"torch.triu": {
"Matcher": "ChangePrefixMatcher"
},
"torch.triu_indices": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.triu_indices",
"min_input_args": 2,
"args_list": [
"row",
"col",
"offset",
"*",
"dtype",
"device",
"layout"
],
"kwargs_change": {
"dtype": "dtype"
}
"Matcher": "ChangePrefixMatcher"
},
"torch.true_divide": {
"Matcher": "ChangePrefixMatcher"
Expand Down
91 changes: 91 additions & 0 deletions tests/test_Tensor_select_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,94 @@ def test_case_5():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_6():
"""Test with 3D tensor"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.zeros((2, 3, 4)).type(torch.float32)
src = torch.ones((2, 4)).type(torch.float32)
result = input.select_scatter(src, 1, 1)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_7():
"""Test with 3D tensor and keyword arguments"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.zeros((2, 3, 4)).type(torch.float32)
src = torch.ones((2, 4)).type(torch.float32)
result = input.select_scatter(src=src, dim=1, index=2)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_8():
"""Test with 4D tensor"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.zeros((2, 3, 4, 5)).type(torch.float32)
src = torch.ones((2, 3, 5)).type(torch.float32)
result = input.select_scatter(src, dim=2, index=1)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_9():
"""Test with index=0"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.zeros((3, 4)).type(torch.float32)
src = torch.ones(4).type(torch.float32)
result = input.select_scatter(src, dim=0, index=0)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_10():
"""Test with float64 dtype"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.zeros((2, 3)).type(torch.float64)
src = torch.ones(3).type(torch.float64)
result = input.select_scatter(src, dim=0, index=1)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_11():
"""Test with keyword arguments out of order"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.zeros((2, 3, 4))
src = torch.ones((2, 4))
result = input.select_scatter(index=1, src=src, dim=1)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_12():
"""Test on last dimension"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.zeros((2, 3, 4))
src = torch.ones((2, 3))
result = input.select_scatter(src=src, dim=2, index=0)
"""
)
obj.run(pytorch_code, ["result"])
96 changes: 96 additions & 0 deletions tests/test_Tensor_sgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,99 @@ def test_case_2():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_3():
"""Test with 2D tensor"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[0.5950, -0.0872], [2.3298, -0.2972]])
result = a.sgn()
"""
)
obj.run(pytorch_code, ["result"])


def test_case_4():
"""Test with 3D tensor"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[[0.5950, -0.0872], [2.3298, -0.2972]]])
result = a.sgn()
"""
)
obj.run(pytorch_code, ["result"])


def test_case_5():
"""Test with zero values"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([0., 1., 0., -1., 0.])
result = a.sgn()
"""
)
obj.run(pytorch_code, ["result"])


def test_case_6():
"""Test with negative values only"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([-1., -2., -3., -0.5])
result = a.sgn()
"""
)
obj.run(pytorch_code, ["result"])


def test_case_7():
"""Test with positive values only"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([1., 2., 3., 0.5])
result = a.sgn()
"""
)
obj.run(pytorch_code, ["result"])


def test_case_8():
"""Test with single element tensor"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([3.5])
result = a.sgn()
"""
)
obj.run(pytorch_code, ["result"])


def test_case_9():
"""Test with large values"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([1e10, -1e10, 1e-10, -1e-10])
result = a.sgn()
"""
)
obj.run(pytorch_code, ["result"])


def test_case_10():
"""Test with float64 dtype"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([0.5950, -0.0872, 2.3298, -0.2972], dtype=torch.float64)
result = a.sgn()
"""
)
obj.run(pytorch_code, ["result"])
Loading