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

Update trigonometric_functions.py #3085

Merged
merged 4 commits into from
Sep 18, 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 @@ -167,30 +167,11 @@ def deg2rad(
return ret


@from_zero_dim_arrays_to_float
def arctan2(
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.atan2(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
arctan.unsupported_dtypes = {"torch": ("float16",)}


@from_zero_dim_arrays_to_float
def radians(
def arctanh(
x,
/,
out=None,
Expand All @@ -203,12 +184,15 @@ def radians(
):
if dtype:
x = ivy.astype(ivy.array(x), ivy.as_ivy_dtype(dtype))
ret = ivy.divide(ivy.multiply(x, ivy.pi, out=out), 180)
ret = ivy.atanh(x, out=out)
if ivy.is_array(where):
ret = ivy.where(where, ret, ivy.default(out, ivy.zeros_like(ret)), out=out)
return ret



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

@from_zero_dim_arrays_to_float
def rad2deg(
x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,128 +312,19 @@ def test_numpy_cosh(
)


# deg2rad
@handle_cmd_line_args
@given(
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
),
dtype=helpers.get_dtypes("float", full=False, none=True),
where=np_frontend_helpers.where(),
as_variable=helpers.array_bools(num_arrays=1),
num_positional_args=helpers.num_positional_args(
fn_name="ivy.functional.frontends.numpy.deg2rad"
),
native_array=helpers.array_bools(num_arrays=1),
)
def test_numpy_deg2rad(
dtype_and_x,
dtype,
where,
as_variable,
with_out,
num_positional_args,
native_array,
fw,
):
input_dtype, x = dtype_and_x
input_dtype = [input_dtype]

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="deg2rad",
x=np.asarray(x, dtype=input_dtype[0]),
out=None,
where=where,
casting="same_kind",
order="k",
dtype=dtype,
subok=True,
test_values=False,
)


# arctan2
@handle_cmd_line_args
# arctanh
@given(
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
num_arrays=2,
min_num_dims=1,
),
dtype=helpers.get_dtypes("float", full=False, none=True),
where=np_frontend_helpers.where(),
as_variable=helpers.array_bools(num_arrays=2),
with_out=st.booleans(),
num_positional_args=helpers.num_positional_args(
fn_name="ivy.functional.frontends.numpy.arctan2"
),
native_array=helpers.array_bools(num_arrays=2),
)
def test_numpy_arctan2(
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="arctan2",
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,
)


# radians
@handle_cmd_line_args
@given(
dtype_and_x=helpers.dtype_and_values(available_dtypes=helpers.get_dtypes("float")),
dtype=helpers.get_dtypes("float", full=False, none=True),
dtype_and_x=helpers.dtype_and_values(available_dtypes=ivy_np.valid_float_dtypes),
dtype=st.sampled_from(ivy_np.valid_float_dtypes + (None,)),
where=np_frontend_helpers.where(),
as_variable=helpers.array_bools(num_arrays=1),
with_out=st.booleans(),
num_positional_args=helpers.num_positional_args(
fn_name="ivy.functional.frontends.numpy.radians"
fn_name="ivy.functional.frontends.numpy.arctanh"
),
native_array=helpers.array_bools(num_arrays=1),
)
def test_numpy_radians(
def test_numpy_arctanh(
dtype_and_x,
dtype,
where,
Expand All @@ -459,12 +350,12 @@ def test_numpy_radians(
native_array_flags=native_array,
fw=fw,
frontend="numpy",
fn_tree="radians",
fn_tree="arctanh",
x=np.asarray(x, dtype=input_dtype[0]),
out=None,
where=where,
casting="same_kind",
order="K",
order="k",
dtype=dtype,
subok=True,
test_values=False,
Expand Down Expand Up @@ -513,4 +404,3 @@ def test_numpy_rad2deg(
subok=True,
test_values=True,
)