Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix scipy.integrate quad integrand function signatures #38

Merged
merged 4 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions scipy-stubs/integrate/_ode.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class complex_ode(ode[Unpack[_Ts]], Generic[Unpack[_Ts]]):
def __init__(self, /, f: _ODEFuncC[Unpack[_Ts]], jac: _ODEFuncC[Unpack[_Ts]] | None = None) -> None: ...
@property
@override
def y(self, /) -> complex: ... # type: ignore[override]
def y(self, /) -> complex: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
@override
def integrate(self, /, t: float, step: bool = False, relax: bool = False) -> complex: ... # type: ignore[override]
def integrate(self, /, t: float, step: bool = False, relax: bool = False) -> complex: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]

def find_integrator(name: str) -> type[IntegratorBase] | None: ...

Expand Down Expand Up @@ -149,7 +149,6 @@ class vode(IntegratorBase):
first_step: float = 0.0,
) -> None: ...

# pyright: reportUnnecessaryTypeIgnoreComment=false
class zvode(vode):
active_global_handle: int
zwork: Untyped
Expand Down
5 changes: 2 additions & 3 deletions scipy-stubs/integrate/_quad_vec.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _InfiniteFunc(Protocol[_NDT_f_co]):
class LRUDict(collections.OrderedDict[tuple[float, float], _VT], Generic[_VT]):
def __init__(self, /, max_size: int) -> None: ...
@override
def update(self, other: Never, /) -> NoReturn: ... # type: ignore[override]
def update(self, other: Never, /) -> NoReturn: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]

class SemiInfiniteFunc(_InfiniteFunc[_NDT_f_co], Generic[_NDT_f_co]):
def __init__(self, /, func: Callable[[float], _NDT_f_co], start: float, infty: bool) -> None: ...
Expand Down Expand Up @@ -77,7 +77,7 @@ class _Bunch(Generic[_SCT_f_co]):

