From ff8f7935af81df7b8f98d0be18ef918f9baa1ab1 Mon Sep 17 00:00:00 2001 From: FelixHuyghe <46262936+FelixHuyghe@users.noreply.github.com> Date: Sun, 6 Aug 2023 14:31:22 +0200 Subject: [PATCH 1/4] add increment method --- .../frontends/paddle/tensor/math.py | 14 +++++++++++ .../test_paddle/test_tensor/test_math.py | 23 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/ivy/functional/frontends/paddle/tensor/math.py b/ivy/functional/frontends/paddle/tensor/math.py index 2f96acfb67617..18ec2d68bd73b 100644 --- a/ivy/functional/frontends/paddle/tensor/math.py +++ b/ivy/functional/frontends/paddle/tensor/math.py @@ -412,3 +412,17 @@ def any(x, axis=None, keepdim=False, name=None): @to_ivy_arrays_and_back def diff(x, n=1, axis=-1, prepend=None, append=None, name=None): return ivy.diff(x, n=n, axis=axis, prepend=prepend, append=append) + + +@with_supported_dtypes( + {"2.5.0 and below": ("float32", "float64", "int32", "int64")}, "paddle" +) +@to_ivy_arrays_and_back +def increment(x, value=1.0): + if x.size == 1: + return ivy.inplace_increment(x, value) + else: + raise ValueError( + "The number of elements in Input(X) should be 1.Now the number is" + f" {x.size}." + ) diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py index fd144b11125f4..ef987d4ee25a4 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py @@ -951,7 +951,7 @@ def test_paddle_lgamma( test_flags=test_flags, fn_tree=fn_tree, on_device=on_device, - atol=1E-4, + atol=1e-4, x=x[0], ) @@ -1864,3 +1864,24 @@ def test_paddle_diff( prepend=prepend[0], append=append[0], ) + + +def test_paddle_increment( + *, + dtype_and_input_and_label, + frontend, + test_flags, + fn_tree, + backend_fw, +): + input_dtypes, input_and_label = dtype_and_input_and_label + input, label = input_and_label + helpers.test_frontend_function( + input_dtypes=input_dtypes, + backend_to_test=backend_fw, + frontend=frontend, + test_flags=test_flags, + fn_tree=fn_tree, + input=input, + label=label, + ) From abfd76bb1b7b7b31164adfec39443a5509faf144 Mon Sep 17 00:00:00 2001 From: FelixHuyghe <46262936+FelixHuyghe@users.noreply.github.com> Date: Sun, 6 Aug 2023 14:39:43 +0200 Subject: [PATCH 2/4] Update test_math.py fix casing --- .../test_frontends/test_paddle/test_tensor/test_math.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py index ef987d4ee25a4..ad5798c46be42 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py @@ -951,7 +951,7 @@ def test_paddle_lgamma( test_flags=test_flags, fn_tree=fn_tree, on_device=on_device, - atol=1e-4, + atol=1E-4, x=x[0], ) From 40e81a470de8d93c5deff696f99f5a6c3ffb361d Mon Sep 17 00:00:00 2001 From: FelixHuyghe Date: Wed, 30 Aug 2023 23:13:08 +0800 Subject: [PATCH 3/4] add testing, test not working --- .../frontends/paddle/tensor/math.py | 11 ++++---- .../test_paddle/test_tensor/test_math.py | 27 ++++++++++++++----- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/ivy/functional/frontends/paddle/tensor/math.py b/ivy/functional/frontends/paddle/tensor/math.py index 18ec2d68bd73b..f8e477fa280d3 100644 --- a/ivy/functional/frontends/paddle/tensor/math.py +++ b/ivy/functional/frontends/paddle/tensor/math.py @@ -1,8 +1,11 @@ # global + import ivy from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes from ivy.functional.frontends.paddle.func_wrapper import to_ivy_arrays_and_back +import paddle + @with_unsupported_dtypes({"2.5.1 and below": ("float16", "bfloat16")}, "paddle") @to_ivy_arrays_and_back @@ -415,14 +418,12 @@ def diff(x, n=1, axis=-1, prepend=None, append=None, name=None): @with_supported_dtypes( - {"2.5.0 and below": ("float32", "float64", "int32", "int64")}, "paddle" + {"2.5.1 and below": ("float32", "float64", "int32", "int64")}, "paddle" ) @to_ivy_arrays_and_back def increment(x, value=1.0): if x.size == 1: return ivy.inplace_increment(x, value) else: - raise ValueError( - "The number of elements in Input(X) should be 1.Now the number is" - f" {x.size}." - ) + # Call paddle to return the correct exception + return paddle.increment(paddle.to_tensor(ivy.to_native(x)), value) diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py index ad5798c46be42..3945452348861 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py @@ -5,6 +5,8 @@ import ivy_tests.test_ivy.helpers as helpers from ivy_tests.test_ivy.helpers import handle_frontend_test +from hypothesis import reproduce_failure + # sin @handle_frontend_test( @@ -951,7 +953,7 @@ def test_paddle_lgamma( test_flags=test_flags, fn_tree=fn_tree, on_device=on_device, - atol=1E-4, + atol=1e-4, x=x[0], ) @@ -1866,22 +1868,35 @@ def test_paddle_diff( ) +# increment +@reproduce_failure("6.82.7", b"AXicY2BkAAE4CWEAAABJAAU=") +@handle_frontend_test( + fn_tree="paddle.tensor.math.increment", + dtype_and_x_and_value=helpers.dtype_and_values( + num_arrays=2, + available_dtypes=helpers.get_dtypes("valid"), + min_num_dims=1, + min_dim_size=1, + ), +) def test_paddle_increment( *, - dtype_and_input_and_label, + dtype_and_x_and_value, frontend, test_flags, fn_tree, backend_fw, ): - input_dtypes, input_and_label = dtype_and_input_and_label - input, label = input_and_label + input_dtypes, x_and_value = dtype_and_x_and_value + value = x_and_value[1] + # Get a single element from the array to use as value parameter + value_first_element = value[0].item() helpers.test_frontend_function( input_dtypes=input_dtypes, backend_to_test=backend_fw, frontend=frontend, test_flags=test_flags, fn_tree=fn_tree, - input=input, - label=label, + x=x_and_value[0], + value=value_first_element, ) From 89ae69192d92d8da2e9554b03772da2c793ce379 Mon Sep 17 00:00:00 2001 From: FelixHuyghe Date: Thu, 7 Sep 2023 18:39:51 +0800 Subject: [PATCH 4/4] add copy and datatype matching --- .../frontends/paddle/tensor/math.py | 9 +++-- .../test_paddle/test_tensor/test_math.py | 36 ++++++++++++------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/ivy/functional/frontends/paddle/tensor/math.py b/ivy/functional/frontends/paddle/tensor/math.py index f8e477fa280d3..b0255158ff585 100644 --- a/ivy/functional/frontends/paddle/tensor/math.py +++ b/ivy/functional/frontends/paddle/tensor/math.py @@ -4,8 +4,6 @@ from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes from ivy.functional.frontends.paddle.func_wrapper import to_ivy_arrays_and_back -import paddle - @with_unsupported_dtypes({"2.5.1 and below": ("float16", "bfloat16")}, "paddle") @to_ivy_arrays_and_back @@ -423,7 +421,8 @@ def diff(x, n=1, axis=-1, prepend=None, append=None, name=None): @to_ivy_arrays_and_back def increment(x, value=1.0): if x.size == 1: - return ivy.inplace_increment(x, value) + return ivy.inplace_increment(ivy.copy_array(x), value) else: - # Call paddle to return the correct exception - return paddle.increment(paddle.to_tensor(ivy.to_native(x)), value) + return ValueError( + "(InvalidArgument) The number of elements in Input(X) should be 1." + ) diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py index 3945452348861..b819b6a520f76 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py @@ -1,12 +1,13 @@ # global + from hypothesis import strategies as st +import ivy + # local import ivy_tests.test_ivy.helpers as helpers from ivy_tests.test_ivy.helpers import handle_frontend_test -from hypothesis import reproduce_failure - # sin @handle_frontend_test( @@ -1869,34 +1870,43 @@ def test_paddle_diff( # increment -@reproduce_failure("6.82.7", b"AXicY2BkAAE4CWEAAABJAAU=") @handle_frontend_test( fn_tree="paddle.tensor.math.increment", - dtype_and_x_and_value=helpers.dtype_and_values( - num_arrays=2, - available_dtypes=helpers.get_dtypes("valid"), + dtype_and_x=helpers.dtype_and_values( + available_dtypes=st.shared(helpers.get_dtypes("valid"), key="dtype"), + min_num_dims=1, + max_num_dims=1, + min_dim_size=1, + max_dim_size=1, + ), + dtype_and_value=helpers.dtype_and_values( + available_dtypes=st.shared(helpers.get_dtypes("float"), key="dtype"), min_num_dims=1, min_dim_size=1, + max_num_dims=1, ), ) def test_paddle_increment( *, - dtype_and_x_and_value, + dtype_and_x, + dtype_and_value, frontend, test_flags, fn_tree, backend_fw, ): - input_dtypes, x_and_value = dtype_and_x_and_value - value = x_and_value[1] - # Get a single element from the array to use as value parameter - value_first_element = value[0].item() + input_dtypes, x = dtype_and_x + value_dtypes, value = dtype_and_value + # Match the data type of x and value to sum them up + x[0], value[0] = ivy.promote_types_of_inputs(x[0], value[0]) + value_first_element = value[0].item(0) + helpers.test_frontend_function( - input_dtypes=input_dtypes, + input_dtypes=[ivy.dtype(x[0]), ivy.dtype(value[0])], backend_to_test=backend_fw, frontend=frontend, test_flags=test_flags, fn_tree=fn_tree, - x=x_and_value[0], + x=x[0], value=value_first_element, )