|
28 | 28 | "floor_divide",
|
29 | 29 | "greater",
|
30 | 30 | "greater_equal",
|
| 31 | + "hypot", |
31 | 32 | "imag",
|
32 | 33 | "isfinite",
|
33 | 34 | "isinf",
|
@@ -1367,6 +1368,51 @@ def greater_equal(x1: array, x2: array, /) -> array:
|
1367 | 1368 | """
|
1368 | 1369 |
|
1369 | 1370 |
|
| 1371 | +def hypot(x1: array, x2: array, /) -> array: |
| 1372 | + r""" |
| 1373 | + Computes the square root of the sum of squares for each element ``x1_i`` of the input array ``x1`` with the respective element ``x2_i`` of the input array ``x2``. |
| 1374 | +
|
| 1375 | + .. note:: |
| 1376 | + The value computed by this function may be interpreted as the length of the hypotenuse of a right-angled triangle with sides of length ``x1_i`` and ``x2_i``, the distance of a point ``(x1_i, x2_i)`` from the origin ``(0, 0)``, or the magnitude of a complex number ``x1_i + x2_i * 1j``. |
| 1377 | +
|
| 1378 | + Parameters |
| 1379 | + ---------- |
| 1380 | + x1: array |
| 1381 | + first input array. Should have a real-valued floating-point data type. |
| 1382 | + x2: array |
| 1383 | + second input array. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued floating-point data type. |
| 1384 | +
|
| 1385 | + Returns |
| 1386 | + ------- |
| 1387 | + out: array |
| 1388 | + an array containing the element-wise results. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`. |
| 1389 | +
|
| 1390 | + Notes |
| 1391 | + ----- |
| 1392 | +
|
| 1393 | + The purpose of this function is to avoid underflow and overflow during intermediate stages of computation. Accordingly, conforming implementations should not use naive implementations. |
| 1394 | +
|
| 1395 | + **Special Cases** |
| 1396 | +
|
| 1397 | + For real-valued floating-point operands, |
| 1398 | +
|
| 1399 | + - If ``x1_i`` is ``+infinity`` or ``-infinity`` and ``x2_i`` is any value, including ``NaN``, the result is ``+infinity``. |
| 1400 | + - If ``x2_i`` is ``+infinity`` or ``-infinity`` and ``x1_i`` is any value, including ``NaN``, the result is ``+infinity``. |
| 1401 | + - If ``x1_i`` is either ``+0`` or ``-0``, the result is equivalent to ``abs(x2_i)``. |
| 1402 | + - If ``x2_i`` is either ``+0`` or ``-0``, the result is equivalent to ``abs(x1_i)``. |
| 1403 | + - If ``x1_i`` is a finite number or ``NaN`` and ``x2_i`` is ``NaN``, the result is ``NaN``. |
| 1404 | + - If ``x2_i`` is a finite number or ``NaN`` and ``x1_i`` is ``NaN``, the result is ``NaN``. |
| 1405 | + - Underflow may only occur when both arguments are subnormal and the correct result is also subnormal. |
| 1406 | +
|
| 1407 | + For real-valued floating-point operands, ``hypot(x1, x2)`` must equal ``hypot(x2, x1)``, ``hypot(x1, -x2)``, ``hypot(-x1, x2)``, and ``hypot(-x1, -x2)``. |
| 1408 | +
|
| 1409 | + .. note:: |
| 1410 | + IEEE 754-2019 requires support for subnormal (a.k.a., denormal) numbers, which are useful for supporting gradual underflow. However, hardware support for subnormal numbers is not universal, and many platforms (e.g., accelerators) and compilers support toggling denormals-are-zero (DAZ) and/or flush-to-zero (FTZ) behavior to increase performance and to guard against timing attacks. |
| 1411 | +
|
| 1412 | + Accordingly, conforming implementations may vary in their support for subnormal numbers. |
| 1413 | + """ |
| 1414 | + |
| 1415 | + |
1370 | 1416 | def imag(x: array, /) -> array:
|
1371 | 1417 | """
|
1372 | 1418 | Returns the imaginary component of a complex number for each element ``x_i`` of the input array ``x``.
|
|
0 commit comments