From ec4ba9bc057a4dafd90175832e4e975278cc59d1 Mon Sep 17 00:00:00 2001 From: ivy-branch Date: Fri, 29 Sep 2023 08:06:25 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Lint=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/overview/contributing/error_handling.rst | 4 +- ivy/functional/frontends/paddle/math.py | 11 +-- .../non_linear_activation_functions.py | 4 - .../test_frontends/test_paddle/test_math.py | 19 ++--- .../test_torch/test_utilities.py | 80 ++++++++++--------- 5 files changed, 62 insertions(+), 56 deletions(-) diff --git a/docs/overview/contributing/error_handling.rst b/docs/overview/contributing/error_handling.rst index f5f9e52ab82e5..be30a9796d38c 100644 --- a/docs/overview/contributing/error_handling.rst +++ b/docs/overview/contributing/error_handling.rst @@ -39,7 +39,7 @@ This section, "Error Handling" aims to assist you in navigating through some com **Solution:** - As we are explicitly passing in a `dtype` which is not supported in the torch framework itself so torch backend fails here, a possible fix is adding the dtype in the unsupported dtype decoartor which would look something like this. + As we are explicitly passing in a `dtype` which is not supported in the torch framework itself so torch backend fails here, a possible fix is adding the dtype in the unsupported dtype decoartor which would look something like this. .. code-block:: python @@ -77,7 +77,7 @@ This section, "Error Handling" aims to assist you in navigating through some com **Solution:** - As both the results are pretty close to each others in this case, adding an `rtol = 10^-3` and `atol = 10^-3` would fix the failing tests here. + As both the results are pretty close to each others in this case, adding an `rtol = 10^-3` and `atol = 10^-3` would fix the failing tests here. .. code-block:: python diff --git a/ivy/functional/frontends/paddle/math.py b/ivy/functional/frontends/paddle/math.py index 9aa3af3555b2c..37c1765c18acd 100644 --- a/ivy/functional/frontends/paddle/math.py +++ b/ivy/functional/frontends/paddle/math.py @@ -338,6 +338,12 @@ def log(x, name=None): return ivy.log(x) +@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle") +@to_ivy_arrays_and_back +def log10(x, name=None): + return ivy.log10(x) + + @with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle") @to_ivy_arrays_and_back def log1p(x, name=None): @@ -349,11 +355,6 @@ def log1p(x, name=None): def log2(x, name=None): return ivy.log2(x) -@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle") -@to_ivy_arrays_and_back -def log10(x, name=None): - return ivy.log10(x) - @with_unsupported_dtypes({"2.5.1 and below": ("float16", "bfloat16")}, "paddle") @to_ivy_arrays_and_back diff --git a/ivy/functional/frontends/torch/nn/functional/non_linear_activation_functions.py b/ivy/functional/frontends/torch/nn/functional/non_linear_activation_functions.py index 27e2fa525cbef..79d3a7d8f1d1a 100644 --- a/ivy/functional/frontends/torch/nn/functional/non_linear_activation_functions.py +++ b/ivy/functional/frontends/torch/nn/functional/non_linear_activation_functions.py @@ -4,10 +4,6 @@ from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back -# --- Main --- # -# ------------ # - - @to_ivy_arrays_and_back def celu(input, alpha=1.0, inplace=False): prod = ivy.multiply( diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py index 096f73f9f7974..f8cddeca9b1ed 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py @@ -1413,15 +1413,13 @@ def test_paddle_log( ) -# log1p @handle_frontend_test( - fn_tree="paddle.log1p", + fn_tree="paddle.log10", dtype_and_x=helpers.dtype_and_values( available_dtypes=helpers.get_dtypes("valid"), - max_value=1e5, ), ) -def test_paddle_log1p( +def test_paddle_log10( *, dtype_and_x, on_device, @@ -1442,14 +1440,15 @@ def test_paddle_log1p( ) -# log2 +# log1p @handle_frontend_test( - fn_tree="paddle.log2", + fn_tree="paddle.log1p", dtype_and_x=helpers.dtype_and_values( available_dtypes=helpers.get_dtypes("valid"), + max_value=1e5, ), ) -def test_paddle_log2( +def test_paddle_log1p( *, dtype_and_x, on_device, @@ -1469,13 +1468,15 @@ def test_paddle_log2( x=x[0], ) + +# log2 @handle_frontend_test( - fn_tree="paddle.log10", + fn_tree="paddle.log2", dtype_and_x=helpers.dtype_and_values( available_dtypes=helpers.get_dtypes("valid"), ), ) -def test_paddle_log10( +def test_paddle_log2( *, dtype_and_x, on_device, diff --git a/ivy_tests/test_ivy/test_frontends/test_torch/test_utilities.py b/ivy_tests/test_ivy/test_frontends/test_torch/test_utilities.py index 8fcae08acbf55..6956ffa3f2a68 100644 --- a/ivy_tests/test_ivy/test_frontends/test_torch/test_utilities.py +++ b/ivy_tests/test_ivy/test_frontends/test_torch/test_utilities.py @@ -6,6 +6,50 @@ from ivy_tests.test_ivy.helpers import handle_frontend_test +# --- Helpers --- # +# --------------- # + + +@st.composite +def _elemwise_helper(draw): + value_strategy = st.one_of( + helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("valid"), + ), + st.integers(min_value=-10000, max_value=10000), + st.floats(min_value=-10000, max_value=10000), + ) + + dtype_and_x1 = draw(value_strategy) + if isinstance(dtype_and_x1, tuple): + dtype1 = dtype_and_x1[0] + x1 = dtype_and_x1[1][0] + else: + dtype1 = [] + x1 = dtype_and_x1 + + dtype_and_x2 = draw(value_strategy) + if isinstance(dtype_and_x2, tuple): + dtype2 = dtype_and_x2[0] + x2 = dtype_and_x2[1][0] + else: + dtype2 = [] + x2 = dtype_and_x2 + + num_pos_args = None + if not dtype1 and not dtype2: + num_pos_args = 2 + elif not dtype1: + x1, x2 = x2, x1 + input_dtypes = dtype1 + dtype2 + + return x1, x2, input_dtypes, num_pos_args + + +# --- Main --- # +# ------------ # + + # ToDo: Fix this test after torch overide of assert is implemented # @handle_frontend_test( # fn_tree="torch._assert", @@ -74,42 +118,6 @@ def test_torch_bincount( ) -@st.composite -def _elemwise_helper(draw): - value_strategy = st.one_of( - helpers.dtype_and_values( - available_dtypes=helpers.get_dtypes("valid"), - ), - st.integers(min_value=-10000, max_value=10000), - st.floats(min_value=-10000, max_value=10000), - ) - - dtype_and_x1 = draw(value_strategy) - if isinstance(dtype_and_x1, tuple): - dtype1 = dtype_and_x1[0] - x1 = dtype_and_x1[1][0] - else: - dtype1 = [] - x1 = dtype_and_x1 - - dtype_and_x2 = draw(value_strategy) - if isinstance(dtype_and_x2, tuple): - dtype2 = dtype_and_x2[0] - x2 = dtype_and_x2[1][0] - else: - dtype2 = [] - x2 = dtype_and_x2 - - num_pos_args = None - if not dtype1 and not dtype2: - num_pos_args = 2 - elif not dtype1: - x1, x2 = x2, x1 - input_dtypes = dtype1 + dtype2 - - return x1, x2, input_dtypes, num_pos_args - - @handle_frontend_test( fn_tree="torch.result_type", dtypes_and_xs=_elemwise_helper(),