From 0ec328b14b3e855c2a30848d23465a0739d5bfa3 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Thu, 7 May 2026 14:16:45 +0530 Subject: [PATCH 01/12] Adding angle Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- src/array_api_extra/__init__.py | 2 ++ src/array_api_extra/_lib/_funcs.py | 33 ++++++++++++++++++++++++++++++ tests/test_funcs.py | 25 ++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/src/array_api_extra/__init__.py b/src/array_api_extra/__init__.py index 2fcdcd8e..e41deaeb 100644 --- a/src/array_api_extra/__init__.py +++ b/src/array_api_extra/__init__.py @@ -24,6 +24,7 @@ default_dtype, kron, nunique, + angle, ) from ._lib._lazy import lazy_apply @@ -54,4 +55,5 @@ "setdiff1d", "sinc", "union1d", + "angle", ] diff --git a/src/array_api_extra/_lib/_funcs.py b/src/array_api_extra/_lib/_funcs.py index 97904ddb..cce51179 100644 --- a/src/array_api_extra/_lib/_funcs.py +++ b/src/array_api_extra/_lib/_funcs.py @@ -818,3 +818,36 @@ def union1d(a: Array, b: Array, /, *, xp: ModuleType) -> Array: b = xp.reshape(b, (-1,)) # XXX: `sparse` returns NumPy arrays from `unique_values` return xp.asarray(xp.unique_values(xp.concat([a, b]))) + + +def angle(z: Array, deg: bool = False, /, *, xp: ModuleType | None = None) -> Array: + """ + Return the angle of the complex argument. + + Parameters + ---------- + z : Array + Input array. + deg : bool, optional + Return angle in degrees if True, radians if False (default). + xp : array_namespace, optional + The standard-compatible namespace for `z`. Default: infer. + + Returns + ------- + angle : ndarray or scalar + The counterclockwise angle from the positive real axis on the complex + plane in the range ``(-pi, pi]``, with dtype as float64. + """ + if xp is None: + xp = array_namespace(z) + if xp.isdtype(z.dtype, "complex floating"): + zimage = xp.imag(z) + zreal = xp.real(z) + else: + zimage = xp.zeros_like(z, dtype=xp.float64) + zreal = xp.astype(z, xp.float64) + a = xp.atan2(zimage, zreal) + if deg: + a = a * 180 / xp.pi + return a \ No newline at end of file diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 6a11e059..86d0a377 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -33,6 +33,7 @@ setdiff1d, sinc, union1d, + angle, ) from array_api_extra import ( searchsorted as xpx_searchsorted, @@ -1881,3 +1882,27 @@ def test_device(self, xp: ModuleType, device: Device): a = xp.asarray([-1, 1, 0], device=device) b = xp.asarray([2, -2, 0], device=device) assert get_device(union1d(a, b)) == device + +class TestAngle: + def test_simple(self, xp: ModuleType): + a = xp.asarray([1, 0]) + expected = xp.asarray([0., 0.]) + res = angle(a) + xp_assert_equal(res, expected) + + def test_complex(self, xp: ModuleType): + a = xp.asarray([1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j]) + expected = xp.asarray([np.pi / 4, -np.pi / 4, 3 * np.pi / 4, -3 * np.pi / 4]) + res = angle(a) + xp_assert_equal(res, expected) + + def test_2d(self, xp: ModuleType): + a = xp.asarray([[1 + 1j, 1 - 1j], [-1 + 1j, -1 - 1j]]) + expected = xp.asarray([[np.pi / 4, -np.pi / 4], [3 * np.pi / 4, -3 * np.pi / 4]]) + res = angle(a) + xp_assert_equal(res, expected) + + @pytest.mark.skip_xp_backend(Backend.TORCH, reason="materialize 'meta' device") + def test_device(self, xp: ModuleType, device: Device): + a = xp.asarray([1 + 1j], device=device) + assert get_device(angle(a)) == device \ No newline at end of file From 81c5651cfca0d303bf5765731782b134f71f5d5c Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Thu, 7 May 2026 16:37:44 +0530 Subject: [PATCH 02/12] test correction + pre commit Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- src/array_api_extra/__init__.py | 4 ++-- src/array_api_extra/_lib/_funcs.py | 4 ++-- tests/test_funcs.py | 11 +++++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/array_api_extra/__init__.py b/src/array_api_extra/__init__.py index e41deaeb..17503674 100644 --- a/src/array_api_extra/__init__.py +++ b/src/array_api_extra/__init__.py @@ -19,12 +19,12 @@ ) from ._lib._at import at from ._lib._funcs import ( + angle, apply_where, broadcast_shapes, default_dtype, kron, nunique, - angle, ) from ._lib._lazy import lazy_apply @@ -33,6 +33,7 @@ # pylint: disable=duplicate-code __all__ = [ "__version__", + "angle", "apply_where", "argpartition", "at", @@ -55,5 +56,4 @@ "setdiff1d", "sinc", "union1d", - "angle", ] diff --git a/src/array_api_extra/_lib/_funcs.py b/src/array_api_extra/_lib/_funcs.py index cce51179..b58cf3d0 100644 --- a/src/array_api_extra/_lib/_funcs.py +++ b/src/array_api_extra/_lib/_funcs.py @@ -835,7 +835,7 @@ def angle(z: Array, deg: bool = False, /, *, xp: ModuleType | None = None) -> Ar Returns ------- - angle : ndarray or scalar + ndarray or scalar The counterclockwise angle from the positive real axis on the complex plane in the range ``(-pi, pi]``, with dtype as float64. """ @@ -850,4 +850,4 @@ def angle(z: Array, deg: bool = False, /, *, xp: ModuleType | None = None) -> Ar a = xp.atan2(zimage, zreal) if deg: a = a * 180 / xp.pi - return a \ No newline at end of file + return a diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 86d0a377..71d7bc57 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -13,6 +13,7 @@ from typing_extensions import override from array_api_extra import ( + angle, apply_where, argpartition, at, @@ -33,7 +34,6 @@ setdiff1d, sinc, union1d, - angle, ) from array_api_extra import ( searchsorted as xpx_searchsorted, @@ -1883,10 +1883,11 @@ def test_device(self, xp: ModuleType, device: Device): b = xp.asarray([2, -2, 0], device=device) assert get_device(union1d(a, b)) == device + class TestAngle: def test_simple(self, xp: ModuleType): a = xp.asarray([1, 0]) - expected = xp.asarray([0., 0.]) + expected = xp.asarray([0.0, 0.0], dtype=xp.float64) res = angle(a) xp_assert_equal(res, expected) @@ -1898,11 +1899,13 @@ def test_complex(self, xp: ModuleType): def test_2d(self, xp: ModuleType): a = xp.asarray([[1 + 1j, 1 - 1j], [-1 + 1j, -1 - 1j]]) - expected = xp.asarray([[np.pi / 4, -np.pi / 4], [3 * np.pi / 4, -3 * np.pi / 4]]) + expected = xp.asarray( + [[np.pi / 4, -np.pi / 4], [3 * np.pi / 4, -3 * np.pi / 4]] + ) res = angle(a) xp_assert_equal(res, expected) @pytest.mark.skip_xp_backend(Backend.TORCH, reason="materialize 'meta' device") def test_device(self, xp: ModuleType, device: Device): a = xp.asarray([1 + 1j], device=device) - assert get_device(angle(a)) == device \ No newline at end of file + assert get_device(angle(a)) == device From 2ab1dbdf8501196098fc532a7e662e01b0a06e99 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Mon, 11 May 2026 16:02:05 +0530 Subject: [PATCH 03/12] adding suggestions Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- src/array_api_extra/_lib/_funcs.py | 22 +++++++++++---- tests/test_funcs.py | 44 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/array_api_extra/_lib/_funcs.py b/src/array_api_extra/_lib/_funcs.py index b58cf3d0..134e266d 100644 --- a/src/array_api_extra/_lib/_funcs.py +++ b/src/array_api_extra/_lib/_funcs.py @@ -23,6 +23,7 @@ from ._utils._typing import Array, Device, DType __all__ = [ + "angle", "apply_where", "atleast_nd", "broadcast_shapes", @@ -820,7 +821,7 @@ def union1d(a: Array, b: Array, /, *, xp: ModuleType) -> Array: return xp.asarray(xp.unique_values(xp.concat([a, b]))) -def angle(z: Array, deg: bool = False, /, *, xp: ModuleType | None = None) -> Array: +def angle(z: Array, deg: bool = False, *, xp: ModuleType | None = None) -> Array: """ Return the angle of the complex argument. @@ -835,19 +836,28 @@ def angle(z: Array, deg: bool = False, /, *, xp: ModuleType | None = None) -> Ar Returns ------- - ndarray or scalar + array The counterclockwise angle from the positive real axis on the complex plane in the range ``(-pi, pi]``, with dtype as float64. + + Examples + -------- + >>> import array_api_strict as xp + >>> import array_api_extra as xpx + >>> xpx.angle(xp.asarray([1.0, 1.0j, 1 + 1j]), xp=xp) + Array([0. , 1.57079633, 0.78539816], dtype=array_api_strict.float64) """ if xp is None: xp = array_namespace(z) if xp.isdtype(z.dtype, "complex floating"): - zimage = xp.imag(z) + zimag = xp.imag(z) zreal = xp.real(z) else: - zimage = xp.zeros_like(z, dtype=xp.float64) - zreal = xp.astype(z, xp.float64) - a = xp.atan2(zimage, zreal) + if not xp.isdtype(z.dtype, "real floating"): + z = xp.astype(z, default_dtype(xp, device=_compat.device(z))) + zimag = xp.zeros_like(z) + zreal = z + a = xp.atan2(zimag, zreal) if deg: a = a * 180 / xp.pi return a diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 71d7bc57..fa814408 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -1891,12 +1891,56 @@ def test_simple(self, xp: ModuleType): res = angle(a) xp_assert_equal(res, expected) + def test_basic(self, xp: ModuleType): + x = xp.asarray( + [ + 1 + 3j, + np.sqrt(2) / 2.0 + 1j * np.sqrt(2) / 2, + 1, + 1j, + -1, + -1j, + 1 - 3j, + -1 + 3j, + ], + dtype=xp.complex128, + ) + expected = xp.asarray( + [ + np.arctan(3.0 / 1.0), + np.arctan(1.0), + 0, + np.pi / 2, + np.pi, + -np.pi / 2.0, + -np.arctan(3.0 / 1.0), + np.pi - np.arctan(3.0 / 1.0), + ], + dtype=xp.float64, + ) + xp_assert_close(angle(x), expected, rtol=0, atol=1e-11) + xp_assert_close(angle(x, deg=True), expected * 180 / xp.pi, rtol=0, atol=1e-11) + + def test_real(self, xp: ModuleType): + x = xp.asarray([0.0, -0.0, 1.0, -1.0]) + expected = xp.asarray([0.0, xp.pi, 0.0, xp.pi], dtype=x.dtype) + xp_assert_close(angle(x), expected) + def test_complex(self, xp: ModuleType): a = xp.asarray([1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j]) expected = xp.asarray([np.pi / 4, -np.pi / 4, 3 * np.pi / 4, -3 * np.pi / 4]) res = angle(a) xp_assert_equal(res, expected) + def test_integral(self, xp: ModuleType): + x = xp.asarray([0, -1, 1], dtype=xp.int32) + actual = angle(x) + expected = xp.asarray( + [0.0, xp.pi, 0.0], dtype=default_dtype(xp, device=get_device(x)) + ) + xp_assert_close(actual, expected) + assert actual.dtype == expected.dtype + def test_2d(self, xp: ModuleType): a = xp.asarray([[1 + 1j, 1 - 1j], [-1 + 1j, -1 - 1j]]) expected = xp.asarray( From 15c8cfed581178f4e39bcee46bcca8a2dc7f3b66 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Mon, 11 May 2026 17:47:13 +0530 Subject: [PATCH 04/12] fix test Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- tests/test_funcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_funcs.py b/tests/test_funcs.py index fa814408..5574b0ed 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -1887,8 +1887,8 @@ def test_device(self, xp: ModuleType, device: Device): class TestAngle: def test_simple(self, xp: ModuleType): a = xp.asarray([1, 0]) - expected = xp.asarray([0.0, 0.0], dtype=xp.float64) res = angle(a) + expected = xp.asarray([0.0, 0.0], dtype=res.dtype) xp_assert_equal(res, expected) def test_basic(self, xp: ModuleType): From f7cb8ee4d36c8e94e751354b33f67d4e90e38396 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Tue, 12 May 2026 00:19:35 +0530 Subject: [PATCH 05/12] make deg keyword only and z position only Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- src/array_api_extra/_lib/_funcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_extra/_lib/_funcs.py b/src/array_api_extra/_lib/_funcs.py index 134e266d..e7738dc3 100644 --- a/src/array_api_extra/_lib/_funcs.py +++ b/src/array_api_extra/_lib/_funcs.py @@ -821,7 +821,7 @@ def union1d(a: Array, b: Array, /, *, xp: ModuleType) -> Array: return xp.asarray(xp.unique_values(xp.concat([a, b]))) -def angle(z: Array, deg: bool = False, *, xp: ModuleType | None = None) -> Array: +def angle(z: Array, /, *, deg: bool = False, xp: ModuleType | None = None) -> Array: """ Return the angle of the complex argument. From f65c0b8f504eadd03218813a41484b33843199e9 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+prady0t@users.noreply.github.com> Date: Tue, 12 May 2026 01:23:31 +0530 Subject: [PATCH 06/12] Update tests/test_funcs.py Co-authored-by: Lucas Colley --- tests/test_funcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 5574b0ed..1663596b 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -1928,7 +1928,7 @@ def test_real(self, xp: ModuleType): def test_complex(self, xp: ModuleType): a = xp.asarray([1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j]) - expected = xp.asarray([np.pi / 4, -np.pi / 4, 3 * np.pi / 4, -3 * np.pi / 4]) + expected = xp.asarray([xp.pi / 4, -xp.pi / 4, 3 * xp.pi / 4, -3 * xp.pi / 4]) res = angle(a) xp_assert_equal(res, expected) From 6f644b33d8b64915bb98765504ebf8570ead9d81 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+prady0t@users.noreply.github.com> Date: Tue, 12 May 2026 01:23:45 +0530 Subject: [PATCH 07/12] Update src/array_api_extra/_lib/_funcs.py Co-authored-by: Lucas Colley --- src/array_api_extra/_lib/_funcs.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/array_api_extra/_lib/_funcs.py b/src/array_api_extra/_lib/_funcs.py index e7738dc3..bfd99932 100644 --- a/src/array_api_extra/_lib/_funcs.py +++ b/src/array_api_extra/_lib/_funcs.py @@ -846,6 +846,8 @@ def angle(z: Array, /, *, deg: bool = False, xp: ModuleType | None = None) -> Ar >>> import array_api_extra as xpx >>> xpx.angle(xp.asarray([1.0, 1.0j, 1 + 1j]), xp=xp) Array([0. , 1.57079633, 0.78539816], dtype=array_api_strict.float64) + >>> xpx.angle(xp.asarray([1.0, 1.0j, 1 + 1j]), deg=True, xp=xp) + Array([ 0., 90., 45.], dtype=array_api_strict.float64) """ if xp is None: xp = array_namespace(z) From 4ccaf4a0941fd6ecd0fb31b33854d6a6d44a60b1 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+prady0t@users.noreply.github.com> Date: Tue, 12 May 2026 01:23:57 +0530 Subject: [PATCH 08/12] Update tests/test_funcs.py Co-authored-by: Lucas Colley --- tests/test_funcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 1663596b..1a09225a 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -1944,7 +1944,7 @@ def test_integral(self, xp: ModuleType): def test_2d(self, xp: ModuleType): a = xp.asarray([[1 + 1j, 1 - 1j], [-1 + 1j, -1 - 1j]]) expected = xp.asarray( - [[np.pi / 4, -np.pi / 4], [3 * np.pi / 4, -3 * np.pi / 4]] + [[xp.pi / 4, -xp.pi / 4], [3 * xp.pi / 4, -3 * xp.pi / 4]] ) res = angle(a) xp_assert_equal(res, expected) From be2a90c9cc71430ee6b0d6ab8047ad12553b2e1c Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+prady0t@users.noreply.github.com> Date: Tue, 12 May 2026 01:24:10 +0530 Subject: [PATCH 09/12] Update tests/test_funcs.py Co-authored-by: Lucas Colley --- tests/test_funcs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_funcs.py b/tests/test_funcs.py index 1a09225a..a3290596 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -1939,7 +1939,6 @@ def test_integral(self, xp: ModuleType): [0.0, xp.pi, 0.0], dtype=default_dtype(xp, device=get_device(x)) ) xp_assert_close(actual, expected) - assert actual.dtype == expected.dtype def test_2d(self, xp: ModuleType): a = xp.asarray([[1 + 1j, 1 - 1j], [-1 + 1j, -1 - 1j]]) From dd2a32cd7d82038263794aea81de0fcb0b9a4193 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Tue, 12 May 2026 02:29:08 +0530 Subject: [PATCH 10/12] adding suggestions Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- docs/api-reference.md | 1 + src/array_api_extra/_lib/_funcs.py | 2 +- tests/test_funcs.py | 17 +++++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/api-reference.md b/docs/api-reference.md index 771967af..3b886292 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -26,4 +26,5 @@ setdiff1d sinc union1d + angle ``` diff --git a/src/array_api_extra/_lib/_funcs.py b/src/array_api_extra/_lib/_funcs.py index bfd99932..ece0eec6 100644 --- a/src/array_api_extra/_lib/_funcs.py +++ b/src/array_api_extra/_lib/_funcs.py @@ -838,7 +838,7 @@ def angle(z: Array, /, *, deg: bool = False, xp: ModuleType | None = None) -> Ar ------- array The counterclockwise angle from the positive real axis on the complex - plane in the range ``(-pi, pi]``, with dtype as float64. + plane in the range ``(-pi, pi]``. Examples -------- diff --git a/tests/test_funcs.py b/tests/test_funcs.py index a3290596..f3fb7100 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -1918,23 +1918,28 @@ def test_basic(self, xp: ModuleType): ], dtype=xp.float64, ) - xp_assert_close(angle(x), expected, rtol=0, atol=1e-11) - xp_assert_close(angle(x, deg=True), expected * 180 / xp.pi, rtol=0, atol=1e-11) + xp_assert_close(angle(x, xp=xp), expected, rtol=0, atol=1e-11) + xp_assert_close( + angle(x, deg=True, xp=xp), + expected * 180 / xp.pi, + rtol=0, + atol=1e-11, +) def test_real(self, xp: ModuleType): x = xp.asarray([0.0, -0.0, 1.0, -1.0]) expected = xp.asarray([0.0, xp.pi, 0.0, xp.pi], dtype=x.dtype) - xp_assert_close(angle(x), expected) + xp_assert_close(angle(x, xp=xp), expected) def test_complex(self, xp: ModuleType): a = xp.asarray([1 + 1j, 1 - 1j, -1 + 1j, -1 - 1j]) expected = xp.asarray([xp.pi / 4, -xp.pi / 4, 3 * xp.pi / 4, -3 * xp.pi / 4]) - res = angle(a) + res = angle(a, xp=xp) xp_assert_equal(res, expected) def test_integral(self, xp: ModuleType): x = xp.asarray([0, -1, 1], dtype=xp.int32) - actual = angle(x) + actual = angle(x, xp=xp) expected = xp.asarray( [0.0, xp.pi, 0.0], dtype=default_dtype(xp, device=get_device(x)) ) @@ -1945,7 +1950,7 @@ def test_2d(self, xp: ModuleType): expected = xp.asarray( [[xp.pi / 4, -xp.pi / 4], [3 * xp.pi / 4, -3 * xp.pi / 4]] ) - res = angle(a) + res = angle(a, xp=xp) xp_assert_equal(res, expected) @pytest.mark.skip_xp_backend(Backend.TORCH, reason="materialize 'meta' device") From f337afa7b929e9fc3c497ffbc88132cf8afeabce Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Tue, 12 May 2026 02:29:39 +0530 Subject: [PATCH 11/12] adding suggestions Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- tests/test_funcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_funcs.py b/tests/test_funcs.py index f3fb7100..5aef838d 100644 --- a/tests/test_funcs.py +++ b/tests/test_funcs.py @@ -1924,7 +1924,7 @@ def test_basic(self, xp: ModuleType): expected * 180 / xp.pi, rtol=0, atol=1e-11, -) + ) def test_real(self, xp: ModuleType): x = xp.asarray([0.0, -0.0, 1.0, -1.0]) From 0524d4c2bccc123fa6b14e4a9fcfbe0d06074f4e Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Tue, 12 May 2026 10:16:39 +0530 Subject: [PATCH 12/12] adding a note for real input Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> --- docs/api-reference.md | 2 +- src/array_api_extra/_lib/_funcs.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/api-reference.md b/docs/api-reference.md index 3b886292..aba97eb6 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -6,6 +6,7 @@ :nosignatures: :toctree: generated + angle apply_where argpartition at @@ -26,5 +27,4 @@ setdiff1d sinc union1d - angle ``` diff --git a/src/array_api_extra/_lib/_funcs.py b/src/array_api_extra/_lib/_funcs.py index ece0eec6..77340fbf 100644 --- a/src/array_api_extra/_lib/_funcs.py +++ b/src/array_api_extra/_lib/_funcs.py @@ -840,6 +840,10 @@ def angle(z: Array, /, *, deg: bool = False, xp: ModuleType | None = None) -> Ar The counterclockwise angle from the positive real axis on the complex plane in the range ``(-pi, pi]``. + Notes + ----- + A real input x is interpreted as x + 0j + Examples -------- >>> import array_api_strict as xp