Skip to content

Commit

Permalink
feat: add Numpy min frontend function and its test (#27391)
Browse files Browse the repository at this point in the history
Co-authored-by: NripeshN <[email protected]>
  • Loading branch information
alvin-98 and NripeshN authored Nov 25, 2023
1 parent 039ac59 commit 1948300
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ def amin(
return ivy.astype(res, out_dtype, out=out, copy=False)


@handle_numpy_out
@to_ivy_arrays_and_back
@from_zero_dim_arrays_to_scalar
def min(
a,
/,
*,
axis=None,
out=None,
keepdims=False,
initial=None,
where=True,
):
return amin(a, axis=axis, out=out, keepdims=keepdims, initial=initial, where=where)


@handle_numpy_out
@to_ivy_arrays_and_back
@from_zero_dim_arrays_to_scalar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,55 @@ def test_numpy_maximum(
)


@handle_frontend_test(
fn_tree="numpy.min",
dtype_x_axis=helpers.dtype_values_axis(
available_dtypes=helpers.get_dtypes("float"),
min_num_dims=1,
valid_axis=True,
force_int_axis=True,
large_abs_safety_factor=2,
safety_factor_scale="log",
),
initial=st.one_of(st.floats(min_value=-1000, max_value=1000), st.none()),
keepdims=st.booleans(),
where=np_frontend_helpers.where(),
)
def test_numpy_min(
dtype_x_axis,
frontend,
test_flags,
fn_tree,
backend_fw,
on_device,
where,
initial,
keepdims,
):
if initial is None and np.all(where) is not True:
assume(initial is inf)

input_dtypes, x, axis = dtype_x_axis
where, input_dtypes, test_flags = np_frontend_helpers.handle_where_and_array_bools(
where=where,
input_dtype=input_dtypes,
test_flags=test_flags,
)
np_frontend_helpers.test_frontend_function(
input_dtypes=input_dtypes,
backend_to_test=backend_fw,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
a=x[0],
axis=axis,
keepdims=keepdims,
initial=initial,
where=where,
)


# minimum
@handle_frontend_test(
fn_tree="numpy.minimum",
Expand Down

0 comments on commit 1948300

Please sign in to comment.