fn

hypot

Tensor
hypot(input: Tensor, other: Tensor | Scalar)
source

Element-wise Euclidean norm of two operands, computed in a numerically stable way.

Returns x2+y2\sqrt{x^2 + y^2} while avoiding intermediate overflow / underflow when one operand is much larger than the other.

Parameters

inputTensor
Left operand.
otherTensor or scalar
Right operand. Broadcasts against input following the standard broadcasting rules; Python scalars are promoted to a tensor of matching dtype.

Returns

Tensor

Element-wise result with shape broadcast(input.shape, other.shape) and dtype determined by the usual type-promotion rules.

Notes

Mathematical definition:

outi=inputi2+otheri2\text{out}_i = \sqrt{\text{input}_i^{2} + \text{other}_i^{2}}

Equivalent to sqrt(input**2 + other**2) but with better numerical properties at the dtype extremes.

Examples

>>> import lucid
>>> a = lucid.tensor([1.0, 2.0, 3.0])
>>> b = lucid.tensor([4.0, 5.0, 6.0])
>>> lucid.hypot(a, b)
Tensor([...])