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
429 changes: 38 additions & 391 deletions paconvert/api_mapping.json

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions tests/test_col_indices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.Tensor.col_indices")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.randn(3, 4).to_sparse_csr()
result = x.col_indices()
"""
)
obj.run(pytorch_code, ["result"])
30 changes: 30 additions & 0 deletions tests/test_crow_indices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.Tensor.crow_indices")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.randn(3, 4).to_sparse_csr()
result = x.crow_indices()
"""
)
obj.run(pytorch_code, ["result"])
41 changes: 41 additions & 0 deletions tests/test_erf_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.Tensor.erf_")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([-2.0, -0.5, 1.5, 3.0], dtype=torch.float32)
result = x.erf_()
"""
)
obj.run(pytorch_code, ["x", "result"])


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[-3.0, -1.25], [0.75, 2.5]], dtype=torch.float64)
result = x.erf_()
"""
)
obj.run(pytorch_code, ["x", "result"])
41 changes: 41 additions & 0 deletions tests/test_fix_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.Tensor.fix_")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([-2.5, -0.5, 1.5, 3.7], dtype=torch.float32)
result = x.fix_()
"""
)
obj.run(pytorch_code, ["x", "result"])


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[-3.5, -1.25], [0.75, 2.5]], dtype=torch.float64)
result = x.fix_()
"""
)
obj.run(pytorch_code, ["x", "result"])
41 changes: 41 additions & 0 deletions tests/test_matrix_exp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.Tensor.matrix_exp")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.eye(3, dtype=torch.float32)
result = x.matrix_exp()
"""
)
obj.run(pytorch_code, ["result"])


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.eye(3, dtype=torch.float64)
result = x.matrix_exp()
"""
)
obj.run(pytorch_code, ["result"])
41 changes: 41 additions & 0 deletions tests/test_mvlgamma_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.Tensor.mvlgamma_")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([1.5, 2.5, 3.5], dtype=torch.float32)
result = x.mvlgamma_(2)
"""
)
obj.run(pytorch_code, ["x", "result"])


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[1.5, 2.5], [3.5, 4.5]], dtype=torch.float64)
result = x.mvlgamma_(3)
"""
)
obj.run(pytorch_code, ["x", "result"])
41 changes: 41 additions & 0 deletions tests/test_negative_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.Tensor.negative_")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([-2.0, -0.5, 1.5, 3.0], dtype=torch.float32)
result = x.negative_()
"""
)
obj.run(pytorch_code, ["x", "result"])


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[-3.0, -1.25], [0.75, 2.5]], dtype=torch.float64)
result = x.negative_()
"""
)
obj.run(pytorch_code, ["x", "result"])
33 changes: 33 additions & 0 deletions tests/test_retain_grad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.Tensor.retain_grad")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([1.0, 2.0, 3.0], requires_grad=True)
x.retain_grad()
y = x.sum()
y.backward()
result = x.grad
"""
)
obj.run(pytorch_code, ["result"], check_stop_gradient=False)
46 changes: 46 additions & 0 deletions tests/test_sparse_mask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.Tensor.sparse_mask")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.randn(3, 4)
indices = torch.tensor([[0, 1], [0, 1]])
values = torch.tensor([1.0, 1.0])
sparse_mask = torch.sparse_coo_tensor(indices, values, (3, 4))
result = x.sparse_mask(sparse_mask)
"""
)
expect_paddle_code = textwrap.dedent(
"""
import paddle

x = paddle.randn(3, 4)
indices = paddle.tensor([[0, 1], [0, 1]])
values = paddle.tensor([1.0, 1.0])
sparse_mask = paddle.sparse.sparse_coo_tensor(
indices=indices, values=values, shape=(3, 4)
)
result = x.sparse_mask(sparse_mask)
"""
)
obj.run(pytorch_code, expect_paddle_code=expect_paddle_code)
Loading