Skip to content

Commit

Permalink
Add real function to Numpy frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Joboa committed Feb 10, 2023
1 parent a582370 commit 9d1bf8f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ivy/functional/frontends/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ def promote_types_of_numpy_inputs(

from ivy.functional.frontends.numpy.mathematical_functions.handling_complex_numbers import (
_imag,
_real,
)

from ivy.functional.frontends.numpy.mathematical_functions.hyperbolic_functions import (
Expand Down Expand Up @@ -663,3 +664,4 @@ def promote_types_of_numpy_inputs(
matmul = ufunc("_matmul")
maximum = ufunc("_maximum")
minimum = ufunc("_minimum")
real = ufunc("_real")
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
@to_ivy_arrays_and_back
def _imag(val):
return ivy.imag(val)


@to_ivy_arrays_and_back
def _real(val):
return ivy.real(val)
3 changes: 2 additions & 1 deletion ivy/functional/frontends/numpy/ufunc/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"greater_equal",
"heaviside",
"hypot",
"imag"
"imag",
"invert",
"isfinite",
"isinf",
Expand Down Expand Up @@ -84,6 +84,7 @@
"power",
"rad2deg",
"radians",
"real",
"reciprocal",
"remainder",
"right_shift",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,27 @@ def test_numpy_imag(
on_device=on_device,
val=x[0],
)


# real
@handle_frontend_test(
fn_tree="numpy.real",
dtype_and_x=helpers.dtype_and_values(available_dtypes=helpers.get_dtypes("valid")),
test_with_out=st.just(False),
)
def test_numpy_real(
dtype_and_x,
frontend,
test_flags,
fn_tree,
on_device,
):
input_dtypes, x = dtype_and_x
helpers.test_frontend_function(
input_dtypes=input_dtypes,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
val=x[0],
)

0 comments on commit 9d1bf8f

Please sign in to comment.