Repository: ivy-llc/ivy

Issue:
signbit



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/numpy/__init__.py b/ivy/functional/frontends/numpy/__init__.py
--- a/ivy/functional/frontends/numpy/__init__.py
+++ b/ivy/functional/frontends/numpy/__init__.py
@@ -638,6 +638,7 @@ def promote_types_of_numpy_inputs(
 
 from ivy.functional.frontends.numpy.mathematical_functions.floating_point_routines import (  # noqa
     _nextafter,
+    _signbit,
     _spacing,
 )
 
@@ -721,6 +722,7 @@ def promote_types_of_numpy_inputs(
 conj = ufunc("_conj")
 rint = ufunc("_rint")
 nextafter = ufunc("_nextafter")
+signbit = ufunc("_signbit")
 conjugate = ufunc("_conj")
 lcm = ufunc("_lcm")
 gcd = ufunc("_gcd")
diff --git a/ivy/functional/frontends/numpy/mathematical_functions/floating_point_routines.py b/ivy/functional/frontends/numpy/mathematical_functions/floating_point_routines.py
--- a/ivy/functional/frontends/numpy/mathematical_functions/floating_point_routines.py
+++ b/ivy/functional/frontends/numpy/mathematical_functions/floating_point_routines.py
@@ -35,6 +35,26 @@ def _nextafter(
     return ivy.nextafter(x1, x2, out=out)
 
 
+@handle_numpy_out
+@handle_numpy_dtype
+@to_ivy_arrays_and_back
+@handle_numpy_casting
+@from_zero_dim_arrays_to_scalar
+def _signbit(
+    x,
+    /,
+    out=None,
+    *,
+    where=True,
+    casting="safe",
+    order="K",
+    dtype=None,
+    subok=True,
+):
+    x = ivy.astype(x, ivy.float64)
+    return ivy.logical_or(ivy.less(x, 0), ivy.atan2(0.0, x) == ivy.pi, out=out)
+
+
 @handle_numpy_out
 @handle_numpy_dtype
 @to_ivy_arrays_and_back


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_floating_point_routines.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_floating_point_routines.py
--- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_floating_point_routines.py
+++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_mathematical_functions/test_floating_point_routines.py
@@ -54,6 +54,54 @@ def test_numpy_nextafter(
     )
 
 
+# signbit
+@handle_frontend_test(
+    fn_tree="numpy.signbit",
+    dtypes_values_casting=np_frontend_helpers.dtypes_values_casting_dtype(
+        arr_func=[
+            lambda: helpers.dtype_and_values(
+                available_dtypes=helpers.get_dtypes("valid"),
+                shared_dtype=True,
+            )
+        ],
+    ),
+    where=np_frontend_helpers.where(),
+    number_positional_args=np_frontend_helpers.get_num_positional_args_ufunc(
+        fn_name="signbit"
+    ),
+)
+def test_numpy_signbit(
+    dtypes_values_casting,
+    where,
+    frontend,
+    test_flags,
+    backend_fw,
+    fn_tree,
+    on_device,
+):
+    input_dtypes, xs, casting, dtype = dtypes_values_casting
+    where, input_dtypes, test_flags = np_frontend_helpers.handle_where_and_array_bools(
+        where=where,
+        input_dtype=input_dtypes,
+        test_flags=test_flags,
+    )
+    np_frontend_helpers.test_frontend_function(
+        input_dtypes=input_dtypes,
+        frontend=frontend,
+        test_flags=test_flags,
+        backend_to_test=backend_fw,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        x=xs[0],
+        out=None,
+        where=where,
+        casting="safe",
+        order="K",
+        dtype=dtype,
+        subok=True,
+    )
+
+
 # spacing
 @handle_frontend_test(
     fn_tree="numpy.spacing",