Skip to content

Commit b689d43

Browse files
committed
Add hypot()
This is untested, but the NumPy hypot() should match the standard.
1 parent 16b38d3 commit b689d43

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

array_api_strict/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
floor_divide,
151151
greater,
152152
greater_equal,
153+
hypot,
153154
imag,
154155
isfinite,
155156
isinf,
@@ -214,6 +215,7 @@
214215
"floor_divide",
215216
"greater",
216217
"greater_equal",
218+
"hypot",
217219
"imag",
218220
"isfinite",
219221
"isinf",

array_api_strict/_elementwise_functions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,18 @@ def greater_equal(x1: Array, x2: Array, /) -> Array:
455455
x1, x2 = Array._normalize_two_args(x1, x2)
456456
return Array._new(np.greater_equal(x1._array, x2._array))
457457

458+
def hypot(x1: Array, x2: Array, /) -> Array:
459+
"""
460+
Array API compatible wrapper for :py:func:`np.hypot <numpy.hypot>`.
461+
462+
See its docstring for more information.
463+
"""
464+
if x1.dtype not in _real_floating_dtypes or x2.dtype not in _real_floating_dtypes:
465+
raise TypeError("Only real floating-point dtypes are allowed in hypot")
466+
# Call result type here just to raise on disallowed type combinations
467+
_result_type(x1.dtype, x2.dtype)
468+
x1, x2 = Array._normalize_two_args(x1, x2)
469+
return Array._new(np.hypot(x1._array, x2._array))
458470

459471
def imag(x: Array, /) -> Array:
460472
"""

0 commit comments

Comments
 (0)