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

For double sided maxwell #21264

Merged
merged 22 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion ivy/functional/frontends/jax/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def pareto(key, b, shape=None, dtype="float64"):
@to_ivy_arrays_and_back
@with_unsupported_dtypes(
{
"0.3.14 and below": (
"0.4.14 and below": (
"float16",
"bfloat16",
)
Expand All @@ -328,6 +328,31 @@ def maxwell(key, shape=None, dtype="float64"):
return x


@handle_jax_dtype
@to_ivy_arrays_and_back
@with_unsupported_dtypes(
stalemate1 marked this conversation as resolved.
Show resolved Hide resolved
{
"0.4.14 and below": (
"float16",
"bfloat16",
)
},
"jax",
)
def double_sided_maxwell(key, loc, scale, shape=(), dtype="float64"):
seed = _get_seed(key)
x = ivy.random_normal(seed=seed, shape=shape, dtype=dtype)
z_1 = ivy.subtract(x, loc)
if scale != 0:
z = z_1 / scale
maxwell = (z**2) * ivy.exp(-(z**2) / 2)
coefficient = 1 / (2 * ivy.pi * scale)
double_maxwell = ivy.multiply(coefficient, maxwell)
else:
double_maxwell = ivy.full(shape, loc)
return double_maxwell


@handle_jax_dtype
@to_ivy_arrays_and_back
@with_supported_dtypes(
Expand Down
61 changes: 61 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_jax/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,67 @@ def call():
assert u.shape == v.shape


@pytest.mark.xfail
@handle_frontend_test(
fn_tree="jax.random.double_sided_maxwell",
dtype_key=helpers.dtype_and_values(
available_dtypes=["uint32"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are specifying the dtype here, this should be valid dtype and the dtypes that should be skipped should be added in the decorator above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and pass in valid here, so that the decorator skips the dtypes which are not to be tested on. Rather than us trying to restrict those in the tests.

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(),
dtype=helpers.get_dtypes("float", full=False),
loc=st.integers(min_value=10, max_value=100),
scale=st.floats(min_value=0, max_value=100, exclude_min=True),
test_with_out=st.just(False),
)
def test_jax_double_sided_maxwell(
*,
dtype_key,
loc,
scale,
shape,
dtype,
on_device,
fn_tree,
frontend,
test_flags,
backend_fw,
):
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,
backend_to_test=backend_fw,
key=key[0],
loc=loc,
scale=scale,
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(backend=backend_fw, ret=ret_np)
ret_from_np = helpers.flatten_and_to_np(backend=backend_fw, ret=ret_from_np)
for u, v in zip(ret_np, ret_from_np):
assert u.dtype == v.dtype
assert u.shape == v.shape


@pytest.mark.xfail
@handle_frontend_test(
fn_tree="jax.random.ball",
Expand Down
Loading