Skip to content

Commit

Permalink
Merge pull request #18 from jorenham/fix/scipy.integrate
Browse files Browse the repository at this point in the history
fix `scipy.integrate` stubtests
  • Loading branch information
jorenham authored Sep 5, 2024
2 parents 5f5e44f + 7f71807 commit 7d39478
Show file tree
Hide file tree
Showing 14 changed files with 550 additions and 226 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ pyright), the "type completeness score" is **42.6%**.
| `scipy.__init__` | 3: ready |
| `scipy._lib` | 2: partial |
| `scipy.cluster` | 1: skeleton |
| `scipy.constants` | 3: ready |
| `scipy.constants` | **4: done** |
| `scipy.datasets` | 2: partial |
| `scipy.fft` | 2: partial |
| `scipy.fft._pocketfft` | 2: partial |
| `scipy.fftpack` | 2: partial |
| `scipy.integrate` | 3: ready |
| `scipy.integrate` | **4: done** |
| `scipy.integrate._bvp` | 2: partial |
| `scipy.integrate._ivp` | 2: partial |
| `scipy.interpolate` | 2: partial |
| `scipy.io` | 2: partial |
Expand All @@ -115,11 +116,11 @@ pyright), the "type completeness score" is **42.6%**.
| `scipy.special.cython_special` | 2: partial |
| `scipy.stats` | 2: partial |
| `scipy.stats.contingency` | 1: skeleton |
| `scipy.stats.distributions` | 4: done |
| `scipy.stats.distributions` | **4: done** |
| `scipy.stats.mstats` | 1: skeleton |
| `scipy.stats.qmc` | 2: partial |
| `scipy.stats.sampling` | 1: skeleton |
| `scipy.version` | 4: done |
| `scipy.version` | **4: done** |

Status labels:

Expand Down
35 changes: 27 additions & 8 deletions scipy-stubs/integrate/_bvp.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# TODO: Annotate the private functions as well

from collections.abc import Callable, Sequence
from typing import Any, Final, Generic, Literal, TypeAlias, overload
from typing_extensions import TypeVar

import numpy as np
import numpy.typing as npt
import optype.numpy as onpt
from scipy._typing import UntypedCallable
from scipy.interpolate import PPoly

_SCT = TypeVar("_SCT", bound=np.generic)
Expand Down Expand Up @@ -40,13 +39,34 @@ _FunBCR_p: TypeAlias = Callable[
]
_FunBCR_jac: TypeAlias = Callable[
[_Array_1d[_SCT_fc], _Array_1d[_SCT_fc]],
tuple[npt.NDArray[_SCT_fc], npt.NDArray[_SCT_fc]]
tuple[npt.NDArray[_SCT_fc], npt.NDArray[_SCT_fc]],
]
_FunBCR_jac_p: TypeAlias = Callable[
[_Array_1d[_SCT_fc], _Array_1d[_SCT_fc], _Array_1d[np.float64]],
tuple[npt.NDArray[_SCT_fc], npt.NDArray[_SCT_fc], npt.NDArray[_SCT_fc]]
tuple[npt.NDArray[_SCT_fc], npt.NDArray[_SCT_fc], npt.NDArray[_SCT_fc]],
]

EPS: Final[float]
TERMINATION_MESSAGES: Final[dict[int, str]]

# private functions
# TODO: Annotate these
estimate_fun_jac: UntypedCallable
estimate_bc_jac: UntypedCallable
compute_jac_indices: UntypedCallable
stacked_matmul: UntypedCallable
construct_global_jac: UntypedCallable
collocation_fun: UntypedCallable
prepare_sys: UntypedCallable
solve_newton: UntypedCallable
print_iteration_progress: Callable[..., None]
estimate_rms_residuals: UntypedCallable
create_spline: UntypedCallable
modify_mesh: UntypedCallable
wrap_functions: UntypedCallable

def print_iteration_header() -> None: ...

# NOTE: this inherits from `scipy.optimize.OptimizeResult` at runtime.
# But because `BVPResult` doesn't share all members (and optional attributes
# still aren't a thing), it was omitted as a base class here.
Expand All @@ -59,10 +79,9 @@ class BVPResult(Generic[_SCT_fc]):
status: Final[Literal[0, 1, 2]]
message: Final[str]
success: Final[bool]
@property
def y(self, /) -> onpt.Array[tuple[int, int], _SCT_fc]: ...
@property
def yp(self) -> onpt.Array[tuple[int, int], _SCT_fc]: ...

y: onpt.Array[tuple[int, int], _SCT_fc]
yp: onpt.Array[tuple[int, int], _SCT_fc]

# public
@overload
Expand Down
15 changes: 9 additions & 6 deletions scipy-stubs/integrate/_ivp/base.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from collections.abc import Callable, Sequence
from typing import Any, ClassVar, Final, Generic, Literal, TypeAlias, TypeVar
from typing import Any, ClassVar, Final, Generic, Literal, TypeAlias, TypeVar, overload

