diff --git a/paconvert/api_mapping.json b/paconvert/api_mapping.json index 16f4280ad..b1f501312 100644 --- a/paconvert/api_mapping.json +++ b/paconvert/api_mapping.json @@ -6083,33 +6083,27 @@ "paddle_api": "paddle.device.get_device" }, "torch.Tensor.gt": { - "Matcher": "GenericMatcher", + "Matcher": "Num2TensorBinaryMatcher", "paddle_api": "paddle.Tensor.greater_than", "args_list": [ "other" - ], - "kwargs_change": { - "other": "y" - } + ] }, "torch.Tensor.greater": { - "Matcher": "GenericMatcher", + "Matcher": "Num2TensorBinaryMatcher", "paddle_api": "paddle.Tensor.greater_than", "args_list": [ "other" - ], - "kwargs_change": { - "other": "y" - } + ] }, "torch.Tensor.heaviside": { "Matcher": "GenericMatcher", "paddle_api": "paddle.Tensor.heaviside", "args_list": [ - "values" + "data" ], "kwargs_change": { - "other": "y" + "data": "y" } }, "torch.Tensor.index_select": { @@ -6196,24 +6190,18 @@ } }, "torch.Tensor.le": { - "Matcher": "GenericMatcher", + "Matcher": "Num2TensorBinaryMatcher", "paddle_api": "paddle.Tensor.less_equal", "args_list": [ "other" - ], - "kwargs_change": { - "other": "y" - } + ] }, "torch.Tensor.less_equal": { - "Matcher": "GenericMatcher", + "Matcher": "Num2TensorBinaryMatcher", "paddle_api": "paddle.Tensor.less_equal", "args_list": [ "other" - ], - "kwargs_change": { - "other": "y" - } + ] }, "torch.Tensor.lerp": { "Matcher": "GenericMatcher", @@ -6268,38 +6256,29 @@ } }, "torch.Tensor.logical_and": { - "Matcher": "GenericMatcher", + "Matcher": "TensorLogicalMatcher", "paddle_api": "paddle.Tensor.logical_and", "args_list": [ "other" - ], - "kwargs_change": { - "other": "y" - } + ] }, "torch.Tensor.logical_not": { "Matcher": "GenericMatcher", "paddle_api": "paddle.Tensor.logical_not" }, "torch.Tensor.logical_or": { - "Matcher": "GenericMatcher", + "Matcher": "TensorLogicalMatcher", "paddle_api": "paddle.Tensor.logical_or", "args_list": [ "other" - ], - "kwargs_change": { - "other": "y" - } + ] }, "torch.Tensor.logical_xor": { - "Matcher": "GenericMatcher", + "Matcher": "TensorLogicalMatcher", "paddle_api": "paddle.Tensor.logical_xor", "args_list": [ "other" - ], - "kwargs_change": { - "other": "y" - } + ] }, "torch.Tensor.logit": { "Matcher": "GenericMatcher", @@ -6309,24 +6288,18 @@ ] }, "torch.Tensor.lt": { - "Matcher": "GenericMatcher", + "Matcher": "Num2TensorBinaryMatcher", "paddle_api": "paddle.Tensor.less_than", "args_list": [ "other" - ], - "kwargs_change": { - "other": "y" - } + ] }, "torch.Tensor.less": { - "Matcher": "GenericMatcher", + "Matcher": "Num2TensorBinaryMatcher", "paddle_api": "paddle.Tensor.less_than", "args_list": [ "other" - ], - "kwargs_change": { - "other": "y" - } + ] }, "torch.Tensor.lu": { "Matcher": "GenericMatcher", diff --git a/paconvert/api_matcher.py b/paconvert/api_matcher.py index 42af57ec0..68b566256 100644 --- a/paconvert/api_matcher.py +++ b/paconvert/api_matcher.py @@ -3620,3 +3620,13 @@ def generate_code(self, kwargs): self.get_paddle_api(), self.paddleClass, self.kwargs_to_str(kwargs) ) return code + + +class TensorLogicalMatcher(BaseMatcher): + def generate_code(self, kwargs): + + code = "{}(y=({}).astype(({}).dtype))".format( + self.get_paddle_api(), kwargs["other"], self.paddleClass + ) + + return code diff --git a/tests/test_Tensor_ger.py b/tests/test_Tensor_ger.py new file mode 100644 index 000000000..d6aeb1d72 --- /dev/null +++ b/tests/test_Tensor_ger.py @@ -0,0 +1,79 @@ +# Copyright (c) 2023 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.ger") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([1., 2, 3]) + y = torch.tensor([1., 2, 3, 4]) + result = x.ger(y) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([1., 2, 3]) + y = torch.tensor([1., 2, 3, 4]) + result = x.ger(vec2=y) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([1., 2, 3]).ger(torch.tensor([1., 2, 3, 4])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +# The paddle input does not support integer type +def _test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([1, 2, 3]) + y = torch.tensor([1, 2, 3, 4]) + result = x.ger(y) + """ + ) + obj.run(pytorch_code, ["result"]) + + +# The paddle other does not support integer type +def _test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([1., 2., 3.]) + y = torch.tensor([1, 2, 3, 4]) + result = x.ger(y) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_greater.py b/tests/test_Tensor_greater.py new file mode 100644 index 000000000..faf12f57e --- /dev/null +++ b/tests/test_Tensor_greater.py @@ -0,0 +1,75 @@ +# Copyright (c) 2023 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.greater") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[1, 2], [3, 4]]).greater(torch.tensor([[1, 1], [4, 4]])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([[1, 1], [4, 4]]) + result = input.greater(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([[1, 2], [3, 4]]) + result = input.greater(other=other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([1, 2]) + result = input.greater(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[1, 2], [3, 4]]).greater(2) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_gt.py b/tests/test_Tensor_gt.py new file mode 100644 index 000000000..a5d7ff791 --- /dev/null +++ b/tests/test_Tensor_gt.py @@ -0,0 +1,75 @@ +# Copyright (c) 2023 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.gt") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[1, 2], [3, 4]]).gt(torch.tensor([[1, 1], [4, 4]])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([[1, 1], [4, 4]]) + result = input.gt(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([[1, 2], [3, 4]]) + result = input.gt(other=other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([1, 2]) + result = input.gt(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[1, 2], [3, 4]]).gt(2) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_heaviside.py b/tests/test_Tensor_heaviside.py new file mode 100644 index 000000000..f98cb08ab --- /dev/null +++ b/tests/test_Tensor_heaviside.py @@ -0,0 +1,73 @@ +# Copyright (c) 2023 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.heaviside") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([-1.5, 0, 2.0]) + values = torch.tensor([0.5]) + result = input.heaviside(values) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([-1.5, 0, 2.0]).heaviside(torch.tensor([0.5])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([-1.5, 0, 2.0]) + result = input.heaviside(torch.tensor([0.5])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([-1.5, 0, 2.0]) + result = input.heaviside(torch.tensor([0.5, 1.7, 0.8])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([-1.5, 0, 2.0]) + result = input.heaviside(torch.tensor(data=[0.5, 1.7, 0.8])) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_index_select.py b/tests/test_Tensor_index_select.py new file mode 100644 index 000000000..1495b3dae --- /dev/null +++ b/tests/test_Tensor_index_select.py @@ -0,0 +1,66 @@ +# Copyright (c) 2023 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.index_select") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.eye(2, 4) + indices = torch.tensor([0, 1]) + result = x.index_select(0, indices) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + indices = torch.tensor([0, 1]) + result = torch.eye(3, 4).index_select(1, indices) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + indices = torch.tensor([0, 1]) + dim = 0 + result = torch.eye(3, 4).index_select(dim, indices) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + indices = torch.tensor([0, 3]) + dim = 0 + result = torch.eye(5, 4).index_select(dim=dim, index=indices) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_inner.py b/tests/test_Tensor_inner.py new file mode 100644 index 000000000..4b8a951dc --- /dev/null +++ b/tests/test_Tensor_inner.py @@ -0,0 +1,80 @@ +# Copyright (c) 2023 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.inner") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([1., 2, 3]).inner(torch.tensor([0., 2, 1])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([[0.8173, 1.0874, 1.1784], [0.3279, 0.1234, 2.7894]]) + y = torch.tensor([[[-0.4682, -0.7159, 0.1506], + [ 0.4034, -0.3657, 1.0387], + [ 0.9892, -0.6684, 0.1774], + [ 0.9482, 1.3261, 0.3917]], + [[ 0.4537, 0.7493, 1.1724], + [ 0.2291, 0.5749, -0.2267], + [-0.7920, 0.3607, -0.3701], + [ 1.3666, -0.5850, -1.7242]]]) + result = x.inner(y) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([[0.8173, 1.0874, 1.1784], [0.3279, 0.1234, 2.7894]]) + result = x.inner(torch.tensor(2.)) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([1., 2, 3]).inner(other=torch.tensor([0., 2, 1])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +# The paddle input does not support integer type +def _test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([1, 2, 3]).inner(torch.tensor([0, 2, 1])) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_inverse.py b/tests/test_Tensor_inverse.py new file mode 100644 index 000000000..97c18b89f --- /dev/null +++ b/tests/test_Tensor_inverse.py @@ -0,0 +1,66 @@ +# Copyright (c) 2023 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.inverse") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([[ 0.7308, 1.0060, 0.5270, 1.4516], + [-0.1383, 1.5706, 0.4724, 0.4141], + [ 0.1193, 0.2829, 0.9037, 0.3957], + [-0.8202, -0.6474, -0.1631, -0.6543]]) + result = x.inverse() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([[[[-0.1533, 2.3020, -0.1771, 0.5928], + [ 0.4338, -0.6537, 0.2296, 0.5946], + [-0.4932, 1.8386, -0.1039, 1.0440], + [ 0.1735, -0.8303, -0.3821, -0.4384]], + [[-0.1533, 2.3020, -0.1771, 0.5928], + [ 0.4338, -0.6537, 0.2296, 0.5946], + [-0.4932, 1.8386, -0.1039, 1.0440], + [ 0.1735, -0.8303, -0.3821, -0.4384]]]]) + result = x.inverse() + """ + ) + obj.run(pytorch_code, ["result"]) + + +# The paddle input does not support complex type +def _test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([[-3.0832+3.0494j, -0.1751+0.1449j, 1.2197+1.8188j, 4.0353-0.7416j], + [-2.9842-2.8928j, 0.2123+0.6190j, -2.6104+0.7303j, 1.9740+3.3802j], + [ 0.4939-2.4271j, 0.5006-0.6895j, -1.3655-0.2352j, -1.6636+1.6514j], + [-4.1212+0.1513j, 0.7119-0.0603j, -1.7803+2.8278j, 3.4966+1.2988j]]) + result = x.inverse() + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_is_complex.py b/tests/test_Tensor_is_complex.py new file mode 100644 index 000000000..06a1733b6 --- /dev/null +++ b/tests/test_Tensor_is_complex.py @@ -0,0 +1,51 @@ +# Copyright (c) 2023 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.is_complex") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([[4, 9], [23, 2]]) + result = a.is_complex() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[4, 9], [23, 2]], dtype=torch.complex64).is_complex() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([[4, 9], [23, 2]], dtype=torch.complex128) + result = a.is_complex() + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_is_floating_point.py b/tests/test_Tensor_is_floating_point.py new file mode 100644 index 000000000..eb894164d --- /dev/null +++ b/tests/test_Tensor_is_floating_point.py @@ -0,0 +1,71 @@ +# Copyright (c) 2023 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.is_floating_point") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([[4, 9], [23, 2]], dtype=torch.int64) + result = a.is_floating_point() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([[4, 9], [23, 2]], dtype=torch.float64) + result = a.is_floating_point() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[4, 9], [23, 2]], dtype=torch.float32).is_floating_point() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[4, 9], [23, 2]], dtype=torch.float16).is_floating_point() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[4, 9], [23, 2]], dtype=torch.bfloat16).is_floating_point() + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_isclose.py b/tests/test_Tensor_isclose.py new file mode 100644 index 000000000..ca3939d50 --- /dev/null +++ b/tests/test_Tensor_isclose.py @@ -0,0 +1,69 @@ +# Copyright (c) 2023 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.isclose") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([10000., 1e-07]).isclose(torch.tensor([10000.1, 1e-08])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([10000., 1e-08]).isclose(torch.tensor([10000.1, 1e-09])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([1.0, float('nan')]).isclose(torch.tensor([1.0, float('nan')])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([1.0, float('inf')]).isclose(torch.tensor([1.0, float('inf')]), equal_nan=True) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([10000., 1e-07]).isclose(torch.tensor([10000.1, 1e-08]), atol=2.) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_isfinite.py b/tests/test_Tensor_isfinite.py new file mode 100644 index 000000000..7c4b24bf4 --- /dev/null +++ b/tests/test_Tensor_isfinite.py @@ -0,0 +1,51 @@ +# Copyright (c) 2023 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.isfinite") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]).isfinite() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]) + result = input.isfinite() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([1, 6.9, 2]) + result = input.isfinite() + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_isinf.py b/tests/test_Tensor_isinf.py new file mode 100644 index 000000000..9ab5fe9a8 --- /dev/null +++ b/tests/test_Tensor_isinf.py @@ -0,0 +1,51 @@ +# Copyright (c) 2023 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.isinf") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]).isinf() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]) + result = input.isinf() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([1, 6.9, 2]) + result = input.isinf() + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_isnan.py b/tests/test_Tensor_isnan.py new file mode 100644 index 000000000..b95f9a771 --- /dev/null +++ b/tests/test_Tensor_isnan.py @@ -0,0 +1,51 @@ +# Copyright (c) 2023 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.isnan") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]).isnan() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]) + result = input.isnan() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([1, 6.9, 2]) + result = input.isnan() + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_kthvalue.py b/tests/test_Tensor_kthvalue.py new file mode 100644 index 000000000..338fde9a5 --- /dev/null +++ b/tests/test_Tensor_kthvalue.py @@ -0,0 +1,63 @@ +# Copyright (c) 2023 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.kthvalue") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([1., 2., 3., 4., 5.]) + result = x.kthvalue(4) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([[ 1., 2., 3.], [ 4., 5., 6.]]) + result = x.kthvalue(2, 0, True) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([[ 1., 2., 3.], [ 4., 5., 6.]]) + result = x.kthvalue(k=2, dim=0, keepdim=True) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([[ 1., 2., 3.], [ 4., 5., 6.]]) + result = x.kthvalue(k=2, dim=0, keepdim=True) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_lcm.py b/tests/test_Tensor_lcm.py new file mode 100644 index 000000000..b205198ae --- /dev/null +++ b/tests/test_Tensor_lcm.py @@ -0,0 +1,75 @@ +# Copyright (c) 2023 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.lcm") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([5, 10, 15]) + b = torch.tensor([3, 4, 5]) + result = a.lcm(b) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([5, 10, 15]) + b = torch.tensor([3, 4, 5]) + result = a.lcm(other=b) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([5, 10, 15]).lcm(torch.tensor([3, 4, 5])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([5, 10, 15]).lcm(other=torch.tensor([3, 4, 5])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([5, 10, 15]) + b = torch.tensor([3]) + result = a.lcm(other=b) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_le.py b/tests/test_Tensor_le.py new file mode 100644 index 000000000..d83e0d95a --- /dev/null +++ b/tests/test_Tensor_le.py @@ -0,0 +1,75 @@ +# Copyright (c) 2023 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.le") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[1, 2], [3, 4]]).le(torch.tensor([[1, 1], [4, 4]])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([[1, 1], [4, 4]]) + result = input.le(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([[1, 2], [3, 4]]) + result = input.le(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([1, 2]) + result = input.le(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[1, 2], [3, 4]]).le(2) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_lerp.py b/tests/test_Tensor_lerp.py new file mode 100644 index 000000000..dc210ffc0 --- /dev/null +++ b/tests/test_Tensor_lerp.py @@ -0,0 +1,68 @@ +# Copyright (c) 2023 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.lerp") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + start = torch.tensor([1., 2., 3., 4.]) + end = torch.tensor([10., 10., 10., 10.]) + weight = torch.tensor([0.5, 1, 0.3, 0.6]) + result = start.lerp(end, weight) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + weight = torch.tensor([0.5, 1, 0.3, 0.6]) + result = torch.tensor([1., 2., 3., 4.]).lerp(torch.tensor([10., 10., 10., 10.]), weight) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + start = torch.tensor([1., 2., 3., 4.]) + end = torch.tensor([10., 10., 10., 10.]) + weight = torch.tensor([0.5, 1, 0.3, 0.6]) + result = start.lerp(end=end, weight=weight) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + start = torch.tensor([1., 2., 3., 4.]) + end = torch.tensor([10., 10., 10., 10.]) + result = start.lerp(end=end, weight=0.5) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_lerp_.py b/tests/test_Tensor_lerp_.py new file mode 100644 index 000000000..aa3c2fa11 --- /dev/null +++ b/tests/test_Tensor_lerp_.py @@ -0,0 +1,68 @@ +# Copyright (c) 2023 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.lerp_") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + start = torch.tensor([1., 2., 3., 4.]) + end = torch.tensor([10., 10., 10., 10.]) + weight = torch.tensor([0.5, 1, 0.3, 0.6]) + result = start.lerp_(end, weight) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + weight = torch.tensor([0.5, 1, 0.3, 0.6]) + result = torch.tensor([1., 2., 3., 4.]).lerp_(torch.tensor([10., 10., 10., 10.]), weight) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + start = torch.tensor([1., 2., 3., 4.]) + end = torch.tensor([10., 10., 10., 10.]) + weight = torch.tensor([0.5, 1, 0.3, 0.6]) + result = start.lerp_(end=end, weight=weight) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + start = torch.tensor([1., 2., 3., 4.]) + end = torch.tensor([10., 10., 10., 10.]) + result = start.lerp_(end=end, weight=0.5) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_less.py b/tests/test_Tensor_less.py new file mode 100644 index 000000000..ca869de7a --- /dev/null +++ b/tests/test_Tensor_less.py @@ -0,0 +1,75 @@ +# Copyright (c) 2023 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.less") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[1, 2], [3, 4]]).less(torch.tensor([[1, 1], [4, 4]])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([[1, 1], [4, 4]]) + result = input.less(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([[1, 2], [3, 4]]) + result = input.less(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([1, 2]) + result = input.less(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[1, 2], [3, 4]]).less(2) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_less_equal.py b/tests/test_Tensor_less_equal.py new file mode 100644 index 000000000..473cc4aae --- /dev/null +++ b/tests/test_Tensor_less_equal.py @@ -0,0 +1,75 @@ +# Copyright (c) 2023 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.less_equal") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[1, 2], [3, 4]]).less_equal(torch.tensor([[1, 1], [4, 4]])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([[1, 1], [4, 4]]) + result = input.less_equal(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([[1, 2], [3, 4]]) + result = input.less_equal(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([1, 2]) + result = input.less_equal(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[1, 2], [3, 4]]).less_equal(2) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_lgamma.py b/tests/test_Tensor_lgamma.py new file mode 100644 index 000000000..6a8206c93 --- /dev/null +++ b/tests/test_Tensor_lgamma.py @@ -0,0 +1,52 @@ +# Copyright (c) 2023 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.lgamma") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([0.34, 1.5, 0.73]) + result = input.lgamma() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([0.34, 1.5, 0.73]).lgamma() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([0.34, 1.5, 0.73]) + result = input.lgamma() + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_log.py b/tests/test_Tensor_log.py new file mode 100644 index 000000000..73d4e9ce3 --- /dev/null +++ b/tests/test_Tensor_log.py @@ -0,0 +1,62 @@ +# Copyright (c) 2023 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.log") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([4.7767, 4.3234, 1.2156, 0.2411, 4.5739]) + result = input.log() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([4.7767, 4.3234, 1.2156, 0.2411, 4.5739]).log() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([4, 10, 7, 9]).log() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([4, 10, 7, 9]) + result = x.log() + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_log10.py b/tests/test_Tensor_log10.py new file mode 100644 index 000000000..5bcf7e7bf --- /dev/null +++ b/tests/test_Tensor_log10.py @@ -0,0 +1,51 @@ +# Copyright (c) 2023 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.log10") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([4.7767, 4.3234, 1.2156, 0.2411, 4.5739]) + result = input.log10() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([4.7767, 4.3234, 1.2156, 0.2411, 4.5739]).log10() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([4, 10, 7, 9]).log10() + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_log2.py b/tests/test_Tensor_log2.py new file mode 100644 index 000000000..400707ed7 --- /dev/null +++ b/tests/test_Tensor_log2.py @@ -0,0 +1,62 @@ +# Copyright (c) 2023 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.log2") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([4.7767, 4.3234, 1.2156, 0.2411, 4.5739]) + result = input.log2() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([4.7767, 4.3234, 1.2156, 0.2411, 4.5739]).log2() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([4, 10, 7, 9]).log2() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + x = torch.tensor([4, 10, 7, 9]) + result = x.log2() + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_logical_and.py b/tests/test_Tensor_logical_and.py new file mode 100644 index 000000000..d4d65018f --- /dev/null +++ b/tests/test_Tensor_logical_and.py @@ -0,0 +1,78 @@ +# Copyright (c) 2023 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.logical_and") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([True, False, True]).logical_and(torch.tensor([True, False, False])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.int8) + b = torch.tensor([4, 0, 1, 0], dtype=torch.int8) + result = a.logical_and(b) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.float32) + b = torch.tensor([4, 0, 1, 0], dtype=torch.float32) + result = a.logical_and(b) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.float32) + b = torch.tensor([4, 0, 1, 0], dtype=torch.float32) + result = torch.tensor([0, 1, 10., 0.]).logical_and(other=torch.tensor([4, 0, 10., 0.])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.float32) + b = torch.tensor([4, 0, 1, 0], dtype=torch.int8) + result = a.logical_and(b) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_logical_not.py b/tests/test_Tensor_logical_not.py new file mode 100644 index 000000000..ce4d11b05 --- /dev/null +++ b/tests/test_Tensor_logical_not.py @@ -0,0 +1,63 @@ +# Copyright (c) 2023 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.logical_not") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([True, False, True]).logical_not() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.int8) + result = a.logical_not() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.float32) + result = a.logical_not() + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.float32) + result = torch.tensor([0, 1, 10., 0.]).logical_not() + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_logical_or.py b/tests/test_Tensor_logical_or.py new file mode 100644 index 000000000..deeebc94f --- /dev/null +++ b/tests/test_Tensor_logical_or.py @@ -0,0 +1,78 @@ +# Copyright (c) 2023 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.logical_or") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([True, False, True]).logical_or(torch.tensor([True, False, False])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.int8) + b = torch.tensor([4, 0, 1, 0], dtype=torch.int8) + result = a.logical_or(b) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.float32) + b = torch.tensor([4, 0, 1, 0], dtype=torch.float32) + result = a.logical_or(b) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.float32) + b = torch.tensor([4, 0, 1, 0], dtype=torch.float32) + result = torch.tensor([0, 1, 10., 0.]).logical_or(other=torch.tensor([4, 0, 10., 0.])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.float32) + b = torch.tensor([4, 0, 1, 0], dtype=torch.int8) + result = a.logical_or(b) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_logical_xor.py b/tests/test_Tensor_logical_xor.py new file mode 100644 index 000000000..01dddbbec --- /dev/null +++ b/tests/test_Tensor_logical_xor.py @@ -0,0 +1,78 @@ +# Copyright (c) 2023 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.logical_xor") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([True, False, True]).logical_xor(torch.tensor([True, False, False])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.int8) + b = torch.tensor([4, 0, 1, 0], dtype=torch.int8) + result = a.logical_xor(b) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.float32) + b = torch.tensor([4, 0, 1, 0], dtype=torch.float32) + result = a.logical_xor(b) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.float32) + b = torch.tensor([4, 0, 1, 0], dtype=torch.float32) + result = torch.tensor([0, 1, 10., 0.]).logical_xor(other=torch.tensor([4, 0, 10., 0.])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + a = torch.tensor([0, 1, 10, 0], dtype=torch.float32) + b = torch.tensor([4, 0, 1, 0], dtype=torch.int8) + result = a.logical_xor(b) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_logit.py b/tests/test_Tensor_logit.py new file mode 100644 index 000000000..d717bc10e --- /dev/null +++ b/tests/test_Tensor_logit.py @@ -0,0 +1,53 @@ +# Copyright (c) 2023 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.logit") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516]) + result = input.logit(eps=1e-6) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516]) + eps = 1e-6 + result = input.logit(eps) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516]).logit(eps=1e-6) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_logsumexp.py b/tests/test_Tensor_logsumexp.py new file mode 100644 index 000000000..529dba85a --- /dev/null +++ b/tests/test_Tensor_logsumexp.py @@ -0,0 +1,75 @@ +# Copyright (c) 2023 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.logsumexp") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([1.4907, 1.0593, 1.5696]) + result = input.logsumexp(0) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]]) + result = input.logsumexp(1) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]]) + result = input.logsumexp(1, keepdim=True) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]]) + result = input.logsumexp(dim=1, keepdim=True) + """ + ) + obj.run(pytorch_code, ["result"]) + + +# paddle does not integer type +def _test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([1, 4, 6]) + result = input.logsumexp(0) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_Tensor_lt.py b/tests/test_Tensor_lt.py new file mode 100644 index 000000000..7454112e9 --- /dev/null +++ b/tests/test_Tensor_lt.py @@ -0,0 +1,75 @@ +# Copyright (c) 2023 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.lt") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[1, 2], [3, 4]]).lt(torch.tensor([[1, 1], [4, 4]])) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([[1, 1], [4, 4]]) + result = input.lt(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([[1, 2], [3, 4]]) + result = input.lt(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + input = torch.tensor([[1, 2], [3, 4]]) + other = torch.tensor([1, 2]) + result = input.lt(other) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.tensor([[1, 2], [3, 4]]).lt(2) + """ + ) + obj.run(pytorch_code, ["result"]) diff --git a/tests/test_is_complex.py b/tests/test_is_complex.py index 90db19379..b2e390495 100644 --- a/tests/test_is_complex.py +++ b/tests/test_is_complex.py @@ -16,7 +16,7 @@ from apibase import APIBase -obj = APIBase("torch.is_tensor") +obj = APIBase("torch.is_complex") def test_case_1():