Repository navigation
Commit 380c968
authored
Defer scipy imports so import spatialmath is faster (#244)
Part of #234 (the SciPy half; SymPy is not changed here).
`spatialmath/base/quaternions.py` and `spatialmath/spline.py` imported
`scipy.interpolate` / `scipy.spatial.transform` at module level, so
`import spatialmath` pulled in scipy even though only `qrand` (with a
theta range), `SplineSE3` and `BSplineSE3` use it. These imports now
happen inside those functions. The `interpolate.interp1d` return
annotation stays as a string under `TYPE_CHECKING`.
Measured with `python -X importtime -c "import spatialmath"` on one
machine, single run each: 1.42 s before, 0.40 s after. `scipy` is no
longer in `sys.modules` after `import spatialmath`. `sympy` still is, so
the remaining part of #234 (`issymbol` / `argcheck`) is untouched.
Added `tests/test_import.py`, which imports spatialmath in a subprocess
and checks that no scipy module is loaded. It fails on master and passes
here.
Run: full `tests/` suite with `MPLBACKEND=Agg`, 348 passed, 3 skipped;
black 23.10.0 clean on the changed files; `qrand(theta_range=...)` and
importing `SplineSE3`/`BSplineSE3` smoke-checked. Not run: the spline
classes were not exercised by hand beyond what the existing tests cover,
and only Python 3 on Linux was tried.1 parent d1a945d commit 380c968
3 files changed
Lines changed: 28 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
920 | 922 | | |
921 | 923 | | |
922 | 924 | | |
923 | | - | |
| 925 | + | |
924 | 926 | | |
925 | 927 | | |
926 | 928 | | |
| |||
933 | 935 | | |
934 | 936 | | |
935 | 937 | | |
| 938 | + | |
| 939 | + | |
936 | 940 | | |
937 | 941 | | |
938 | 942 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
| |||
122 | 120 | | |
123 | 121 | | |
124 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
292 | 293 | | |
293 | 294 | | |
294 | 295 | | |
| 296 | + | |
| 297 | + | |
295 | 298 | | |
296 | 299 | | |
297 | 300 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
0 commit comments