From 621b94436c45aba0a8373b1c2fda72fd53214379 Mon Sep 17 00:00:00 2001 From: kundakinte <69470630+kundakinte@users.noreply.github.com> Date: Wed, 4 Oct 2023 17:22:57 +0300 Subject: [PATCH 1/3] added max pool 3D test to test_pooling.py --- .../test_nn/test_functional/test_pooling.py | 35 +++++++++++++++++++ 1 file changed, 35 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 881592b4e143a..04b80ec6e1e65 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 @@ -306,3 +306,38 @@ def test_paddle_max_unpool1d( stride=stride, padding=padding, ) + + +# max_pool3d +@handle_frontend_test( + fn_tree="paddle.nn.functional.max_pool3d", + x_k_s_p=helpers.arrays_for_pooling(min_dims=5, max_dims=5, min_side=1, max_side=5), + stride=st.tuples(st.integers(1, 2), st.integers(1, 2)), + test_with_out=st.just(False), +) +def test_paddle_max_pool3d( + *, + x_k_s_p, + stride, + data_format, + frontend, + test_flags, + fn_tree, + backend_fw, + on_device, +): + input_dtype, x, kernel_size, _, padding = x_k_s_p + data_format = data_format + helpers.test_frontend_function( + input_dtypes=input_dtype, + backend_to_test=backend_fw, + frontend=frontend, + test_flags=test_flags, + fn_tree=fn_tree, + on_device=on_device, + x=x[0], + kernel_size=kernel_size, + stride=stride, + padding=padding, + data_format=data_format, + ) From 07d9c72011f69ca93fe091084bc1e7cfb7ae3989 Mon Sep 17 00:00:00 2001 From: kundakinte <69470630+kundakinte@users.noreply.github.com> Date: Wed, 4 Oct 2023 17:23:33 +0300 Subject: [PATCH 2/3] added max pool 3d to pooling.py --- .../frontends/paddle/nn/functional/pooling.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/ivy/functional/frontends/paddle/nn/functional/pooling.py b/ivy/functional/frontends/paddle/nn/functional/pooling.py index b40b468ed7441..829f92bf0da5a 100644 --- a/ivy/functional/frontends/paddle/nn/functional/pooling.py +++ b/ivy/functional/frontends/paddle/nn/functional/pooling.py @@ -113,3 +113,40 @@ def max_unpool1d( name=None, ): return ivy.max_unpool1d(x, indices, kernel_size, stride, padding, data_format) + + +@to_ivy_arrays_and_back +@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle") +def max_pool3d( + x, + kernel_size, + stride=None, + padding=0, + return_mask=False, + ceil_mode=False, + data_format='NCDHW', + name=None +): + if stride is None: + stride = kernel_size + 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.max_pool3d( + x, + kernel_size, + stride, + padding, + return_mask=return_mask, + ceil_mode=ceil_mode, + data_format=data_format + ) + From a08a92f8d703091107ef1b3cbfd8d4edfb24ea21 Mon Sep 17 00:00:00 2001 From: ivy-branch Date: Wed, 4 Oct 2023 14:50:04 +0000 Subject: [PATCH 3/3] =?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/nn/functional/pooling.py | 3 +- .../test_nn/test_functional/test_pooling.py | 54 +++++++++---------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/ivy/functional/frontends/paddle/nn/functional/pooling.py b/ivy/functional/frontends/paddle/nn/functional/pooling.py index 829f92bf0da5a..d6df8b1dd99d1 100644 --- a/ivy/functional/frontends/paddle/nn/functional/pooling.py +++ b/ivy/functional/frontends/paddle/nn/functional/pooling.py @@ -138,7 +138,7 @@ def max_pool3d( padding = "SAME" else: padding = "VALID" - + return ivy.max_pool3d( x, @@ -149,4 +149,3 @@ def max_pool3d( ceil_mode=ceil_mode, data_format=data_format ) - 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 04b80ec6e1e65..53c809052b873 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 @@ -276,68 +276,68 @@ def test_paddle_avg_pool2d( ) -# max_unpool1d +# max_pool3d @handle_frontend_test( - fn_tree="paddle.nn.functional.max_unpool1d", - x_k_s_p=helpers.arrays_for_pooling(min_dims=3, max_dims=3, min_side=1, max_side=4), - indices=st.lists(st.integers(0, 1), min_size=1, max_size=4), + fn_tree="paddle.nn.functional.max_pool3d", + x_k_s_p=helpers.arrays_for_pooling(min_dims=5, max_dims=5, min_side=1, max_side=5), + stride=st.tuples(st.integers(1, 2), st.integers(1, 2)), + test_with_out=st.just(False), ) -def test_paddle_max_unpool1d( +def test_paddle_max_pool3d( *, x_k_s_p, - indices, - test_flags, + stride, + data_format, frontend, - on_device, - backend_fw, + test_flags, fn_tree, + backend_fw, + on_device, ): - (input_dtype, x, kernel_size, stride, padding) = x_k_s_p + input_dtype, x, kernel_size, _, padding = x_k_s_p + data_format = data_format helpers.test_frontend_function( input_dtypes=input_dtype, backend_to_test=backend_fw, frontend=frontend, test_flags=test_flags, - on_device=on_device, fn_tree=fn_tree, + on_device=on_device, x=x[0], - indices=indices, kernel_size=kernel_size, stride=stride, padding=padding, + data_format=data_format, ) -# max_pool3d +# max_unpool1d @handle_frontend_test( - fn_tree="paddle.nn.functional.max_pool3d", - x_k_s_p=helpers.arrays_for_pooling(min_dims=5, max_dims=5, min_side=1, max_side=5), - stride=st.tuples(st.integers(1, 2), st.integers(1, 2)), - test_with_out=st.just(False), + fn_tree="paddle.nn.functional.max_unpool1d", + x_k_s_p=helpers.arrays_for_pooling(min_dims=3, max_dims=3, min_side=1, max_side=4), + indices=st.lists(st.integers(0, 1), min_size=1, max_size=4), ) -def test_paddle_max_pool3d( +def test_paddle_max_unpool1d( *, x_k_s_p, - stride, - data_format, - frontend, + indices, test_flags, - fn_tree, - backend_fw, + frontend, on_device, + backend_fw, + fn_tree, ): - input_dtype, x, kernel_size, _, padding = x_k_s_p - data_format = data_format + (input_dtype, x, kernel_size, stride, padding) = x_k_s_p helpers.test_frontend_function( input_dtypes=input_dtype, backend_to_test=backend_fw, frontend=frontend, test_flags=test_flags, - fn_tree=fn_tree, on_device=on_device, + fn_tree=fn_tree, x=x[0], + indices=indices, kernel_size=kernel_size, stride=stride, padding=padding, - data_format=data_format, )