|
6 | 6 | broadcasting to support batching of arbitrary leading dimensions. |
7 | 7 | """ |
8 | 8 |
|
| 9 | +import os |
| 10 | +import sys |
9 | 11 | from typing import Callable |
10 | 12 |
|
| 13 | +# SciPy array API check. We use the most recent array API features, which require the |
| 14 | +# SCIPY_ARRAY_API environment variable to be set to "1". This flag MUST be set before importing |
| 15 | +# scipy, because scipy's C extensions cannot be unloaded once they have been imported. Therefore, we |
| 16 | +# have to error out if the flag is not set. Otherwise, we immediately import scipy to ensure that no |
| 17 | +# other package sets the flag to a different value before importing scipy. |
| 18 | + |
| 19 | +if "scipy" in sys.modules and os.environ.get("SCIPY_ARRAY_API") != "1": |
| 20 | + msg = """scipy has already been imported and the 'SCIPY_ARRAY_API' environment variable has not |
| 21 | + been set. Please restart your Python session and set SCIPY_ARRAY_API="1" before importing any |
| 22 | + packages that depend on scipy, or import this package first to automatically set the flag.""" |
| 23 | + raise RuntimeError(msg) |
| 24 | + |
| 25 | +os.environ["SCIPY_ARRAY_API"] = "1" |
| 26 | +import scipy # noqa: F401, ensure scipy uses array API features |
| 27 | + |
11 | 28 | from drone_controllers.core import parametrize |
12 | | -from drone_controllers.mellinger import ( |
13 | | - attitude2force_torque as mellinger_attitude2force_torque, |
14 | | -) |
| 29 | +from drone_controllers.mellinger import attitude2force_torque as mellinger_attitude2force_torque |
15 | 30 | from drone_controllers.mellinger import state2attitude as mellinger_state2attitude |
16 | 31 |
|
17 | 32 | available_controller: dict[str, Callable] = { |
|
0 commit comments