Skip to content

Commit 3573e47

Browse files
committed
add njit
1 parent 3544fb4 commit 3573e47

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/smsfusion/_smoothing.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from warnings import warn
33

44
import numpy as np
5+
from numba import njit
56
from numpy.typing import NDArray
67

78
from ._ins import AHRS, VRU, AidedINS
@@ -242,6 +243,7 @@ def euler(self, degrees: bool = False) -> NDArray:
242243
return np.degrees(theta) if degrees else theta
243244

244245

246+
@njit # type: ignore[misc]
245247
def _rts_backward_sweep(
246248
x: list[NDArray],
247249
dx: list[NDArray],
@@ -281,9 +283,11 @@ def _rts_backward_sweep(
281283
filtering with MATLAB exercises", 4th ed. Wiley, pp. 208-212, 2012.
282284
"""
283285

284-
x = x.copy() # np.asarray_chkfinite(x).copy()
285-
dx = dx.copy() # np.asarray_chkfinite(dx).copy()
286-
P = P.copy() # np.asarray_chkfinite(P).copy()
286+
x = x.copy()
287+
dx = dx.copy()
288+
P = P.copy()
289+
290+
q_prealloc = np.array([2.0, 0.0, 0.0, 0.0]) # Preallocation
287291

288292
# Backward sweep
289293
for k in range(len(x) - 2, -1, -1):
@@ -296,7 +300,8 @@ def _rts_backward_sweep(
296300

297301
# Reset
298302
dda = ddx[6:9]
299-
ddq = (1.0 / np.sqrt(4.0 + dda.T @ dda)) * np.r_[2.0, dda]
303+
q_prealloc[1:] = dda
304+
ddq = (1.0 / np.sqrt(4.0 + dda.T @ dda)) * q_prealloc
300305
x[k][:3] = x[k][:3] + ddx[:3]
301306
x[k][3:6] = x[k][3:6] + ddx[3:6]
302307
x[k][6:10] = _quaternion_product(x[k][6:10], ddq)

0 commit comments

Comments
 (0)