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

numpy frontend square #2655

Merged
merged 1 commit into from
Aug 8, 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
Expand Up @@ -69,8 +69,8 @@ def divide(
if ivy.is_array(where):
ret = ivy.where(where, ret, ivy.default(out, ivy.zeros_like(ret)), out=out)
return ret


def multiply(
x1,
x2,
Expand All @@ -93,3 +93,26 @@ def multiply(


multiply.unsupported_dtypes = {"torch": ("float16",)}


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


square.unsupported_dtypes = {"torch": ("float16",)}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_numpy_divide(
subok=True,
test_values=False,
)


# multiply
@given(
Expand Down Expand Up @@ -214,3 +214,52 @@ def test_numpy_multiply(
subok=True,
test_values=False,
)


# square
@given(
dtype_and_x=helpers.dtype_and_values(available_dtypes=ivy_np.valid_numeric_dtypes),
dtype=st.sampled_from(ivy_np.valid_numeric_dtypes + (None,)),
where=np_frontend_helpers.where(),
as_variable=helpers.array_bools(),
with_out=st.booleans(),
num_positional_args=helpers.num_positional_args(
fn_name="ivy.functional.frontends.numpy.square"
),
native_array=helpers.array_bools(),
)
def test_numpy_square(
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_name="square",
x=np.asarray(x, dtype=input_dtype),
out=None,
where=where,
casting="same_kind",
order="k",
dtype=dtype,
subok=True,
test_values=False,
)