|
4 | 4 | from ._lib import _compat, _helpers |
5 | 5 | from ._lib._typing import Array, ArrayNamespace |
6 | 6 |
|
7 | | -__all__ = ["deg2rad", "isclose", "nan_to_num", "rad2deg", "sinc"] |
| 7 | +__all__ = ["angle", "deg2rad", "isclose", "nan_to_num", "rad2deg", "sinc"] |
| 8 | + |
| 9 | + |
| 10 | +def angle(z: Array, /, *, deg: bool = False, xp: ArrayNamespace | None = None) -> Array: |
| 11 | + """ |
| 12 | + Return the angle of the complex argument. |
| 13 | +
|
| 14 | + Parameters |
| 15 | + ---------- |
| 16 | + z : array |
| 17 | + Input array. Real input is interpreted as having zero imaginary part. |
| 18 | + deg : bool, optional |
| 19 | + Return angle in degrees if True, radians if False (default). |
| 20 | + xp : array_namespace, optional |
| 21 | + The standard-compatible namespace for `z`. Default: infer. |
| 22 | +
|
| 23 | + Returns |
| 24 | + ------- |
| 25 | + array |
| 26 | + The counterclockwise angle from the positive real axis on the complex |
| 27 | + plane in the range ``(-pi, pi]``. |
| 28 | +
|
| 29 | + Examples |
| 30 | + -------- |
| 31 | + >>> import array_api_strict as xp |
| 32 | + >>> import array_api_extra as xpx |
| 33 | + >>> xpx.angle(xp.asarray([1.0, 1.0j, 1 + 1j]), xp=xp) |
| 34 | + Array([0. , 1.57079633, 0.78539816], dtype=array_api_strict.float64) |
| 35 | + >>> xpx.angle(xp.asarray([1.0, 1.0j, 1 + 1j]), deg=True, xp=xp) |
| 36 | + Array([ 0., 90., 45.], dtype=array_api_strict.float64) |
| 37 | + """ |
| 38 | + if xp is None: |
| 39 | + xp = _compat.array_namespace(z) |
| 40 | + |
| 41 | + return _agnostic._elementwise.angle(z, deg=deg, xp=xp) |
8 | 42 |
|
9 | 43 |
|
10 | 44 | def deg2rad(x: Array, /, *, xp: ArrayNamespace | None = None) -> Array: |
|
0 commit comments