From ca35d225aec7bb7ba8a848926dc429e0ee1c6659 Mon Sep 17 00:00:00 2001 From: Shah Tanzeel Ahmed <141497653+Tanzeel161@users.noreply.github.com> Date: Thu, 31 Aug 2023 17:03:02 +0500 Subject: [PATCH] feat(frontends): added Numpy's `logseries` Co-authored-by: ivy-branch Reviewed-by: KareemMAX Refs: #22719 --- .../frontends/numpy/random/functions.py | 13 +++++++ .../test_numpy/test_random/test_functions.py | 36 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/ivy/functional/frontends/numpy/random/functions.py b/ivy/functional/frontends/numpy/random/functions.py index 10db884f2be0c..8c794d902a945 100644 --- a/ivy/functional/frontends/numpy/random/functions.py +++ b/ivy/functional/frontends/numpy/random/functions.py @@ -101,6 +101,19 @@ def lognormal(mean=0.0, sigma=1.0, size=None): return ret +@to_ivy_arrays_and_back +@from_zero_dim_arrays_to_scalar +def logseries(p=0, size=None): + if p < 0 or p >= 1: + raise ValueError("p value must be in the open interval (0, 1)") + r = ivy.log(1 - p) + u = ivy.random_uniform(low=0.0, high=1.0, shape=size) + v = ivy.random_uniform(low=0.0, high=1.0, shape=size) + q = 1 - ivy.exp(r * u) + ret = 1 + ivy.log(v) / ivy.log(q) + return ret + + @to_ivy_arrays_and_back @from_zero_dim_arrays_to_scalar def multinomial(n, pvals, size=None): diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py index b2cae02335ca7..240c61bd6063f 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_random/test_functions.py @@ -439,6 +439,42 @@ def test_numpy_lognormal( ) +@handle_frontend_test( + fn_tree="numpy.random.logseries", + input_dtypes=helpers.get_dtypes("float", index=2), + p=st.floats( + allow_nan=False, + allow_infinity=False, + min_value=0, + max_value=1, + exclude_max=True, + ), + size=helpers.get_shape(allow_none=True), + test_with_out=st.just(False), +) +def test_numpy_logseries( + input_dtypes, + frontend, + test_flags, + fn_tree, + backend_fw, + on_device, + p, + size, +): + helpers.test_frontend_function( + input_dtypes=input_dtypes, + backend_to_test=backend_fw, + test_flags=test_flags, + frontend=frontend, + fn_tree=fn_tree, + on_device=on_device, + test_values=False, + p=p, + size=size, + ) + + # multinomial @handle_frontend_test( fn_tree="numpy.random.multinomial",