Repository: ivy-llc/ivy

Issue:
loggamma



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
@@ -172,11 +172,13 @@ def randint(key, shape, minval, maxval, dtype="int64"):
     seed = _get_seed(key)
     return ivy.randint(minval, maxval, shape=shape, dtype=dtype, seed=seed)
 
+
 @to_ivy_arrays_and_back
 def bernoulli(key, p=0.5, shape=None):
     seed = _get_seed(key)
     return ivy.bernoulli(p, shape=shape, seed=seed)
 
+
 @to_ivy_arrays_and_back
 def fold_in(key, data):
     s = ivy.bitwise_left_shift(
@@ -184,6 +186,7 @@ def fold_in(key, data):
     )
     return ivy.bitwise_xor(key, s)
 
+
 @to_ivy_arrays_and_back
 def permutation(key, x, axis=0, independent=False):
     x = ivy.array(x)
@@ -196,3 +199,21 @@ def permutation(key, x, axis=0, independent=False):
     rand = ivy.arange(x.shape[axis])
     ind = ivy.shuffle(rand, 0, seed=seed)
     return ivy.gather(x, ind, axis=axis)
+
+
+# loggamma
+@to_ivy_arrays_and_back
+@handle_jax_dtype
+@to_ivy_arrays_and_back
+@with_unsupported_dtypes(
+    {
+        "0.3.14 and below": (
+            "float16",
+            "bfloat16",
+        )
+    },
+    "jax",
+)
+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))


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
@@ -849,7 +849,7 @@ def call():
         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(
@@ -902,3 +902,61 @@ def call():
     for u, v in zip(ret_np, ret_from_np):
         assert u.dtype == v.dtype
         assert u.shape == v.shape
+
+
+# loggamma
+# TODO Update the test by fixing the uint32 unsupported problem
+@pytest.mark.xfail
+@handle_frontend_test(
+    fn_tree="jax.random.loggamma",
+    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,
+    ),
+    a_shape=_all_gamma_params(),
+    dtype=helpers.get_dtypes("float", full=False),
+    test_with_out=st.just(False),
+)
+def test_jax_loggamma(
+    *,
+    dtype_key,
+    a_shape,
+    dtype,
+    on_device,
+    fn_tree,
+    frontend,
+    test_flags,
+):
+    input_dtype, key = dtype_key
+    a, shape = a_shape
+
+    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],
+            a=a,
+            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