Skip to content

Commit a105dbb

Browse files
authored
Defer scipy.interpolate import in quaternions
1 parent 08cb279 commit a105dbb

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎spatialmath/base/quaternions.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
import spatialmath.base as smb
1717
from spatialmath.base.argcheck import getunit
1818
from spatialmath.base.types import *
19-
import scipy.interpolate as interpolate
20-
from typing import Optional
19+
from typing import TYPE_CHECKING, Optional
2120
from functools import lru_cache
2221
import warnings
2322

23+
if TYPE_CHECKING:
24+
import scipy.interpolate as interpolate
25+
2426
_eps = np.finfo(np.float64).eps
2527

2628

@@ -897,7 +899,7 @@ def _compute_cdf_sin_squared(theta: float):
897899
@lru_cache(maxsize=1)
898900
def _generate_inv_cdf_sin_squared_interp(
899901
num_interpolation_points: int = 256,
900-
) -> interpolate.interp1d:
902+
) -> "interpolate.interp1d":
901903
"""
902904
Computes an interpolation function for the inverse CDF of the distribution of angular magnitude.
903905
@@ -910,6 +912,8 @@ def _generate_inv_cdf_sin_squared_interp(
910912
This function returns interpolation function for the inverse of the integral of the
911913
pdf of angular magnitudes (2/pi * sin^2(theta/2)), which is not analytically defined.
912914
"""
915+
import scipy.interpolate as interpolate # deferred, it is slow to import
916+
913917
cdf_sin_squared_interp_angles = np.linspace(0, np.pi, num_interpolation_points)
914918
cdf_sin_squared_interp_values = _compute_cdf_sin_squared(
915919
cdf_sin_squared_interp_angles

0 commit comments

Comments
 (0)