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

ldexp numpy frontend #12869

Merged
merged 3 commits into from
Mar 22, 2023
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
3 changes: 3 additions & 0 deletions ivy/functional/frontends/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ def promote_types_of_numpy_inputs(
_log2,
_logaddexp,
_logaddexp2,
_ldexp,
)

from ivy.functional.frontends.numpy.logic.array_type_testing import (
Expand Down Expand Up @@ -673,3 +674,5 @@ def promote_types_of_numpy_inputs(
real = ufunc("_real")
divmod = ufunc("_divmod")
fmax = ufunc("_fmax")
ldexp = ufunc("_ldexp")

Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,26 @@ def _logaddexp2(
@to_ivy_arrays_and_back
def i0(x):
return ivy.i0(x)


@handle_numpy_out
@handle_numpy_dtype
@to_ivy_arrays_and_back
@handle_numpy_casting
@from_zero_dim_arrays_to_scalar
def _ldexp(
x1,
x2,
/,
out=None,
*,
where=True,
casting="same_kind",
order="k",
dtype=None,
subok=True,
):
ret = ivy.ldexp(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 @@ -5,6 +5,7 @@
import ivy_tests.test_ivy.test_frontends.test_numpy.helpers as np_frontend_helpers
from ivy_tests.test_ivy.helpers import handle_frontend_test

from ivy_tests.test_ivy.test_functional.test_experimental.test_core.test_elementwise import ldexp_args

# exp
@handle_frontend_test(
Expand Down Expand Up @@ -468,3 +469,30 @@ def test_numpy_i0(
on_device=on_device,
x=x[0],
)

# ldexp
@handle_frontend_test(
fn_tree="numpy.ldexp",
dtype_and_x=ldexp_args(),
number_positional_args=np_frontend_helpers.get_num_positional_args_ufunc(
fn_name="ldexp"
),
)
def test_numpy_ldexp(
*,
dtype_and_x,
test_flags,
on_device,
fn_tree,
frontend,
):
input_dtype, x = dtype_and_x
helpers.test_frontend_function(
input_dtypes=input_dtype,
test_flags=test_flags,
frontend=frontend,
fn_tree=fn_tree,
on_device=on_device,
x1=x[0],
x2=x[1],
)