Repository: ivy-llc/ivy

Issue:
polyint



Discussion:
This issue has been labelled as stale. If you would like to continue working on this issue, then please add another comment or create a PR . If a PR has already been created which refers to this issue, then you should explicitly mention this issue in the relevant PR. For more information please refer to this page in our documentation: https://lets-unify.ai/ivy/contributing/1_the_basics.html#todo-list-issues
working on it

Resolving patch:
diff --git a/ivy/functional/frontends/jax/numpy/mathematical_functions.py b/ivy/functional/frontends/jax/numpy/mathematical_functions.py
--- a/ivy/functional/frontends/jax/numpy/mathematical_functions.py
+++ b/ivy/functional/frontends/jax/numpy/mathematical_functions.py
@@ -596,6 +596,32 @@ def polyder(p, m=1):
     return result
 
 
+@with_unsupported_dtypes(
+    {"0.3.14 and below": ("float16",)},
+    "jax",
+)
+@to_ivy_arrays_and_back
+def polyint(p, m=1, k=None):
+    p = ivy.asarray(p)
+    m = int(m)
+    if m == 0:
+        return p
+    if k is None:
+        k_arr = ivy.zeros((m,), dtype=p.dtype)
+    elif isinstance(k, (int, float)):
+        k_arr = ivy.full((m,), k, dtype=p.dtype)
+    elif ivy.asarray(k).shape == (1,):
+        k_arr = ivy.full((m,), ivy.asarray(k)[0], dtype=p.dtype)
+    elif ivy.asarray(k).shape == (m,):
+        k_arr = ivy.asarray(k, dtype=p.dtype)
+    else:
+        raise ValueError("k must be a scalar or a rank-1 array of length 1 or m.")
+    grid = (ivy.arange(p.size + m, dtype=p.dtype)[ivy.newaxis]
+            - ivy.arange(m, dtype=p.dtype)[:, ivy.newaxis])
+    coeff = ivy.maximum(1, grid).prod(axis=0)[::-1]
+    return ivy.divide(ivy.concat((p, k_arr)), coeff).astype(p.dtype)
+
+
 @to_ivy_arrays_and_back
 def polysub(a1, a2):
     n = max(a1.size, a2.size) - 1


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_jax/test_jax_numpy_math.py b/ivy_tests/test_ivy/test_frontends/test_jax/test_jax_numpy_math.py
--- a/ivy_tests/test_ivy/test_frontends/test_jax/test_jax_numpy_math.py
+++ b/ivy_tests/test_ivy/test_frontends/test_jax/test_jax_numpy_math.py
@@ -2676,6 +2676,52 @@ def test_jax_numpy_polyder(
     )
 
 
+# polyint
+@st.composite
+def _get_array_values_m_and_k(draw):
+    dtype_and_x= draw(helpers.dtype_and_values(
+        available_dtypes=helpers.get_dtypes("float"),
+        num_arrays=1,
+        min_num_dims=1,
+        max_num_dims=1,
+        min_dim_size=1,
+        )
+    )
+    dtype, x = dtype_and_x
+    m = draw(st.integers(min_value=0, max_value=10))
+    max_bound = m-1
+    if max_bound <= m:
+        k = None
+    else:
+        k = draw(st.integers(min_value=0, max_value=max_bound))
+    return dtype, x, m, k
+
+
+@handle_frontend_test(
+    fn_tree="jax.numpy.polyint",
+    dtype_and_x_and_k=_get_array_values_m_and_k(),
+)
+def test_jax_numpy_polyint(
+    *,
+    dtype_and_x_and_k,
+    test_flags,
+    on_device,
+    fn_tree,
+    frontend,
+):
+    input_dtype, x, m, k = dtype_and_x_and_k
+    helpers.test_frontend_function(
+        input_dtypes=input_dtype,
+        test_flags=test_flags,
+        frontend=frontend,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        p=x[0],
+        m=m,
+        k=k,
+    )
+
+
 # polysub
 @handle_frontend_test(
     fn_tree="jax.numpy.polysub",