Skip to content

Commit

Permalink
feat(frontends): added Numpy's logseries
Browse files Browse the repository at this point in the history
Co-authored-by: ivy-branch <[email protected]>
Reviewed-by: KareemMAX <[email protected]>
Refs: #22719
  • Loading branch information
Tanzeel161 and ivy-branch authored Aug 31, 2023
1 parent ea86da1 commit ca35d22
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ivy/functional/frontends/numpy/random/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ca35d22

Please sign in to comment.