Repository: ivy-llc/ivy

Issue:
shuffle



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/jax/random.py b/ivy/functional/frontends/jax/random.py
--- a/ivy/functional/frontends/jax/random.py
+++ b/ivy/functional/frontends/jax/random.py
@@ -217,3 +217,28 @@ def permutation(key, x, axis=0, independent=False):
 def loggamma(key, a, shape=None, dtype="float64"):
     seed = _get_seed(key)
     return ivy.log(ivy.gamma(a, 1.0, shape=shape, dtype=dtype, seed=seed))
+
+
+@to_ivy_arrays_and_back
+def shuffle(key, x, axis=0):
+    seed = _get_seed(key)
+    x = ivy.flip(x, axis=axis)
+    return ivy.shuffle(x, seed=seed)
+
+
+@handle_jax_dtype
+@to_ivy_arrays_and_back
+@with_unsupported_dtypes(
+    {
+        "0.3.14 and below": (
+            "float16",
+            "bfloat16",
+        )
+    },
+    "jax",
+)
+def exponential(key, shape=(), dtype="float64"):
+    seed = _get_seed(key)
+    uniform = ivy.random_uniform(seed=seed, shape=shape, dtype=dtype)
+    exp = -ivy.log(1 - uniform)
+    return exp


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_jax/test_jax_random.py b/ivy_tests/test_ivy/test_frontends/test_jax/test_jax_random.py
--- a/ivy_tests/test_ivy/test_frontends/test_jax/test_jax_random.py
+++ b/ivy_tests/test_ivy/test_frontends/test_jax/test_jax_random.py
@@ -960,3 +960,115 @@ def call():
     for u, v in zip(ret_np, ret_from_np):
         assert u.dtype == v.dtype
         assert u.shape == v.shape
+
+
+# TODO Update the test by fixing the uint32 unsupported problem
+@pytest.mark.xfail
+@handle_frontend_test(
+    fn_tree="jax.random.shuffle",
+    dtype_key=helpers.dtype_and_values(
+        available_dtypes=["uint32"],
+        min_value=0,
+        max_value=2000,
+        min_num_dims=1,
+        max_num_dims=1,
+        min_dim_size=2,
+        max_dim_size=2,
+    ),
+    dtype_x_axis=helpers.dtype_values_axis(
+        available_dtypes=("float32", "float64"),
+        valid_axis=True,
+        max_axes_size=1,
+        force_int_axis=True,
+    ),
+)
+def test_jax_shuffle(
+    *,
+    dtype_key,
+    dtype_x_axis,
+    on_device,
+    fn_tree,
+    frontend,
+    test_flags,
+):
+    key_dtype, key = dtype_key
+    x_dtypes, x, axis = dtype_x_axis
+
+    def call():
+        return helpers.test_frontend_function(
+            input_dtypes=key_dtype + x_dtypes,
+            frontend=frontend,
+            test_flags=test_flags,
+            fn_tree=fn_tree,
+            on_device=on_device,
+            test_values=False,
+            key=key[0],
+            x=x[0],
+            axis=axis,
+        )
+
+    ret = call()
+
+    if not ivy.exists(ret):
+        return
+
+    ret_np, ret_from_np = ret
+    ret_np = helpers.flatten_and_to_np(ret=ret_np)
+    ret_from_np = helpers.flatten_and_to_np(ret=ret_from_np)
+    for u, v in zip(ret_np, ret_from_np):
+        assert u.dtype == v.dtype
+        assert u.shape == v.shape
+
+
+# TODO Update the test by fixing the uint32 unsupported problem
+@pytest.mark.xfail
+@handle_frontend_test(
+    fn_tree="jax.random.exponential",
+    dtype_key=helpers.dtype_and_values(
+        available_dtypes=["uint32"],
+        min_value=0,
+        max_value=2000,
+        min_num_dims=1,
+        max_num_dims=1,
+        min_dim_size=2,
+        max_dim_size=2,
+    ),
+    shape=helpers.get_shape(allow_none=False, min_num_dims=1, min_dim_size=1),
+    dtype=helpers.get_dtypes("float", full=False),
+)
+def test_jax_exponential(
+    *,
+    dtype_key,
+    shape,
+    dtype,
+    on_device,
+    fn_tree,
+    frontend,
+    test_flags,
+):
+    input_dtype, key = dtype_key
+
+    def call():
+        return helpers.test_frontend_function(
+            input_dtypes=input_dtype,
+            frontend=frontend,
+            test_flags=test_flags,
+            fn_tree=fn_tree,
+            on_device=on_device,
+            test_values=False,
+            key=key[0],
+            shape=shape,
+            dtype=dtype[0],
+        )
+
+    ret = call()
+
+    if not ivy.exists(ret):
+        return
+
+    ret_np, ret_from_np = ret
+    ret_np = helpers.flatten_and_to_np(ret=ret_np)
+    ret_from_np = helpers.flatten_and_to_np(ret=ret_from_np)
+    for u, v in zip(ret_np, ret_from_np):
+        assert u.dtype == v.dtype
+        assert u.shape == v.shape