From 1f41b195ba981e20792b87bc8a737b543cc1a7dd Mon Sep 17 00:00:00 2001 From: niixxaaa Date: Sun, 19 Nov 2023 19:50:02 +0400 Subject: [PATCH 1/2] feat: Add __rpow__ method to PaddleTensor class --- .../frontends/paddle/tensor/tensor.py | 7 ++++ .../test_paddle/test_tensor/test_tensor.py | 42 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/ivy/functional/frontends/paddle/tensor/tensor.py b/ivy/functional/frontends/paddle/tensor/tensor.py index 42d40604532f0..835b34973f6ad 100644 --- a/ivy/functional/frontends/paddle/tensor/tensor.py +++ b/ivy/functional/frontends/paddle/tensor/tensor.py @@ -191,6 +191,13 @@ def __iter__(self): def __rmul__(self, y, /, name=None): return paddle_frontend.multiply(self, y) + @with_unsupported_dtypes( + {"2.5.2 and below": ("bool", "unsigned", "int8", "float16", "bfloat16")}, + "paddle", + ) + def __rpow__(self, y, /, name=None): + return paddle_frontend.pow(y, self) + # Instance Methods # # ---------------- # diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py index 525de3a57a643..7d5755589e0bc 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py @@ -868,6 +868,48 @@ def test_paddle_abs( ) +# __rpow__ +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="paddle.to_tensor", + method_name="__rpow__", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("numeric"), + num_arrays=2, + min_value=1, + ), +) +def test_paddle__rpow__( + dtype_and_x, + frontend_method_data, + init_flags, + method_flags, + frontend, + on_device, + backend_fw, +): + input_dtype, x = dtype_and_x + dtype = input_dtype[0] + if "int" in dtype: + x[0] = ivy.abs(x[0]) + helpers.test_frontend_method( + init_input_dtypes=input_dtype, + backend_to_test=backend_fw, + init_all_as_kwargs_np={ + "data": x[0], + }, + method_input_dtypes=input_dtype, + method_all_as_kwargs_np={ + "other": x[1], + }, + frontend_method_data=frontend_method_data, + init_flags=init_flags, + method_flags=method_flags, + frontend=frontend, + on_device=on_device, + ) + + # acosh @handle_frontend_method( class_tree=CLASS_TREE, From 84faf992560f747df917fe1442aae4e3ebaef181 Mon Sep 17 00:00:00 2001 From: ivy-branch Date: Sun, 19 Nov 2023 15:51:03 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A4=96=20Lint=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontends/paddle/tensor/tensor.py | 2 +- .../test_paddle/test_tensor/test_tensor.py | 60 +++++++++---------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/ivy/functional/frontends/paddle/tensor/tensor.py b/ivy/functional/frontends/paddle/tensor/tensor.py index 835b34973f6ad..4c382af1b7ca1 100644 --- a/ivy/functional/frontends/paddle/tensor/tensor.py +++ b/ivy/functional/frontends/paddle/tensor/tensor.py @@ -197,7 +197,7 @@ def __rmul__(self, y, /, name=None): ) def __rpow__(self, y, /, name=None): return paddle_frontend.pow(y, self) - + # Instance Methods # # ---------------- # diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py index 7d5755589e0bc..68c2ef820abe3 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py @@ -794,92 +794,97 @@ def test_paddle__rmul__( ) -# __rsub__ +# __rpow__ @handle_frontend_method( class_tree=CLASS_TREE, init_tree="paddle.to_tensor", - method_name="__rsub__", + method_name="__rpow__", dtype_and_x=helpers.dtype_and_values( available_dtypes=helpers.get_dtypes("numeric"), num_arrays=2, - shared_dtype=True, + min_value=1, ), ) -def test_paddle__rsub__( +def test_paddle__rpow__( dtype_and_x, - frontend, frontend_method_data, init_flags, method_flags, - backend_fw, + frontend, on_device, + backend_fw, ): input_dtype, x = dtype_and_x + dtype = input_dtype[0] + if "int" in dtype: + x[0] = ivy.abs(x[0]) helpers.test_frontend_method( init_input_dtypes=input_dtype, backend_to_test=backend_fw, init_all_as_kwargs_np={ - "value": x[0], + "data": x[0], }, method_input_dtypes=input_dtype, method_all_as_kwargs_np={ - "x": x[1], + "other": x[1], }, - frontend=frontend, frontend_method_data=frontend_method_data, init_flags=init_flags, method_flags=method_flags, + frontend=frontend, on_device=on_device, ) -# abs +# __rsub__ @handle_frontend_method( class_tree=CLASS_TREE, init_tree="paddle.to_tensor", - method_name="abs", + method_name="__rsub__", dtype_and_x=helpers.dtype_and_values( - available_dtypes=helpers.get_dtypes("float"), + available_dtypes=helpers.get_dtypes("numeric"), + num_arrays=2, + shared_dtype=True, ), ) -def test_paddle_abs( +def test_paddle__rsub__( dtype_and_x, + frontend, frontend_method_data, init_flags, method_flags, - frontend, - on_device, backend_fw, + on_device, ): input_dtype, x = dtype_and_x helpers.test_frontend_method( init_input_dtypes=input_dtype, backend_to_test=backend_fw, init_all_as_kwargs_np={ - "data": x[0], + "value": x[0], }, method_input_dtypes=input_dtype, - method_all_as_kwargs_np={}, + method_all_as_kwargs_np={ + "x": x[1], + }, + frontend=frontend, frontend_method_data=frontend_method_data, init_flags=init_flags, method_flags=method_flags, - frontend=frontend, on_device=on_device, ) -# __rpow__ +# abs @handle_frontend_method( class_tree=CLASS_TREE, init_tree="paddle.to_tensor", - method_name="__rpow__", + method_name="abs", dtype_and_x=helpers.dtype_and_values( - available_dtypes=helpers.get_dtypes("numeric"), - num_arrays=2, - min_value=1, + available_dtypes=helpers.get_dtypes("float"), ), ) -def test_paddle__rpow__( +def test_paddle_abs( dtype_and_x, frontend_method_data, init_flags, @@ -889,9 +894,6 @@ def test_paddle__rpow__( backend_fw, ): input_dtype, x = dtype_and_x - dtype = input_dtype[0] - if "int" in dtype: - x[0] = ivy.abs(x[0]) helpers.test_frontend_method( init_input_dtypes=input_dtype, backend_to_test=backend_fw, @@ -899,9 +901,7 @@ def test_paddle__rpow__( "data": x[0], }, method_input_dtypes=input_dtype, - method_all_as_kwargs_np={ - "other": x[1], - }, + method_all_as_kwargs_np={}, frontend_method_data=frontend_method_data, init_flags=init_flags, method_flags=method_flags,