diff --git a/ivy/functional/frontends/numpy/__init__.py b/ivy/functional/frontends/numpy/__init__.py index c6b3b5242e6e9..61db434281df6 100644 --- a/ivy/functional/frontends/numpy/__init__.py +++ b/ivy/functional/frontends/numpy/__init__.py @@ -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 ( @@ -663,3 +664,4 @@ def promote_types_of_numpy_inputs( matmul = ufunc("_matmul") maximum = ufunc("_maximum") minimum = ufunc("_minimum") +real = ufunc("_real") diff --git a/ivy/functional/frontends/numpy/mathematical_functions/handling_complex_numbers.py b/ivy/functional/frontends/numpy/mathematical_functions/handling_complex_numbers.py index a88a694d2e8f9..c356d5b6f6d46 100644 --- a/ivy/functional/frontends/numpy/mathematical_functions/handling_complex_numbers.py +++ b/ivy/functional/frontends/numpy/mathematical_functions/handling_complex_numbers.py @@ -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) diff --git a/ivy/functional/frontends/numpy/ufunc/methods.py b/ivy/functional/frontends/numpy/ufunc/methods.py index 0ffb17dcb2aa9..b444c3dd276ed 100644 --- a/ivy/functional/frontends/numpy/ufunc/methods.py +++ b/ivy/functional/frontends/numpy/ufunc/methods.py @@ -50,6 +50,8 @@ "greater_equal", "heaviside", "hypot", + "imag", + "invert", "imag" "invert", "isfinite", "isinf", @@ -83,6 +85,7 @@ "power", "rad2deg", "radians", + "real", "reciprocal", "remainder", "right_shift", diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_handling_complex_numbers.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_handling_complex_numbers.py index 6436611bfa676..0a18023f3bbd9 100644 --- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_handling_complex_numbers.py +++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_handling_complex_numbers.py @@ -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], + )