import numpy as np
import numpy.typing as npt
import optype.numpy as onpt
from scipy._typing import Untyped
import scipy._typing as spt

_VT = TypeVar("_VT", bound=npt.NDArray[np.inexact[Any]], default=npt.NDArray[np.inexact[Any]])

Expand Down Expand Up @@ -54,9 +54,12 @@ class DenseOutput:
t: Final[float]
t_min: Final[float]
t_max: Final[float]
def __init__(self, t_old: float, t: float, /) -> None: ...
def __call__(self, /, t: _ArrayLikeReal) -> Untyped: ...
def __init__(self, /, t_old: float, t: float) -> None: ...
@overload
def __call__(self, /, t: spt.AnyReal) -> onpt.Array[tuple[int], np.inexact[Any]]: ...
@overload
def __call__(self, /, t: _ArrayLikeReal) -> npt.NDArray[np.inexact[Any]]: ...

class ConstantDenseOutput(DenseOutput, Generic[_VT]):
value: Untyped
def __init__(self, t_old: float, t: float, /, value: _VT) -> None: ...
value: _VT
def __init__(self, /, t_old: float, t: float, value: _VT) -> None: ...
3 changes: 2 additions & 1 deletion scipy-stubs/integrate/_ivp/bdf.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class BDF(OdeSolver):
LU: Untyped
def __init__(
self,
/,
fun: UntypedCallable,
t0: Untyped,
y0: Untyped,
Expand All @@ -62,4 +63,4 @@ class BdfDenseOutput(DenseOutput):
t_shift: Untyped
denom: Untyped
D: Untyped
def __init__(self, t_old: float, t: float, /, h: Untyped, order: Untyped, D: Untyped) -> None: ...
def __init__(self, /, t_old: float, t: float, h: Untyped, order: Untyped, D: Untyped) -> None: ...
2 changes: 1 addition & 1 deletion scipy-stubs/integrate/_ivp/ivp.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class OdeResult(Generic[_SCT_cf]):
message: str
success: bool

def prepare_events(events: UntypedCallable | Sequence[UntypedCallable], t0: Untyped) -> tuple[Untyped, Untyped, Untyped]: ...
def prepare_events(events: UntypedCallable | Sequence[UntypedCallable]) -> tuple[Untyped, Untyped, Untyped]: ...
def solve_event_equation(event: Untyped, sol: Untyped, t_old: Untyped, t: Untyped) -> Untyped: ...
def handle_events(
sol: DenseOutput,
Expand Down
3 changes: 2 additions & 1 deletion scipy-stubs/integrate/_ivp/lsoda.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ from .base import DenseOutput, OdeSolver
class LSODA(OdeSolver):
def __init__(
self,
/,
fun: UntypedCallable,
t0: Untyped,
y0: Untyped,
Expand All @@ -26,4 +27,4 @@ class LsodaDenseOutput(DenseOutput):
h: Untyped
yh: Untyped
p: Untyped
def __init__(self, t_old: float, t: float, /, h: Untyped, order: Untyped, yh: Untyped) -> None: ...
def __init__(self, /, t_old: float, t: float, h: Untyped, order: Untyped, yh: Untyped) -> None: ...
3 changes: 2 additions & 1 deletion scipy-stubs/integrate/_ivp/radau.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Radau(OdeSolver):
Z: Untyped
def __init__(
self,
/,
fun: UntypedCallable,
t0: Untyped,
y0: Untyped,
Expand All @@ -69,4 +70,4 @@ class RadauDenseOutput(DenseOutput):
Q: Untyped
order: Untyped
y_old: Untyped
def __init__(self, t_old: float, t: float, /, y_old: Untyped, Q: Untyped) -> None: ...
def __init__(self, /, t_old: float, t: float, y_old: Untyped, Q: Untyped) -> None: ...
6 changes: 4 additions & 2 deletions scipy-stubs/integrate/_ivp/rk.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class RungeKutta(OdeSolver):
h_previous: Untyped
def __init__(
self,
/,
fun: UntypedCallable,
t0: Untyped,
y0: Untyped,
Expand All @@ -63,6 +64,7 @@ class DOP853(RungeKutta):
K: Untyped
def __init__(
self,
/,
fun: UntypedCallable,
t0: Untyped,
y0: Untyped,
Expand All @@ -80,10 +82,10 @@ class RkDenseOutput(DenseOutput):
Q: Untyped
order: Untyped
y_old: Untyped
def __init__(self, t_old: float, t: float, /, y_old: Untyped, Q: Untyped) -> None: ...
def __init__(self, /, t_old: float, t: float, y_old: Untyped, Q: Untyped) -> None: ...

class Dop853DenseOutput(DenseOutput):
h: Untyped
F: Untyped
y_old: Untyped
def __init__(self, t_old: float, t: float, /, y_old: Untyped, F: Untyped) -> None: ...
def __init__(self, /, t_old: float, t: float, y_old: Untyped, F: Untyped) -> None: ...
Loading

0 comments on commit 7d39478

Please sign in to comment.