Coverage for src\attipy\_vectorops.py: 83%

1 import numpy as np

2 from numba import njit

3 from numpy.typing import NDArray

4

5

6@njit # type: ignore[misc]

7 def _normalize(q: NDArray[np.float64]) -> NDArray[np.float64]:

8 """

9 L2-normalize a vector.

10

11 Parameters

12 ----------

13 q : numpy.ndarray

14 Vector to be normalized

15

16 Returns

17 -------

18 numpy.ndarray

19 Normalized copy of `q`.

20 """

21 return q / np.sqrt((q * q).sum()) # type: ignore[no-any-return] # numpy funcs declare Any as return when given scalar-like