Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add standard_t function to numpy frontend #21549

Merged
8 changes: 8 additions & 0 deletions ivy/functional/frontends/numpy/random/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ def standard_normal(size=None):
return ivy.random_normal(mean=0.0, std=1.0, shape=size, dtype="float64")


@to_ivy_arrays_and_back
@from_zero_dim_arrays_to_scalar
def standard_t(df, size=None):
numerator = ivy.random_normal(mean=0.0, std=1.0, shape=size, dtype="float64")
denominator = ivy.gamma(df / 2, 1.0, shape=size, dtype="float64")
return ivy.sqrt(df / 2) * ivy.divide(numerator, ivy.sqrt(denominator))


@to_ivy_arrays_and_back
@from_zero_dim_arrays_to_scalar
def triangular(left, mode, right, size=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,41 @@ def test_numpy_standard_normal(
)


# standard_t
@handle_frontend_test(
fn_tree="numpy.random.standard_t",
df=st.floats(min_value=1, max_value=20),
df_dtypes=helpers.get_dtypes("integer", full=False),
size=st.tuples(
st.integers(min_value=2, max_value=5), st.integers(min_value=2, max_value=5)
),
size_dtypes=helpers.get_dtypes("integer", full=False),
test_with_out=st.just(False),
)
def test_numpy_standard_t(
df,
df_dtypes,
size,
size_dtypes,
frontend,
test_flags,
fn_tree,
backend_fw,
on_device,
):
helpers.test_frontend_function(
input_dtypes=df_dtypes + size_dtypes,
backend_to_test=backend_fw,
test_flags=test_flags,
frontend=frontend,
fn_tree=fn_tree,
on_device=on_device,
test_values=False,
df=df,
size=size,
)


@handle_frontend_test(
fn_tree="numpy.random.triangular",
input_dtypes=helpers.get_dtypes("float"),
Expand Down