Skip to content

Commit b4cdb9f

Browse files
zhwesky2010claude
andcommitted
[API Compatibility] col_indices/crow_indices/erf_/fix_/matrix_exp/mvlgamma_/negative_/retain_grad/sparse_mask/to_sparse Edit By AI Agent
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cb49e74 commit b4cdb9f

10 files changed

Lines changed: 401 additions & 0 deletions

tests/test_col_indices.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import textwrap
16+
17+
from apibase import APIBase
18+
19+
obj = APIBase("torch.Tensor.col_indices")
20+
21+
22+
def test_case_1():
23+
pytorch_code = textwrap.dedent(
24+
"""
25+
import torch
26+
x = torch.randn(3, 4).to_sparse_csr()
27+
result = x.col_indices()
28+
"""
29+
)
30+
obj.run(pytorch_code, ["result"])

tests/test_crow_indices.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import textwrap
16+
17+
from apibase import APIBase
18+
19+
obj = APIBase("torch.Tensor.crow_indices")
20+
21+
22+
def test_case_1():
23+
pytorch_code = textwrap.dedent(
24+
"""
25+
import torch
26+
x = torch.randn(3, 4).to_sparse_csr()
27+
result = x.crow_indices()
28+
"""
29+
)
30+
obj.run(pytorch_code, ["result"])

tests/test_erf_.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import textwrap
16+
17+
from apibase import APIBase
18+
19+
obj = APIBase("torch.Tensor.erf_")
20+
21+
22+
def test_case_1():
23+
pytorch_code = textwrap.dedent(
24+
"""
25+
import torch
26+
x = torch.tensor([-2.0, -0.5, 1.5, 3.0], dtype=torch.float32)
27+
result = x.erf_()
28+
"""
29+
)
30+
obj.run(pytorch_code, ["x", "result"])
31+
32+
33+
def test_case_2():
34+
pytorch_code = textwrap.dedent(
35+
"""
36+
import torch
37+
x = torch.tensor([[-3.0, -1.25], [0.75, 2.5]], dtype=torch.float64)
38+
result = x.erf_()
39+
"""
40+
)
41+
obj.run(pytorch_code, ["x", "result"])

tests/test_fix_.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import textwrap
16+
17+
from apibase import APIBase
18+
19+
obj = APIBase("torch.Tensor.fix_")
20+
21+
22+
def test_case_1():
23+
pytorch_code = textwrap.dedent(
24+
"""
25+
import torch
26+
x = torch.tensor([-2.5, -0.5, 1.5, 3.7], dtype=torch.float32)
27+
result = x.fix_()
28+
"""
29+
)
30+
obj.run(pytorch_code, ["x", "result"])
31+
32+
33+
def test_case_2():
34+
pytorch_code = textwrap.dedent(
35+
"""
36+
import torch
37+
x = torch.tensor([[-3.5, -1.25], [0.75, 2.5]], dtype=torch.float64)
38+
result = x.fix_()
39+
"""
40+
)
41+
obj.run(pytorch_code, ["x", "result"])

tests/test_matrix_exp.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import textwrap
16+
17+
from apibase import APIBase
18+
19+
obj = APIBase("torch.Tensor.matrix_exp")
20+
21+
22+
def test_case_1():
23+
pytorch_code = textwrap.dedent(
24+
"""
25+
import torch
26+
x = torch.eye(3, dtype=torch.float32)
27+
result = x.matrix_exp()
28+
"""
29+
)
30+
obj.run(pytorch_code, ["result"])
31+
32+
33+
def test_case_2():
34+
pytorch_code = textwrap.dedent(
35+
"""
36+
import torch
37+
x = torch.eye(3, dtype=torch.float64)
38+
result = x.matrix_exp()
39+
"""
40+
)
41+
obj.run(pytorch_code, ["result"])

tests/test_mvlgamma_.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import textwrap
16+
17+
from apibase import APIBase
18+
19+
obj = APIBase("torch.Tensor.mvlgamma_")
20+
21+
22+
def test_case_1():
23+
pytorch_code = textwrap.dedent(
24+
"""
25+
import torch
26+
x = torch.tensor([1.5, 2.5, 3.5], dtype=torch.float32)
27+
result = x.mvlgamma_(2)
28+
"""
29+
)
30+
obj.run(pytorch_code, ["x", "result"])
31+
32+
33+
def test_case_2():
34+
pytorch_code = textwrap.dedent(
35+
"""
36+
import torch
37+
x = torch.tensor([[1.5, 2.5], [3.5, 4.5]], dtype=torch.float64)
38+
result = x.mvlgamma_(3)
39+
"""
40+
)
41+
obj.run(pytorch_code, ["x", "result"])

tests/test_negative_.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import textwrap
16+
17+
from apibase import APIBase
18+
19+
obj = APIBase("torch.Tensor.negative_")
20+
21+
22+
def test_case_1():
23+
pytorch_code = textwrap.dedent(
24+
"""
25+
import torch
26+
x = torch.tensor([-2.0, -0.5, 1.5, 3.0], dtype=torch.float32)
27+
result = x.negative_()
28+
"""
29+
)
30+
obj.run(pytorch_code, ["x", "result"])
31+
32+
33+
def test_case_2():
34+
pytorch_code = textwrap.dedent(
35+
"""
36+
import torch
37+
x = torch.tensor([[-3.0, -1.25], [0.75, 2.5]], dtype=torch.float64)
38+
result = x.negative_()
39+
"""
40+
)
41+
obj.run(pytorch_code, ["x", "result"])

tests/test_retain_grad.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import textwrap
16+
17+
from apibase import APIBase
18+
19+
obj = APIBase("torch.Tensor.retain_grad")
20+
21+
22+
def test_case_1():
23+
pytorch_code = textwrap.dedent(
24+
"""
25+
import torch
26+
x = torch.tensor([1.0, 2.0, 3.0], requires_grad=True)
27+
x.retain_grad()
28+
y = x.sum()
29+
y.backward()
30+
result = x.grad
31+
"""
32+
)
33+
obj.run(pytorch_code, ["result"], check_stop_gradient=False)

tests/test_sparse_mask.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import textwrap
16+
17+
from apibase import APIBase
18+
19+
obj = APIBase("torch.Tensor.sparse_mask")
20+
21+
22+
def test_case_1():
23+
pytorch_code = textwrap.dedent(
24+
"""
25+
import torch
26+
x = torch.randn(3, 4)
27+
indices = torch.tensor([[0, 1], [0, 1]])
28+
values = torch.tensor([1.0, 1.0])
29+
sparse_mask = torch.sparse_coo_tensor(indices, values, (3, 4))
30+
result = x.sparse_mask(sparse_mask)
31+
"""
32+
)
33+
expect_paddle_code = textwrap.dedent(
34+
"""
35+
import paddle
36+
37+
x = paddle.randn(3, 4)
38+
indices = paddle.tensor([[0, 1], [0, 1]])
39+
values = paddle.tensor([1.0, 1.0])
40+
sparse_mask = paddle.sparse.sparse_coo_tensor(
41+
indices=indices, values=values, shape=(3, 4)
42+
)
43+
result = x.sparse_mask(sparse_mask)
44+
"""
45+
)
46+
obj.run(pytorch_code, expect_paddle_code=expect_paddle_code)

0 commit comments

Comments
 (0)