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 minimum in mathematical function #3696

Merged
merged 3 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import ivy

#minimum

def minimum(
x1,
x2,
/,
out=None,
*,
where=True,
casting="same_kind",
order="K",
dtype=None,
subok=True
):
if dtype:
x1 = ivy.astype(ivy.array(x1), ivy.as_ivy_dtype(dtype))
x2 = ivy.astype(ivy.array(x2), ivy.as_ivy_dtype(dtype))
ret = ivy.minimum(x1, x2, out=out)
if ivy.is_array(where):
ret = ivy.where(where, ret, ivy.default(out, ivy.zeros_like(ret)), out=out)
return ret

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# global
import numpy as np
from hypothesis import given, strategies as st

# local
import ivy_tests.test_ivy.helpers as helpers
import ivy.functional.backends.numpy as ivy_np
import ivy_tests.test_ivy.test_frontends.test_numpy.helpers as np_frontend_helpers
from ivy_tests.test_ivy.helpers import handle_cmd_line_args


# minimum
@handle_cmd_line_args
@given(
dtype_and_x=helpers.dtype_and_values(
available_dtypes=ivy_np.valid_float_dtypes,num_arrays=2
),
dtype=st.sampled_from(ivy_np.valid_float_dtypes + (None,)),
where=np_frontend_helpers.where(),
as_variable=helpers.array_bools(),
juliagsy marked this conversation as resolved.
Show resolved Hide resolved
num_positional_args=helpers.num_positional_args(
fn_name="ivy.functional.frontends.numpy.minimum"
),
native_array=helpers.array_bools(),
)
def test_numpy_minimum(
dtype_and_x,
dtype,
where,
as_variable,
with_out,
num_positional_args,
native_array,
fw,
):
input_dtype, x = dtype_and_x
where = np_frontend_helpers.handle_where_and_array_bools(
where=where,
input_dtype=input_dtype,
as_variable=as_variable,
native_array=native_array,

)
np_frontend_helpers.test_frontend_function(
input_dtypes=input_dtype,
as_variable_flags=as_variable,
with_out=with_out,
num_positional_args=num_positional_args,
native_array_flags=native_array,
fw=fw,
frontend="numpy",
fn_tree="minimum",
x1=np.asarray(x[0], dtype=input_dtype[0]),
x2=np.asarray(x[1], dtype=input_dtype[1]),
out=None,
where=where,
casting="same_kind",
order="k",
dtype=dtype,
subok=True,
test_values=False,
)