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