Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions modepy/quadrature/jacobi_gauss.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,17 @@ def jacobi_gauss_lobatto_nodes(
alpha: float, beta: float, N: int, # ruff:ignore[invalid-argument-name]
backend: str | None = None,
force_dim_axis: bool = False) -> ArrayF:
"""Compute Gauss-Lobatto quadrature nodes associated with
r"""Compute Gauss-Lobatto quadrature nodes associated with
:class:`~modepy.JacobiGaussQuadrature` with the same parameters.

This helper returns only the *N+1* nodes; the corresponding
Gauss-Lobatto quadrature rule (using these nodes with appropriate
weights) is exact for polynomials up to degree :math:`2N - 1`
when :math:`N \\ge 1`.
when :math:`N \ge 1`.

For :math:`N = 0`, this function returns a single node at ``0``.
This degenerate case does not correspond to a Gauss-Lobatto node
set with endpoints :math:`\\pm 1`, but is provided for convenience.
set with endpoints :math:`\pm 1`, but is provided for convenience.
"""

x: np.ndarray[tuple[int, ...], np.dtype[np.floating]] = np.zeros((N + 1,))
Expand Down
6 changes: 3 additions & 3 deletions modepy/quadrature/kronrod.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,21 +608,21 @@

def test_semi_pos_neg():
# Semi-infinite negative: e^x from -inf to 0
approx_int, err_est = quadgk(lambda x: np.exp(x), -np.inf, 0)
approx_int, err_est = quadgk(np.exp, -np.inf, 0)

Check failure on line 611 in modepy/quadrature/kronrod.py

View workflow job for this annotation

GitHub Actions / basedpyright

Argument of type "_UFunc_Nin1_Nout1[Literal['exp'], Literal[10], None]" cannot be assigned to parameter "f" of type "ScalarOrArrayIntegrand" in function "quadgk"   "_UFunc_Nin1_Nout1[Literal['exp'], Literal[10], None]" is incompatible with protocol "ScalarOrArrayIntegrand"     "__call__" is an incompatible type       One or more overloads of "__call__" is not assignable         No overloaded function matches type "(x: Array1D[floating[Any]]) -> Array1D[complexfloating[Any, Any]]" (reportArgumentType)
assert err_est < 1e-10
check("integral e^x from -inf to 0", approx_int, 1.0)


def test_multi_break():
# Multiple breakpoints
approx_int, err_est = quadgk(lambda x: abs(x), -1, 0, 1)
approx_int, err_est = quadgk(abs, -1, 0, 1)

Check failure on line 618 in modepy/quadrature/kronrod.py

View workflow job for this annotation

GitHub Actions / basedpyright

Argument of type "(x: SupportsAbs[_T@abs], /) -> _T@abs" cannot be assigned to parameter "f" of type "ScalarOrArrayIntegrand" in function "quadgk"   One or more overloads of "__call__" is not assignable     Type "(x: SupportsAbs[_T@abs], /) -> _T@abs" is not assignable to type "(x: Array1D[floating[Any]]) -> Array1D[complexfloating[Any, Any]]"       Missing keyword parameter "x"         Position-only parameter mismatch; parameter "x" is not position-only         Could not bind method "__abs__" because "ndarray[tuple[int], dtype[floating[Any]]]" is not assignable to parameter "self"           "ndarray[tuple[int], dtype[floating[Any]]]" is not assignable to "ndarray[ShapeT@__abs__, _dtype]"         Position-only parameter mismatch; expected 1 but received 0         Function return type "ndarray[tuple[int], dtype[floating[Any]]]" is incompatible with type "Array1D[complexfloating[Any, Any]]" (reportArgumentType)
assert err_est < 1e-10
check("integral |x| from -1 to 1 (with breakpoint)", approx_int, 1.0)


def test_oscillatory():
# Oscillatory
approx_int, err_est = quadgk(lambda x: np.sin(x), 0, np.pi)
approx_int, err_est = quadgk(np.sin, 0, np.pi)

Check failure on line 625 in modepy/quadrature/kronrod.py

View workflow job for this annotation

GitHub Actions / basedpyright

Argument of type "_UFunc_Nin1_Nout1[Literal['sin'], Literal[9], None]" cannot be assigned to parameter "f" of type "ScalarOrArrayIntegrand" in function "quadgk"   "_UFunc_Nin1_Nout1[Literal['sin'], Literal[9], None]" is incompatible with protocol "ScalarOrArrayIntegrand"     "__call__" is an incompatible type       One or more overloads of "__call__" is not assignable         No overloaded function matches type "(x: Array1D[floating[Any]]) -> Array1D[complexfloating[Any, Any]]" (reportArgumentType)
assert err_est < 1e-10
check("integral sin(x) from 0 to pi", approx_int, 2.0)
Comment on lines 623 to 627

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these tests here on purpose? Shouldn't they be in modepy/test?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are! I noticed this pattern in Rust code, where tests live alongside the code being tested, and rather liked it. At least for the packages where the tests live under the main package import, they're also guaranteed to be discovered. Do you not like this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. I don't know, can't say I have too much of a preference. The main worry is just consistency, I guess? i.e. I wouldn't have looked here for tests.

Although I'm not a big fan of these being exported by default. Does pytest not find them if they're not in __all__?


Expand Down
2 changes: 2 additions & 0 deletions modepy/test/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,9 @@ def agree(x: bool, y: bool) -> bool:

for a in [5, _Inf(), np.inf, -np.inf, "z"]:
for b in [5, _Inf(), np.inf, -np.inf, "z"]:
# ruff: ignore[unnecessary-dunder-call]
assert agree(a.__lt__(b), b.__gt__(a)) # pyright: ignore[reportArgumentType]
# ruff: ignore[unnecessary-dunder-call]
assert agree(a.__le__(b), b.__ge__(a)) # pyright: ignore[reportArgumentType]


Expand Down
11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ extend-select = [
"TC",
]
extend-ignore = [
"C90", # McCabe complexity
"multiple-spaces-before-operator",
"complex-structure",
"error-suffix-on-exception-name",
"missing-whitespace-around-arithmetic-operator",
"multiple-spaces-after-comma",
"tab-after-comma",
"module-import-not-at-top-of-file",
"error-suffix-on-exception-name",
"multiple-spaces-after-comma",
"multiple-spaces-before-operator",
"non-empty-init-module",
"pytest-parameter-with-default-argument",
"tab-after-comma",
"type-check-without-type-error",
]
allowed-confusables = ["‐", "–"]
Expand Down
Loading