Repository: ivy-llc/ivy

Issue:
interpolate



Discussion:
[interpolate] #19489

Resolving patch:
diff --git a/ivy/functional/frontends/paddle/nn/functional/common.py b/ivy/functional/frontends/paddle/nn/functional/common.py
--- a/ivy/functional/frontends/paddle/nn/functional/common.py
+++ b/ivy/functional/frontends/paddle/nn/functional/common.py
@@ -87,6 +87,23 @@ def zeropad2d(x, padding, data_format="NCHW", name=None):
     return ivy.pad(x, padding, mode="constant", constant_values=0.0)
 
 
+@to_ivy_arrays_and_back
+@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle")
+def interpolate(
+    x,
+    size=None,
+    scale_factor=None,
+    mode="nearest",
+    align_corners=False,
+    align_mode=0,
+    data_format="NCHW",
+    name=None,
+):
+    return ivy.interpolate(
+        x, size, mode=mode, scale_factor=scale_factor, align_corners=align_corners
+    )
+
+
 @to_ivy_arrays_and_back
 @with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle")
 def linear(x, weight, bias=None, name=None):


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_common.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_common.py
--- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_common.py
+++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_nn/test_functional/test_common.py
@@ -200,6 +200,193 @@ def test_paddle_zeropad2d(
     )
 
 
+# interpolate
+@st.composite
+def _interp_args(draw, mode=None, mode_list=None):
+    mixed_fn_compos = draw(st.booleans())
+    curr_backend = ivy.current_backend_str()
+    torch_modes = [
+        "linear",
+        "bilinear",
+        "trilinear",
+        "nearest",
+        "nearest-exact",
+        "area",
+    ]
+
+    tf_modes = [
+        "linear",
+        "bilinear",
+        "trilinear",
+        "nearest-exact",
+        "tf_area",
+        "bicubic_tensorflow",
+        "lanczos3",
+        "lanczos5",
+        "mitchellcubic",
+        "gaussian",
+    ]
+
+    jax_modes = [
+        "linear",
+        "bilinear",
+        "trilinear",
+        "nearest-exact",
+        "bicubic_tensorflow",
+        "lanczos3",
+        "lanczos5",
+    ]
+
+    if not mode and not mode_list:
+        if curr_backend == "torch" and not mixed_fn_compos:
+            mode = draw(st.sampled_from(torch_modes))
+        elif curr_backend == "tensorflow" and not mixed_fn_compos:
+            mode = draw(st.sampled_from(tf_modes))
+        elif curr_backend == "jax" and not mixed_fn_compos:
+            mode = draw(st.sampled_from(jax_modes))
+        else:
+            mode = draw(
+                st.sampled_from(
+                    [
+                        "linear",
+                        "bilinear",
+                        "trilinear",
+                        "nearest",
+                        "nearest-exact",
+                        "area",
+                        "tf_area",
+                        "bicubic_tensorflow",
+                        "lanczos3",
+                        "lanczos5",
+                        "mitchellcubic",
+                        "gaussian",
+                    ]
+                )
+            )
+    elif mode_list:
+        mode = draw(st.sampled_from(mode_list))
+    align_corners = draw(st.booleans())
+    if (curr_backend == "tensorflow" or curr_backend == "jax") and not mixed_fn_compos:
+        align_corners = False
+    if mode == "linear":
+        num_dims = 3
+    elif mode in [
+        "bilinear",
+        "bicubic_tensorflow",
+        "bicubic",
+        "mitchellcubic",
+        "gaussian",
+    ]:
+        num_dims = 4
+    elif mode == "trilinear":
+        num_dims = 5
+    elif mode in [
+        "nearest",
+        "area",
+        "tf_area",
+        "lanczos3",
+        "lanczos5",
+        "nearest-exact",
+    ]:
+        num_dims = (
+            draw(
+                helpers.ints(min_value=1, max_value=3, mixed_fn_compos=mixed_fn_compos)
+            )
+            + 2
+        )
+        align_corners = False
+    if curr_backend == "tensorflow" and not mixed_fn_compos:
+        num_dims = 3
+    dtype, x = draw(
+        helpers.dtype_and_values(
+            available_dtypes=helpers.get_dtypes(
+                "float", mixed_fn_compos=mixed_fn_compos
+            ),
+            min_num_dims=num_dims,
+            max_num_dims=num_dims,
+            min_dim_size=2,
+            max_dim_size=5,
+            large_abs_safety_factor=50,
+            small_abs_safety_factor=50,
+            safety_factor_scale="log",
+        )
+    )
+    if draw(st.booleans()):
+        scale_factor = draw(
+            st.one_of(
+                helpers.lists(
+                    x=helpers.floats(
+                        min_value=1.0, max_value=2.0, mixed_fn_compos=mixed_fn_compos
+                    ),
+                    min_size=num_dims - 2,
+                    max_size=num_dims - 2,
+                ),
+                helpers.floats(
+                    min_value=1.0, max_value=2.0, mixed_fn_compos=mixed_fn_compos
+                ),
+            )
+        )
+        recompute_scale_factor = draw(st.booleans())
+        size = None
+    else:
+        size = draw(
+            st.one_of(
+                helpers.lists(
+                    x=helpers.ints(
+                        min_value=1, max_value=3, mixed_fn_compos=mixed_fn_compos
+                    ),
+                    min_size=num_dims - 2,
+                    max_size=num_dims - 2,
+                ),
+                st.integers(min_value=1, max_value=3),
+            )
+        )
+        recompute_scale_factor = False
+        scale_factor = None
+    if (curr_backend == "tensorflow" or curr_backend == "jax") and not mixed_fn_compos:
+        if not recompute_scale_factor:
+            recompute_scale_factor = True
+
+    return (dtype, x, mode, size, align_corners, scale_factor, recompute_scale_factor)
+
+
+@handle_frontend_test(
+    fn_tree="paddle.nn.functional.common.interpolate",
+    dtype_x_mode=_interp_args(),
+)
+def test_paddle_interpolate(
+    dtype_x_mode,
+    on_device,
+    fn_tree,
+    frontend,
+    backend_fw,
+    test_flags,
+):
+    (
+        input_dtype,
+        x,
+        mode,
+        size,
+        align_corners,
+        scale_factor,
+        recompute_scale_factor,
+    ) = dtype_x_mode
+
+    helpers.test_frontend_function(
+        input_dtypes=input_dtype,
+        frontend=frontend,
+        backend_to_test=backend_fw,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        x=x[0],
+        size=size,
+        scale_factor=scale_factor,
+        mode=mode,
+        align_corners=align_corners,
+    )
+
+
 # linear
 @handle_frontend_test(
     fn_tree="paddle.nn.functional.common.linear",