From 8f98fcd49a63b8e091d5c235c6b661e3b6875254 Mon Sep 17 00:00:00 2001 From: KaylaMLe Date: Fri, 25 Aug 2023 23:30:04 -0700 Subject: [PATCH 1/4] added paddlepaddle avg_pool3d --- .../frontends/paddle/nn/functional/pooling.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/ivy/functional/frontends/paddle/nn/functional/pooling.py b/ivy/functional/frontends/paddle/nn/functional/pooling.py index b40b468ed7441..c1f06f1304d23 100644 --- a/ivy/functional/frontends/paddle/nn/functional/pooling.py +++ b/ivy/functional/frontends/paddle/nn/functional/pooling.py @@ -8,6 +8,46 @@ from ivy.func_wrapper import with_unsupported_dtypes +@to_ivy_arrays_and_back +@with_unsupported_dtypes({"2.5.1 and below": ("float16", "bfloat16")}, "paddle") +def avg_pool3d( + x, + kernel_size, + stride=None, + padding=0, + ceil_mode=False, + exclusive=True, + divisor_override=None, + data_format="NDHWC", + name=None, +): + if stride is None: + stride = kernel_size + + count_include_pad = not exclusive + kernel_size = _broadcast_pooling_helper(kernel_size, "3d", name="kernel_size") + padding = _broadcast_pooling_helper(padding, "3d", name="padding") + + # Figure out padding string + if all( + [pad == ivy.ceil((kernel - 1) / 2) for kernel, pad in zip(kernel_size, padding)] + ): + padding = "SAME" + else: + padding = "VALID" + + return ivy.avg_pool3d( + x, + kernel_size, + stride, + padding, + data_format=data_format, + count_include_pad=count_include_pad, + ceil_mode=ceil_mode, + divisor_override=divisor_override, + ) + + @to_ivy_arrays_and_back @with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle") def adaptive_avg_pool1d(x, output_size, name=None): From 3dcb2549e3158b6db785c1b4ebf9b87fb64caa66 Mon Sep 17 00:00:00 2001 From: KaylaMLe Date: Sat, 26 Aug 2023 00:11:21 -0700 Subject: [PATCH 2/4] added test --- .../test_nn/test_functional/test_pooling.py | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_pooling.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_pooling.py index 8bba5d93b0f77..3e00523d4014e 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_pooling.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_pooling.py @@ -9,6 +9,66 @@ ) +# avg_pool3d +@handle_frontend_test( + fn_tree="paddle.nn.functional.pooling.avg_pool3d", + dtype_x_k_s=helpers.arrays_for_pooling( + min_dims=4, + max_dims=4, + min_side=2, + max_side=4, + ), + ceil_mode=st.booleans(), + exclusive=st.booleans(), + data_format=st.sampled_from(["NDHWC", "NCDHW"]), +) +def test_paddle_avg_pool3d( + df_x_k_s_p, + exclusive, + ceil_mode, + data_format, + *, + test_flags, + backend_fw, + frontend, + fn_tree, + on_device, +): + input_df, x, kernel, stride, padding = df_x_k_s_p + + if data_format == "NCDHW": + x[0] = x[0].reshape( + (x[0].shape[0], x[0].shape[4], x[0].shape[1], x[0].shape[2], x[0].shape[3]) + ) + + if len(stride) == 1: + stride = (stride[0], stride[0], stride[0]) + + if padding == "SAME": + padding = test_pooling_functions.calculate_same_padding( + kernel, stride, x[0].shape[2:] + ) + else: + padding = (0, 0, 0) + + helpers.test_frontend_function( + input_dtypes=input_df, + test_flags=test_flags, + backend_to_test=backend_fw, + frontend=frontend, + fn_tree=fn_tree, + on_device=on_device, + x=x[0], + kernel_size=kernel, + stride=stride, + padding=padding, + ceil_mode=ceil_mode, + exclusive=exclusive, + divisor_override=None, + data_format=data_format, + ) + + # avg_pool2d @handle_frontend_test( fn_tree="paddle.nn.functional.pooling.avg_pool2d", From 3fd1c55fccfec4aaaae3737ec6bd1d910baacf69 Mon Sep 17 00:00:00 2001 From: KaylaMLe Date: Sat, 26 Aug 2023 10:16:49 -0700 Subject: [PATCH 3/4] lint fix --- .../test_paddle/test_nn/test_functional/test_pooling.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_pooling.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_pooling.py index 3e00523d4014e..ff02784d1069a 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_pooling.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_pooling.py @@ -40,7 +40,6 @@ def test_paddle_avg_pool3d( x[0] = x[0].reshape( (x[0].shape[0], x[0].shape[4], x[0].shape[1], x[0].shape[2], x[0].shape[3]) ) - if len(stride) == 1: stride = (stride[0], stride[0], stride[0]) From cdd6a0139150a7a6dd2bfc7a7ccb42d5ebb11ad8 Mon Sep 17 00:00:00 2001 From: KaylaMLe Date: Sat, 26 Aug 2023 10:16:49 -0700 Subject: [PATCH 4/4] pre-commit lint fixes --- .../FactorizedTensor/tucker_tensor.py | 2 +- .../frontends/paddle/nn/functional/pooling.py | 80 +++++++++---------- .../frontends/paddle/tensor/tensor.py | 2 +- .../frontends/scipy/func_wrapper.py | 1 - .../test_nn/test_functional/test_pooling.py | 1 - .../test_scipy/test_fft/test_fft.py | 1 - .../test_scipy/test_linalg/test_linalg.py | 1 - 7 files changed, 42 insertions(+), 46 deletions(-) diff --git a/ivy/data_classes/FactorizedTensor/tucker_tensor.py b/ivy/data_classes/FactorizedTensor/tucker_tensor.py index a3f06749e721b..f0f212a937482 100644 --- a/ivy/data_classes/FactorizedTensor/tucker_tensor.py +++ b/ivy/data_classes/FactorizedTensor/tucker_tensor.py @@ -236,7 +236,7 @@ def validate_tucker_rank( tensor_shape, rank="same", rounding="round", fixed_modes=None ): from scipy.optimize import brentq - + if rounding == "ceil": rounding_fun = ivy.ceil elif rounding == "floor": diff --git a/ivy/functional/frontends/paddle/nn/functional/pooling.py b/ivy/functional/frontends/paddle/nn/functional/pooling.py index c1f06f1304d23..4890029b75d0c 100644 --- a/ivy/functional/frontends/paddle/nn/functional/pooling.py +++ b/ivy/functional/frontends/paddle/nn/functional/pooling.py @@ -8,46 +8,6 @@ from ivy.func_wrapper import with_unsupported_dtypes -@to_ivy_arrays_and_back -@with_unsupported_dtypes({"2.5.1 and below": ("float16", "bfloat16")}, "paddle") -def avg_pool3d( - x, - kernel_size, - stride=None, - padding=0, - ceil_mode=False, - exclusive=True, - divisor_override=None, - data_format="NDHWC", - name=None, -): - if stride is None: - stride = kernel_size - - count_include_pad = not exclusive - kernel_size = _broadcast_pooling_helper(kernel_size, "3d", name="kernel_size") - padding = _broadcast_pooling_helper(padding, "3d", name="padding") - - # Figure out padding string - if all( - [pad == ivy.ceil((kernel - 1) / 2) for kernel, pad in zip(kernel_size, padding)] - ): - padding = "SAME" - else: - padding = "VALID" - - return ivy.avg_pool3d( - x, - kernel_size, - stride, - padding, - data_format=data_format, - count_include_pad=count_include_pad, - ceil_mode=ceil_mode, - divisor_override=divisor_override, - ) - - @to_ivy_arrays_and_back @with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle") def adaptive_avg_pool1d(x, output_size, name=None): @@ -140,6 +100,46 @@ def avg_pool2d( ) +@to_ivy_arrays_and_back +@with_unsupported_dtypes({"2.5.1 and below": ("float16", "bfloat16")}, "paddle") +def avg_pool3d( + x, + kernel_size, + stride=None, + padding=0, + ceil_mode=False, + exclusive=True, + divisor_override=None, + data_format="NDHWC", + name=None, +): + if stride is None: + stride = kernel_size + + count_include_pad = not exclusive + kernel_size = _broadcast_pooling_helper(kernel_size, "3d", name="kernel_size") + padding = _broadcast_pooling_helper(padding, "3d", name="padding") + + # Figure out padding string + if all( + [pad == ivy.ceil((kernel - 1) / 2) for kernel, pad in zip(kernel_size, padding)] + ): + padding = "SAME" + else: + padding = "VALID" + + return ivy.avg_pool3d( + x, + kernel_size, + stride, + padding, + data_format=data_format, + count_include_pad=count_include_pad, + ceil_mode=ceil_mode, + divisor_override=divisor_override, + ) + + @to_ivy_arrays_and_back @with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle") def max_unpool1d( diff --git a/ivy/functional/frontends/paddle/tensor/tensor.py b/ivy/functional/frontends/paddle/tensor/tensor.py index bd09e50dc5a45..aff16d83ca294 100644 --- a/ivy/functional/frontends/paddle/tensor/tensor.py +++ b/ivy/functional/frontends/paddle/tensor/tensor.py @@ -632,4 +632,4 @@ def std(self, axis=None, unbiased=True, keepdim=False, name=None): {"2.5.1 and below": ("int32", "int64", "float32", "float64")}, "paddle" ) def trunc(self, name=None): - return paddle_frontend.Tensor(ivy.trunc(self._ivy_array)) \ No newline at end of file + return paddle_frontend.Tensor(ivy.trunc(self._ivy_array)) diff --git a/ivy/functional/frontends/scipy/func_wrapper.py b/ivy/functional/frontends/scipy/func_wrapper.py index 566e4467784b1..e69de29bb2d1d 100644 --- a/ivy/functional/frontends/scipy/func_wrapper.py +++ b/ivy/functional/frontends/scipy/func_wrapper.py @@ -1 +0,0 @@ -from ivy.functional.frontends.numpy.func_wrapper import to_ivy_arrays_and_back \ No newline at end of file diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_pooling.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_pooling.py index 3e00523d4014e..ff02784d1069a 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_pooling.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_pooling.py @@ -40,7 +40,6 @@ def test_paddle_avg_pool3d( x[0] = x[0].reshape( (x[0].shape[0], x[0].shape[4], x[0].shape[1], x[0].shape[2], x[0].shape[3]) ) - if len(stride) == 1: stride = (stride[0], stride[0], stride[0]) diff --git a/ivy_tests/test_ivy/test_frontends/test_scipy/test_fft/test_fft.py b/ivy_tests/test_ivy/test_frontends/test_scipy/test_fft/test_fft.py index 45b60249c0949..8384db2426fd7 100644 --- a/ivy_tests/test_ivy/test_frontends/test_scipy/test_fft/test_fft.py +++ b/ivy_tests/test_ivy/test_frontends/test_scipy/test_fft/test_fft.py @@ -1,6 +1,5 @@ # global from hypothesis import strategies as st -import pytest # local import ivy_tests.test_ivy.helpers as helpers diff --git a/ivy_tests/test_ivy/test_frontends/test_scipy/test_linalg/test_linalg.py b/ivy_tests/test_ivy/test_frontends/test_scipy/test_linalg/test_linalg.py index 87c54f882b128..5444d9b047f9b 100644 --- a/ivy_tests/test_ivy/test_frontends/test_scipy/test_linalg/test_linalg.py +++ b/ivy_tests/test_ivy/test_frontends/test_scipy/test_linalg/test_linalg.py @@ -4,7 +4,6 @@ import sys from hypothesis import strategies as st import numpy as np -import pytest # local import ivy_tests.test_ivy.helpers as helpers