@overload
def quad_vec(
f: _QuadVecFunc[_NDT_f],
f: Callable[[float], _NDT_f],
a: float,
b: float,
epsabs: float = 1e-200,
Expand Down Expand Up @@ -110,7 +110,6 @@ def quad_vec(
args: tuple[Unpack[_Ts]],
) -> tuple[_NDT_f, float]: ...
# false positive (basedmypy==1.6.0 / mypy==1.11.1)
# pyright: reportUnnecessaryTypeIgnoreComment=false
@overload
def quad_vec( # type: ignore[overload-overlap]
f: _QuadVecFunc[float | np.float64, Unpack[_Ts]],
Expand Down
95 changes: 60 additions & 35 deletions scipy-stubs/integrate/_quadpack_py.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ from ._typing import QuadInfoDict, QuadOpts, QuadWeights

__all__ = ["IntegrationWarning", "dblquad", "nquad", "quad", "tplquad"]

_Ts = TypeVarTuple("_Ts", default=Unpack[tuple[()]])
_Ts = TypeVarTuple("_Ts")
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_T_f = TypeVar("_T_f", default=float)
Expand Down Expand Up @@ -57,7 +57,7 @@ class _QuadOutputNC(TypedDict):
neval: int

_QuadComplexFullOutput: TypeAlias = _QuadOutput1C_1 | _QuadOutput1C_2 | _QuadOutput1C_3
_QuadExplain = TypedDict("_QuadExplain", {0: str, 1: str, 2: str, 3: str, 4: str, 5: str}) # type: ignore[misc]
_QuadExplain = TypedDict("_QuadExplain", {0: str, 1: str, 2: str, 3: str, 4: str, 5: str}) # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]

@type_check_only
class _CanLenAndIter(Protocol[_T_co]):
Expand All @@ -83,10 +83,10 @@ class _OptCallable(Protocol[_T_f_contra, _OptT_co]):
# 1-dimensional quadrature
@overload
def quad(
func: _QuadFunc1[spt.AnyReal] | LowLevelCallable,
func: _QuadFunc1[spt.AnyReal, Unpack[_Ts]] | LowLevelCallable,
a: float,
b: float,
args: tuple[()] = (),
args: tuple[Unpack[_Ts]],
full_output: Literal[False, 0, None] = 0,
epsabs: float = 1.49e-08,
epsrel: float = 1.49e-08,
Expand All @@ -101,11 +101,10 @@ def quad(
) -> tuple[float, float]: ...
@overload
def quad(
func: _QuadFunc1[spt.AnyReal] | LowLevelCallable,
func: _QuadFunc1[spt.AnyReal, Unpack[_Ts]] | LowLevelCallable,
a: float,
b: float,
args: tuple[()] = (),
*,
args: tuple[Unpack[_Ts]],
full_output: Literal[True, 1],
epsabs: float = 1.49e-08,
epsrel: float = 1.49e-08,
Expand All @@ -124,10 +123,10 @@ def quad(
): ...
@overload
def quad(
func: _QuadFunc1[spt.AnyComplex] | LowLevelCallable,
func: _QuadFunc1[spt.AnyComplex, Unpack[_Ts]] | LowLevelCallable,
a: float,
b: float,
args: tuple[()] = (),
args: tuple[Unpack[_Ts]],
full_output: Literal[False, 0, None] = 0,
epsabs: float = 1.49e-08,
epsrel: float = 1.49e-08,
Expand All @@ -143,11 +142,10 @@ def quad(
) -> tuple[complex, complex]: ...
@overload
def quad(
func: _QuadFunc1[spt.AnyComplex] | LowLevelCallable,
func: _QuadFunc1[spt.AnyComplex, Unpack[_Ts]] | LowLevelCallable,
a: float,
b: float,
args: tuple[()] = (),
*,
args: tuple[Unpack[_Ts]],
full_output: Literal[True, 1],
epsabs: float = 1.49e-08,
epsrel: float = 1.49e-08,
Expand All @@ -158,14 +156,15 @@ def quad(
wopts: tuple[int, npt.NDArray[np.float32 | np.float64]] | None = None,
maxp1: int = 50,
limlst: int = 50,
*,
complex_func: Literal[True, 1],
) -> tuple[complex, complex, _QuadComplexFullOutput]: ...
@overload
def quad(
func: _QuadFunc1[spt.AnyReal, Unpack[_Ts]] | LowLevelCallable,
func: Callable[[float], spt.AnyReal] | LowLevelCallable,
a: float,
b: float,
args: tuple[Unpack[_Ts]],
args: tuple[()] = (),
full_output: Literal[False, 0, None] = 0,
epsabs: float = 1.49e-08,
epsrel: float = 1.49e-08,
Expand All @@ -180,10 +179,11 @@ def quad(
) -> tuple[float, float]: ...
@overload
def quad(
func: _QuadFunc1[spt.AnyReal, Unpack[_Ts]] | LowLevelCallable,
func: Callable[[float], spt.AnyReal] | LowLevelCallable,
a: float,
b: float,
args: tuple[Unpack[_Ts]],
args: tuple[()] = (),
*,
full_output: Literal[True, 1],
epsabs: float = 1.49e-08,
epsrel: float = 1.49e-08,
Expand All @@ -202,10 +202,10 @@ def quad(
): ...
@overload
def quad(
func: _QuadFunc1[spt.AnyComplex, Unpack[_Ts]] | LowLevelCallable,
func: Callable[[float], spt.AnyComplex] | LowLevelCallable,
a: float,
b: float,
args: tuple[Unpack[_Ts]],
args: tuple[()] = (),
full_output: Literal[False, 0, None] = 0,
epsabs: float = 1.49e-08,
epsrel: float = 1.49e-08,
Expand All @@ -221,10 +221,11 @@ def quad(
) -> tuple[complex, complex]: ...
@overload
def quad(
func: _QuadFunc1[spt.AnyComplex, Unpack[_Ts]] | LowLevelCallable,
func: Callable[[float], spt.AnyComplex] | LowLevelCallable,
a: float,
b: float,
args: tuple[Unpack[_Ts]],
args: tuple[()] = (),
*,
full_output: Literal[True, 1],
epsabs: float = 1.49e-08,
epsrel: float = 1.49e-08,
Expand All @@ -235,58 +236,57 @@ def quad(
wopts: tuple[int, npt.NDArray[np.float32 | np.float64]] | None = None,
maxp1: int = 50,
limlst: int = 50,
*,
complex_func: Literal[True, 1],
) -> tuple[complex, complex, _QuadComplexFullOutput]: ...

# 2-dimensional quadrature
@overload
def dblquad(
func: _QuadFunc2R[spt.AnyReal] | LowLevelCallable,
func: _QuadFunc2R[spt.AnyReal, Unpack[_Ts]] | LowLevelCallable,
a: float,
b: float,
gfun: float | Callable[[float], float],
hfun: float | Callable[[float], float],
args: tuple[()] = (),
args: tuple[Unpack[_Ts]],
epsabs: float = 1.49e-08,
epsrel: float = 1.49e-08,
) -> tuple[float, float]: ...
@overload
def dblquad(
func: _QuadFunc2R[spt.AnyReal, Unpack[_Ts]] | LowLevelCallable,
func: Callable[[float, float], spt.AnyReal] | LowLevelCallable,
a: float,
b: float,
gfun: float | Callable[[float], float],
hfun: float | Callable[[float], float],
args: tuple[Unpack[_Ts]],
args: tuple[()] = (),
epsabs: float = 1.49e-08,
epsrel: float = 1.49e-08,
) -> tuple[float, float]: ...

# 3-dimensional quadrature
@overload
def tplquad(
func: _QuadFunc3R[spt.AnyReal] | LowLevelCallable,
func: _QuadFunc3R[spt.AnyReal, Unpack[_Ts]] | LowLevelCallable,
a: float,
b: float,
gfun: float | Callable[[float], float],
hfun: float | Callable[[float], float],
qfun: float | Callable[[float, float], float],
rfun: float | Callable[[float, float], float],
args: tuple[()] = (),
args: tuple[Unpack[_Ts]],
epsabs: float = 1.49e-08,
epsrel: float = 1.49e-08,
) -> tuple[float, float]: ...
@overload
def tplquad(
func: _QuadFunc3R[spt.AnyReal, Unpack[_Ts]] | LowLevelCallable,
func: Callable[[float, float, float], spt.AnyReal] | LowLevelCallable,
a: float,
b: float,
gfun: float | Callable[[float], float],
hfun: float | Callable[[float], float],
qfun: float | Callable[[float, float], float],
rfun: float | Callable[[float, float], float],
args: tuple[Unpack[_Ts]],
args: tuple[()] = (),
epsabs: float = 1.49e-08,
epsrel: float = 1.49e-08,
) -> tuple[float, float]: ...
Expand All @@ -296,24 +296,49 @@ def tplquad(
def nquad(
func: _QuadFuncNR[_T_f],
ranges: _SizedIterable[_QuadRange | _RangeCallable[_T_f]],
args: op.CanIter[op.CanNext[_T_f]] | None = None,
opts: QuadOpts | _OptCallable[_T_f] | op.CanIter[op.CanNext[QuadOpts | _OptCallable[_T_f]]] | None = None,
args: op.CanIter[op.CanNext[_T_f]],
opts: QuadOpts | _OptCallable[float | _T_f] | op.CanIter[op.CanNext[QuadOpts | _OptCallable[float | _T_f]]] | None = None,
full_output: Literal[False, 0, None] = False,
) -> tuple[float, float]: ...
@overload
def nquad(
func: _QuadFuncNR,
ranges: _SizedIterable[_QuadRange | _RangeCallable],
args: None = None,
opts: QuadOpts | _OptCallable | op.CanIter[op.CanNext[QuadOpts | _OptCallable]] | None = None,
full_output: Literal[False, 0, None] = False,
) -> tuple[float, float]: ...
@overload
def nquad(
func: _QuadFuncNR[_T_f],
ranges: _SizedIterable[_QuadRange | _RangeCallable[_T_f]],
args: op.CanIter[op.CanNext[_T_f]] | None,
opts: QuadOpts | _OptCallable[_T_f] | op.CanIter[op.CanNext[QuadOpts | _OptCallable[_T_f]]] | None,
args: op.CanIter[op.CanNext[_T_f]],
opts: QuadOpts | _OptCallable[float | _T_f] | op.CanIter[op.CanNext[QuadOpts | _OptCallable[float | _T_f]]] | None,
full_output: Literal[True, 1],
) -> tuple[float, float, _QuadOutputNC]: ...
@overload
def nquad(
func: _QuadFuncNR,
ranges: _SizedIterable[_QuadRange | _RangeCallable],
args: None,
opts: QuadOpts | _OptCallable | op.CanIter[op.CanNext[QuadOpts | _OptCallable]] | None,
full_output: Literal[True, 1],
) -> tuple[float, float, _QuadOutputNC]: ...
@overload
def nquad(
func: _QuadFuncNR[_T_f],
ranges: _SizedIterable[_QuadRange | _RangeCallable[_T_f]],
args: op.CanIter[op.CanNext[_T_f]] | None = None,
opts: QuadOpts | _OptCallable[_T_f] | op.CanIter[op.CanNext[QuadOpts | _OptCallable[_T_f]]] | None = None,
args: op.CanIter[op.CanNext[_T_f]],
opts: QuadOpts | _OptCallable[float | _T_f] | op.CanIter[op.CanNext[QuadOpts | _OptCallable[float | _T_f]]] | None = None,
*,
full_output: Literal[True, 1],
) -> tuple[float, float, _QuadOutputNC]: ...
@overload
def nquad(
func: _QuadFuncNR,
ranges: _SizedIterable[_QuadRange | _RangeCallable],
args: None = None,
opts: QuadOpts | _OptCallable | op.CanIter[op.CanNext[QuadOpts | _OptCallable]] | None = None,
*,
full_output: Literal[True, 1],
) -> tuple[float, float, _QuadOutputNC]: ...
Expand Down
15 changes: 8 additions & 7 deletions scipy-stubs/integrate/_quadrature.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ _NestedReal: TypeAlias = Sequence[float] | Sequence[_NestedReal]
_NestedComplex: TypeAlias = Sequence[complex] | Sequence[_NestedComplex]
_ArrayLike_uif: TypeAlias = _NestedReal | onpt.AnyFloatingArray | onpt.AnyIntegerArray
_ArrayLike_uifc: TypeAlias = _NestedComplex | onpt.AnyNumberArray
_QuadFuncOut: TypeAlias = np.ndarray[onpt.AtLeast1D, np.dtype[np.floating[Any]]] | float | np.floating[Any]
_QuadFuncOut: TypeAlias = onpt.Array[tuple[int, ...], np.floating[Any]] | Sequence[float]

_NDT_f = TypeVar("_NDT_f", bound=_QuadFuncOut)
_NDT_f_co = TypeVar("_NDT_f_co", bound=_QuadFuncOut, covariant=True)
_Ts = TypeVarTuple("_Ts", default=Unpack[tuple[()]])
_Ts = TypeVarTuple("_Ts")

@type_check_only
class _VectorizedQuadFunc(Protocol[_NDT_f_co, Unpack[_Ts]]):
def __call__(self, x: float, /, *args: Unpack[_Ts]) -> _NDT_f_co: ...
def __call__(self, x: onpt.Array[tuple[int], np.float64], /, *args: Unpack[_Ts]) -> _NDT_f_co: ...

class AccuracyWarning(Warning): ...

Expand Down Expand Up @@ -128,18 +128,19 @@ def cumulative_simpson(
# function-based
@overload
def fixed_quad(
func: _VectorizedQuadFunc[_NDT_f],
func: _VectorizedQuadFunc[_NDT_f, Unpack[_Ts]],
a: spt.AnyReal,
b: spt.AnyReal,
args: tuple[()] = (),
args: tuple[Unpack[_Ts]],
n: op.CanIndex = 5,
) -> _NDT_f: ...
@overload
def fixed_quad(
func: _VectorizedQuadFunc[_NDT_f, Unpack[_Ts]],
# func: _VectorizedQuadFunc[_NDT_f],
func: Callable[[onpt.Array[tuple[int], np.float64]], _NDT_f],
a: spt.AnyReal,
b: spt.AnyReal,
args: tuple[Unpack[_Ts]],
args: tuple[()] = (),
n: op.CanIndex = 5,
) -> _NDT_f: ...

Expand Down
1 change: 0 additions & 1 deletion scipy-stubs/sparse/_dok.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pyright: reportUnnecessaryTypeIgnoreComment=false
from collections.abc import Iterable
from typing_extensions import Self, override

Expand Down
1 change: 0 additions & 1 deletion scipy-stubs/special/_orthogonal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ __all__ = [

_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])

# pyright: reportUnnecessaryTypeIgnoreComment=false
# mypy: disable-error-code="explicit-override"
class orthopoly1d(np.poly1d):
limits: tuple[float, float]
Expand Down
Loading