Skip to content

Commit fab7d5d

Browse files
RoboX2020taughz
authored andcommitted
Defer scipy.interpolate import in quaternions
1 parent a660079 commit fab7d5d

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

@@ -920,7 +922,7 @@ def _compute_cdf_sin_squared(theta: float):
920922
@lru_cache(maxsize=1)
921923
def _generate_inv_cdf_sin_squared_interp(
922924
num_interpolation_points: int = 256,
923-
) -> interpolate.interp1d:
925+
) -> "interpolate.interp1d":
924926
"""
925927
Computes an interpolation function for the inverse CDF of the distribution of angular magnitude.
926928
@@ -933,6 +935,8 @@ def _generate_inv_cdf_sin_squared_interp(
933935
This function returns interpolation function for the inverse of the integral of the
934936
pdf of angular magnitudes (2/pi * sin^2(theta/2)), which is not analytically defined.
935937
"""
938+
import scipy.interpolate as interpolate # deferred, it is slow to import
939+
936940
cdf_sin_squared_interp_angles = np.linspace(0, np.pi, num_interpolation_points)
937941
cdf_sin_squared_interp_values = _compute_cdf_sin_squared(
938942
cdf_sin_squared_interp_angles

0 commit comments

Comments
 (0)