Skip to content

Commit

Permalink
ldexp numpy frontend (ivy-llc#12869)
Browse files Browse the repository at this point in the history
Co-authored by: nassimberrada
  • Loading branch information
pillarxyz authored and Giac3 committed Mar 24, 2023
1 parent 74491d1 commit 0a4e255
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
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],
)

0 comments on commit 0a4e255

Please sign in to comment.