|
| 1 | +from typing import TypeAlias, assert_type, type_check_only |
| 2 | + |
| 3 | +import numpy as np |
| 4 | +import numpy.typing as npt |
| 5 | + |
| 6 | +from scipy.integrate import odeint |
| 7 | + |
| 8 | +# based on the example from the `odeint` docstring |
| 9 | +@type_check_only |
| 10 | +def pend_0(y: npt.NDArray[np.floating], t: float) -> list[float]: ... |
| 11 | +@type_check_only |
| 12 | +def pend_ty_0(t: float, y: npt.NDArray[np.floating]) -> list[float]: ... |
| 13 | +@type_check_only |
| 14 | +def pend(y: npt.NDArray[np.floating], t: float, b: float, c: float) -> list[float]: ... |
| 15 | +@type_check_only |
| 16 | +def pend_ty(t: float, y: npt.NDArray[np.floating], b: float, c: float) -> list[float]: ... |
| 17 | + |
| 18 | +y0: list[float] = ... |
| 19 | +b: float = ... |
| 20 | +c: float = ... |
| 21 | +t: npt.NDArray[np.float64] = ... |
| 22 | + |
| 23 | +_VecF64: TypeAlias = np.ndarray[tuple[int], np.dtype[np.float64]] |
| 24 | +_MatF64: TypeAlias = np.ndarray[tuple[int, int], np.dtype[np.float64]] |
| 25 | + |
| 26 | +### |
| 27 | + |
| 28 | +assert_type(odeint(pend_0, y0, t), _MatF64) |
| 29 | +assert_type(odeint(pend_0, y0, t, full_output=True)[0], _MatF64) |
| 30 | +assert_type(odeint(pend_0, y0, t, full_output=True)[1]["hu"], _VecF64) |
| 31 | +assert_type(odeint(pend_0, y0, t, full_output=True)[1]["message"], str) |
| 32 | + |
| 33 | +assert_type(odeint(pend_ty_0, y0, t, tfirst=True), _MatF64) |
| 34 | +assert_type(odeint(pend_ty_0, y0, t, full_output=True, tfirst=True)[0], _MatF64) |
| 35 | +assert_type(odeint(pend_ty_0, y0, t, full_output=True, tfirst=True)[1]["hu"], _VecF64) |
| 36 | +assert_type(odeint(pend_ty_0, y0, t, full_output=True, tfirst=True)[1]["message"], str) |
| 37 | + |
| 38 | +assert_type(odeint(pend, y0, t, args=(b, c)), _MatF64) |
| 39 | +assert_type(odeint(pend, y0, t, full_output=True, args=(b, c))[0], _MatF64) |
| 40 | +assert_type(odeint(pend, y0, t, full_output=True, args=(b, c))[1]["hu"], _VecF64) |
| 41 | +assert_type(odeint(pend, y0, t, full_output=True, args=(b, c))[1]["message"], str) |
| 42 | + |
| 43 | +assert_type(odeint(pend_ty, y0, t, args=(b, c), tfirst=True), _MatF64) |
| 44 | +assert_type(odeint(pend_ty, y0, t, full_output=True, args=(b, c), tfirst=True)[0], _MatF64) |
| 45 | +assert_type(odeint(pend_ty, y0, t, full_output=True, args=(b, c), tfirst=True)[1]["hu"], _VecF64) |
| 46 | +assert_type(odeint(pend_ty, y0, t, full_output=True, args=(b, c), tfirst=True)[1]["message"], str) |
0 commit comments