clamped_length#
- iskra.geometry.distances.clamped_length(x: Tensor, dim: int | tuple[int, ...] = -1, keepdim: bool = False, eps: float = 1e-06) Tensor[SOURCE]#
Computes the lengths of a set of vectors and then clamps them.
Helps avoid numerical issues when computing lengths of vectors, such as:
The gradient of the square-root tends to infinitey as we get closer to zero.
We often wish to divide by length, which also explodes around zero.
- Parameters:
- Returns:
(
Tensor[Any, [Bs] | [Bs, 1]]) – Lengths of vectors along dimension dim. Last dimension of output is 1 ifkeepdim=True, otherwise it is removed.