Skip to content

Commit

Permalink
numpy_copysign (#9238)
Browse files Browse the repository at this point in the history
Co-authored-by: nassimberrada <Nassim>
  • Loading branch information
nassimberrada authored Dec 30, 2022
1 parent f7267ef commit 93f6e95
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,25 @@ def interp_inner(value):
return ivy.astype(ivy.array(ret[0]), "float64")
else:
return ivy.astype(ivy.array(ret), "float64")


@handle_numpy_dtype
@to_ivy_arrays_and_back
@handle_numpy_casting
@from_zero_dim_arrays_to_scalar
def copysign(
x1,
x2,
/,
out=None,
*,
where=True,
casting="same_kind",
order="k",
dtype=None,
subok=True,
):
ret = ivy.copysign(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
Expand Up @@ -603,3 +603,60 @@ def test_numpy_convolve(
v=xs[1],
mode=mode,
)


# copysign
@handle_frontend_test(
fn_tree="numpy.copysign",
dtypes_values_casting=np_frontend_helpers.dtypes_values_casting_dtype(
arr_func=[
lambda: helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
num_arrays=2,
shared_dtype=True,
min_value=-100,
max_value=100,
)
],
get_dtypes_kind="float",
),
where=np_frontend_helpers.where(),
)
def test_numpy_copysign(
dtypes_values_casting,
where,
as_variable,
with_out,
num_positional_args,
native_array,
frontend,
fn_tree,
on_device,
):
input_dtype, xs, casting, dtype = dtypes_values_casting
where, as_variable, native_array = 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,
frontend=frontend,
fn_tree=fn_tree,
on_device=on_device,
rtol=1e-2,
atol=1e-2,
x1=xs[0],
x2=xs[1],
out=None,
where=where,
casting=casting,
order="K",
dtype=dtype,
subok=True,
)

0 comments on commit 93f6e95

Please sign in to comment.