From 203d00c22dc60e1ac08c6f4fab69c0895fe1e3f2 Mon Sep 17 00:00:00 2001 From: Joboa Date: Thu, 9 Feb 2023 21:47:07 -0500 Subject: [PATCH 1/6] Add imag function to Numpy frontend --- ivy/functional/frontends/numpy/__init__.py | 5 +++ .../handling_complex_numbers.py | 19 ++++++++++ .../frontends/numpy/ufunc/methods.py | 1 + .../test_handling_complex_numbers.py | 35 +++++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/ivy/functional/frontends/numpy/__init__.py b/ivy/functional/frontends/numpy/__init__.py index 6472da65b081b..9d8809fa1f92e 100644 --- a/ivy/functional/frontends/numpy/__init__.py +++ b/ivy/functional/frontends/numpy/__init__.py @@ -538,6 +538,10 @@ def promote_types_of_numpy_inputs( _tan, ) +from ivy.functional.frontends.numpy.mathematical_functions.handling_complex_numbers import ( + _imag, +) + from ivy.functional.frontends.numpy.mathematical_functions.hyperbolic_functions import ( _arccosh, _arcsinh, @@ -636,6 +640,7 @@ def promote_types_of_numpy_inputs( equal = ufunc("_equal") greater = ufunc("_greater") greater_equal = ufunc("_greater_equal") +imag = ufunc("_imag") less = ufunc("_less") less_equal = ufunc("_less_equal") not_equal = ufunc("_not_equal") 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 e69de29bb2d1d..48c92c892adcf 100644 --- a/ivy/functional/frontends/numpy/mathematical_functions/handling_complex_numbers.py +++ b/ivy/functional/frontends/numpy/mathematical_functions/handling_complex_numbers.py @@ -0,0 +1,19 @@ +# global +import ivy +from ivy.functional.frontends.numpy import promote_types_of_numpy_inputs +from ivy.functional.frontends.numpy.func_wrapper import ( + to_ivy_arrays_and_back, + handle_numpy_casting, + handle_numpy_dtype, + from_zero_dim_arrays_to_scalar, + handle_numpy_out, +) + + +# @handle_numpy_dtype +# @to_ivy_arrays_and_back +# @from_zero_dim_arrays_to_scalar +def _imag(val): + # if dtype: + # val = [ivy.astype(ivy.array(v), ivy.as_ivy_dtype(dtype)) for v in val] + return ivy.imag(val) \ No newline at end of file diff --git a/ivy/functional/frontends/numpy/ufunc/methods.py b/ivy/functional/frontends/numpy/ufunc/methods.py index 4f4e7cae96410..b8ac633c4ea98 100644 --- a/ivy/functional/frontends/numpy/ufunc/methods.py +++ b/ivy/functional/frontends/numpy/ufunc/methods.py @@ -50,6 +50,7 @@ "greater_equal", "heaviside", "hypot", + "imag" "invert", "isfinite", "isinf", 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 e69de29bb2d1d..88ebc8850b636 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 @@ -0,0 +1,35 @@ +# global +from hypothesis import assume, given, strategies as st +import numpy as np + +# local +import ivy_tests.test_ivy.helpers as helpers +import ivy_tests.test_ivy.test_frontends.test_numpy.helpers as np_frontend_helpers +from ivy_tests.test_ivy.helpers import handle_frontend_test + + +# imag +@handle_frontend_test( + fn_tree="numpy.imag", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("numeric") + ), + test_with_out=st.just(False), +) +def test_numpy_imag( + 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, + test_values=False, + val=x, + ) \ No newline at end of file From 764aa2be58a007feb4f5763c87265b2930194925 Mon Sep 17 00:00:00 2001 From: Joboa Date: Fri, 10 Feb 2023 12:45:08 -0500 Subject: [PATCH 2/6] Fix imag function for Numpy frontend --- .../handling_complex_numbers.py | 13 ++----------- .../test_handling_complex_numbers.py | 13 ++++--------- 2 files changed, 6 insertions(+), 20 deletions(-) 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 48c92c892adcf..a88a694d2e8f9 100644 --- a/ivy/functional/frontends/numpy/mathematical_functions/handling_complex_numbers.py +++ b/ivy/functional/frontends/numpy/mathematical_functions/handling_complex_numbers.py @@ -1,19 +1,10 @@ # global import ivy -from ivy.functional.frontends.numpy import promote_types_of_numpy_inputs from ivy.functional.frontends.numpy.func_wrapper import ( to_ivy_arrays_and_back, - handle_numpy_casting, - handle_numpy_dtype, - from_zero_dim_arrays_to_scalar, - handle_numpy_out, ) -# @handle_numpy_dtype -# @to_ivy_arrays_and_back -# @from_zero_dim_arrays_to_scalar +@to_ivy_arrays_and_back def _imag(val): - # if dtype: - # val = [ivy.astype(ivy.array(v), ivy.as_ivy_dtype(dtype)) for v in val] - return ivy.imag(val) \ No newline at end of file + return ivy.imag(val) 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 88ebc8850b636..6436611bfa676 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 @@ -1,19 +1,15 @@ # global -from hypothesis import assume, given, strategies as st -import numpy as np +from hypothesis import strategies as st # local import ivy_tests.test_ivy.helpers as helpers -import ivy_tests.test_ivy.test_frontends.test_numpy.helpers as np_frontend_helpers from ivy_tests.test_ivy.helpers import handle_frontend_test # imag @handle_frontend_test( fn_tree="numpy.imag", - dtype_and_x=helpers.dtype_and_values( - available_dtypes=helpers.get_dtypes("numeric") - ), + dtype_and_x=helpers.dtype_and_values(available_dtypes=helpers.get_dtypes("valid")), test_with_out=st.just(False), ) def test_numpy_imag( @@ -30,6 +26,5 @@ def test_numpy_imag( test_flags=test_flags, fn_tree=fn_tree, on_device=on_device, - test_values=False, - val=x, - ) \ No newline at end of file + val=x[0], + ) From 9d1bf8f2590fe4fb672b4b2ddcce4a2fadf22a24 Mon Sep 17 00:00:00 2001 From: Joboa Date: Fri, 10 Feb 2023 18:42:51 -0500 Subject: [PATCH 3/6] Add real function to Numpy frontend --- ivy/functional/frontends/numpy/__init__.py | 2 ++ .../handling_complex_numbers.py | 5 ++++ .../frontends/numpy/ufunc/methods.py | 3 ++- .../test_handling_complex_numbers.py | 24 +++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/ivy/functional/frontends/numpy/__init__.py b/ivy/functional/frontends/numpy/__init__.py index 9d8809fa1f92e..f13381e27b81b 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 b8ac633c4ea98..d6df90269f082 100644 --- a/ivy/functional/frontends/numpy/ufunc/methods.py +++ b/ivy/functional/frontends/numpy/ufunc/methods.py @@ -50,7 +50,7 @@ "greater_equal", "heaviside", "hypot", - "imag" + "imag", "invert", "isfinite", "isinf", @@ -84,6 +84,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], + ) From 014939a98735bddfeb59580d22fdabd95ade65a9 Mon Sep 17 00:00:00 2001 From: Joboa Date: Sat, 11 Feb 2023 02:58:19 -0500 Subject: [PATCH 4/6] Revert "Add real function to Numpy frontend" This reverts commit 9d1bf8f2590fe4fb672b4b2ddcce4a2fadf22a24. --- ivy/functional/frontends/numpy/__init__.py | 2 -- .../handling_complex_numbers.py | 5 ---- .../frontends/numpy/ufunc/methods.py | 3 +-- .../test_handling_complex_numbers.py | 24 ------------------- 4 files changed, 1 insertion(+), 33 deletions(-) diff --git a/ivy/functional/frontends/numpy/__init__.py b/ivy/functional/frontends/numpy/__init__.py index f13381e27b81b..9d8809fa1f92e 100644 --- a/ivy/functional/frontends/numpy/__init__.py +++ b/ivy/functional/frontends/numpy/__init__.py @@ -540,7 +540,6 @@ 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 ( @@ -664,4 +663,3 @@ 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 c356d5b6f6d46..a88a694d2e8f9 100644 --- a/ivy/functional/frontends/numpy/mathematical_functions/handling_complex_numbers.py +++ b/ivy/functional/frontends/numpy/mathematical_functions/handling_complex_numbers.py @@ -8,8 +8,3 @@ @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 d6df90269f082..b8ac633c4ea98 100644 --- a/ivy/functional/frontends/numpy/ufunc/methods.py +++ b/ivy/functional/frontends/numpy/ufunc/methods.py @@ -50,7 +50,7 @@ "greater_equal", "heaviside", "hypot", - "imag", + "imag" "invert", "isfinite", "isinf", @@ -84,7 +84,6 @@ "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 0a18023f3bbd9..6436611bfa676 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,27 +28,3 @@ 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], - ) From 769f72bcd0e0dbb54788dd514a58f0a098288259 Mon Sep 17 00:00:00 2001 From: Joboa Date: Sat, 11 Feb 2023 03:35:22 -0500 Subject: [PATCH 5/6] Add real function to Numpy frontend --- ivy/functional/frontends/numpy/__init__.py | 2 ++ .../handling_complex_numbers.py | 5 ++++ .../frontends/numpy/ufunc/methods.py | 3 ++- .../test_handling_complex_numbers.py | 24 +++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/ivy/functional/frontends/numpy/__init__.py b/ivy/functional/frontends/numpy/__init__.py index 9d8809fa1f92e..f13381e27b81b 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 b8ac633c4ea98..d6df90269f082 100644 --- a/ivy/functional/frontends/numpy/ufunc/methods.py +++ b/ivy/functional/frontends/numpy/ufunc/methods.py @@ -50,7 +50,7 @@ "greater_equal", "heaviside", "hypot", - "imag" + "imag", "invert", "isfinite", "isinf", @@ -84,6 +84,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], + ) From f4c34cda59ecfb246732c20f4125b5d506097356 Mon Sep 17 00:00:00 2001 From: Joboa Date: Wed, 22 Feb 2023 18:17:09 -0500 Subject: [PATCH 6/6] fix real complex numbers function for Numpy frontend --- .../numpy/mathematical_functions/handling_complex_numbers.py | 2 +- .../test_handling_complex_numbers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 f168925fa80bb..c356d5b6f6d46 100644 --- a/ivy/functional/frontends/numpy/mathematical_functions/handling_complex_numbers.py +++ b/ivy/functional/frontends/numpy/mathematical_functions/handling_complex_numbers.py @@ -12,4 +12,4 @@ def _imag(val): @to_ivy_arrays_and_back def _real(val): - return ivy.real(val) \ No newline at end of file + return ivy.real(val) 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 f666c66e8c2ac..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 @@ -51,4 +51,4 @@ def test_numpy_real( fn_tree=fn_tree, on_device=on_device, val=x[0], - ) \ No newline at end of file + )