L2 norm of tensor clamped above a minimum value `eps`. :param sqrt: if `False`, returns the square of the L2 norm
(x, axis=-1, keepdims=False, eps=1e-8, sqrt=True)
| 53 | |
| 54 | |
| 55 | def _norm_no_nan(x, axis=-1, keepdims=False, eps=1e-8, sqrt=True): |
| 56 | ''' |
| 57 | L2 norm of tensor clamped above a minimum value `eps`. |
| 58 | |
| 59 | :param sqrt: if `False`, returns the square of the L2 norm |
| 60 | ''' |
| 61 | out = torch.clamp(torch.sum(torch.square(x), axis, keepdims), min=eps) |
| 62 | return torch.sqrt(out) if sqrt else out |
| 63 | |
| 64 | |
| 65 | def _split(x, nv): |