diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index 14cad9da..41d3b058 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -10221,22 +10221,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 20, - "endColumn": 37, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 20, - "endColumn": 37, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -36535,54 +36519,6 @@ } ], "./sumpy/point_calculus.py": [ - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 23, - "endColumn": 29, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 23, - "endColumn": 29, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 31, - "endColumn": 32, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 39, - "endColumn": 44, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 48, - "endColumn": 53, - "lineCount": 1 - } - }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 19, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -36599,14 +36535,6 @@ "lineCount": 1 } }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 20, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -36639,22 +36567,6 @@ "lineCount": 1 } }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 16, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 29, - "endColumn": 40, - "lineCount": 1 - } - }, { "code": "reportUnknownArgumentType", "range": { @@ -36671,14 +36583,6 @@ "lineCount": 1 } }, - { - "code": "reportUnannotatedClassAttribute", - "range": { - "startColumn": 13, - "endColumn": 19, - "lineCount": 1 - } - }, { "code": "reportUnknownMemberType", "range": { @@ -36735,14 +36639,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 8, - "endColumn": 13, - "lineCount": 1 - } - }, { "code": "reportUnknownParameterType", "range": { @@ -36752,51 +36648,27 @@ } }, { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 23, - "endColumn": 26, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 23, - "endColumn": 26, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 28, - "endColumn": 29, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", + "code": "reportAny", "range": { - "startColumn": 28, - "endColumn": 29, + "startColumn": 16, + "endColumn": 21, "lineCount": 1 } }, { - "code": "reportUnknownArgumentType", + "code": "reportAny", "range": { - "startColumn": 38, - "endColumn": 44, + "startColumn": 46, + "endColumn": 51, "lineCount": 1 } }, { - "code": "reportUnknownArgumentType", + "code": "reportReturnType", "range": { - "startColumn": 46, - "endColumn": 51, - "lineCount": 1 + "startColumn": 15, + "endColumn": 70, + "lineCount": 3 } }, { @@ -36943,54 +36815,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 19, - "endColumn": 23, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 19, - "endColumn": 23, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 25, - "endColumn": 33, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 25, - "endColumn": 33, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 35, - "endColumn": 42, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 18, - "endColumn": 29, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -37024,211 +36848,27 @@ } }, { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 16, - "endColumn": 47, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 17, - "endColumn": 25, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 17, - "endColumn": 25, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 15, - "endColumn": 24, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 28, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 17, - "endColumn": 25, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 17, - "endColumn": 25, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 15, - "endColumn": 24, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 28, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 17, - "endColumn": 25, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 17, - "endColumn": 25, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 15, - "endColumn": 24, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 28, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 22, - "endColumn": 30, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 22, - "endColumn": 30, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 19, - "endColumn": 28, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 36, - "endColumn": 44, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 18, - "endColumn": 21, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 18, - "endColumn": 21, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", + "code": "reportAny", "range": { "startColumn": 34, - "endColumn": 37, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 30, - "endColumn": 39, - "lineCount": 1 - } - }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 43, - "endColumn": 48, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 19, - "endColumn": 22, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 19, - "endColumn": 22, + "endColumn": 46, "lineCount": 1 } }, { - "code": "reportUnknownMemberType", + "code": "reportAny", "range": { - "startColumn": 41, - "endColumn": 50, + "startColumn": 34, + "endColumn": 46, "lineCount": 1 } }, { - "code": "reportUnknownArgumentType", + "code": "reportReturnType", "range": { - "startColumn": 54, - "endColumn": 60, - "lineCount": 1 + "startColumn": 15, + "endColumn": 31, + "lineCount": 5 } }, { @@ -37263,14 +36903,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 8, - "endColumn": 9, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -37279,14 +36911,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 8, - "endColumn": 9, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -37295,14 +36919,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 8, - "endColumn": 9, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -37424,26 +37040,26 @@ } }, { - "code": "reportUnknownParameterType", + "code": "reportUnknownMemberType", "range": { - "startColumn": 19, - "endColumn": 20, + "startColumn": 12, + "endColumn": 21, "lineCount": 1 } }, { - "code": "reportMissingParameterType", + "code": "reportAny", "range": { - "startColumn": 19, - "endColumn": 20, + "startColumn": 23, + "endColumn": 35, "lineCount": 1 } }, { - "code": "reportUnknownMemberType", + "code": "reportAny", "range": { - "startColumn": 12, - "endColumn": 21, + "startColumn": 23, + "endColumn": 35, "lineCount": 1 } }, @@ -37471,86 +37087,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownArgumentType", - "range": { - "startColumn": 55, - "endColumn": 56, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 4, - "endColumn": 28, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 29, - "endColumn": 35, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 29, - "endColumn": 35, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 37, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 37, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 40, - "endColumn": 41, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 40, - "endColumn": 41, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 43, - "endColumn": 44, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 43, - "endColumn": 44, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -37560,34 +37096,26 @@ } }, { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 20, - "endColumn": 31, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", + "code": "reportAny", "range": { - "startColumn": 19, - "endColumn": 30, + "startColumn": 4, + "endColumn": 9, "lineCount": 1 } }, { - "code": "reportUnknownMemberType", + "code": "reportAny", "range": { - "startColumn": 18, - "endColumn": 28, + "startColumn": 4, + "endColumn": 17, "lineCount": 1 } }, { - "code": "reportUnknownMemberType", + "code": "reportAny", "range": { - "startColumn": 18, - "endColumn": 28, + "startColumn": 4, + "endColumn": 16, "lineCount": 1 } } @@ -50421,14 +49949,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 21, - "endColumn": 28, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { diff --git a/doc/conf.py b/doc/conf.py index cf885d0e..b6f6d0ed 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -29,6 +29,14 @@ ] sphinxconfig_missing_reference_aliases = { + # numpy + "Array1D": "class:numpy.ndarray", + "Array2D": "class:numpy.ndarray", + "np.floating": "class:numpy.floating", + "np.complexfloating": "class:numpy.complexfloating", + "np.inexact": "class:numpy.inexact", + # pytools + "obj_array.ObjectArray1D": "obj:pytools.obj_array.ObjectArray1D", # sympy "sp.Matrix": "class:sympy.matrices.dense.DenseMatrix", # pytools diff --git a/pyproject.toml b/pyproject.toml index 7a1db248..59045ea0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,10 +40,14 @@ dependencies = [ [dependency-groups] dev = [ + {include-group = "type"}, {include-group = "doc"}, {include-group = "test"}, {include-group = "lint"}, ] +type = [ + "optype" +] lint = [ "pylint", # https://github.com/astral-sh/ruff/issues/16943 diff --git a/sumpy/point_calculus.py b/sumpy/point_calculus.py index f2c3d1d2..144ddee2 100644 --- a/sumpy/point_calculus.py +++ b/sumpy/point_calculus.py @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ +from typing import TYPE_CHECKING, Literal, TypeAlias import numpy as np import numpy.linalg as la @@ -30,13 +31,27 @@ from pytools import memoize_method +if TYPE_CHECKING: + from collections.abc import Callable, Sequence + + from optype.numpy import Array1D, Array2D + + __doc__ = """ +.. autodata:: NodesKind + :noindex: + +.. class:: NodesKind + .. autoclass:: CalculusPatch .. autofunction:: frequency_domain_maxwell """ +NodesKind: TypeAlias = Literal["chebyshev", "equispaced", "legendre"] + + class CalculusPatch: """Sets up a grid of points on which derivatives can be calculated. Useful to verify that an evaluated potential actually solves a PDE. @@ -64,7 +79,16 @@ class CalculusPatch: .. automethod:: plot_nodes .. automethod:: plot """ - def __init__(self, center, h=1e-1, order=4, nodes="chebyshev"): + dim: int + center: Array1D[np.floating] + points: Array2D[np.floating] + npoints: int + + def __init__(self, + center: Array1D[np.floating], + h: float = 1e-1, + order: int = 4, + nodes: NodesKind = "chebyshev"): self.center = center npoints = order + 1 @@ -119,7 +143,7 @@ def _zero_eval_vec_1d(self): # The zeroth coefficient--all others involve x=0. return self._vandermonde_1d()[0] - def basis(self): + def basis(self) -> Sequence[Callable[[Array2D[np.floating]], Array1D[np.floating]]]: """ :returns: a :class:`list` containing functions that realize a high-order interpolation basis on the :py:attr:`points`. @@ -129,7 +153,7 @@ def basis(self): from pytools import indices_in_shape - def eval_basis(ind, x): + def eval_basis(ind: tuple[int, ...], x: Array2D[np.floating]): result = 1 for i in range(self.dim): coord = (x[i] - self.center[i])/(self.h/2) @@ -172,7 +196,11 @@ def _diff_mat_1d(self, nderivs): deriv_coeffs_mat = la.solve(vandermonde.T, n_diff_mat.T).T return vandermonde.dot(deriv_coeffs_mat) - def diff(self, axis, f_values, nderivs=1): + def diff(self, + axis: int, + f_values: Array1D[np.inexact], + nderivs: int = 1 + ) -> Array1D[np.inexact] | Literal[0]: """Return the derivative along *axis* of *f_values*. :arg f_values: an array of shape ``(npoints_total,)`` @@ -197,16 +225,16 @@ def diff(self, axis, f_values, nderivs=1): self._diff_mat_1d(nderivs), f_values.reshape(*self._pshape)).reshape(-1) - def dx(self, f_values): + def dx(self, f_values: Array1D[np.inexact]): return self.diff(0, f_values) - def dy(self, f_values): + def dy(self, f_values: Array1D[np.inexact]): return self.diff(1, f_values) - def dz(self, f_values): + def dz(self, f_values: Array1D[np.inexact]): return self.diff(2, f_values) - def laplace(self, f_values): + def laplace(self, f_values: Array1D[np.inexact]): """Return the Laplacian of *f_values*. :arg f_values: an array of shape ``(npoints_total,)`` @@ -215,18 +243,22 @@ def laplace(self, f_values): return sum(self.diff(iaxis, f_values, 2) for iaxis in range(self.dim)) - def div(self, arg): + def div(self, + arg: obj_array.ObjectArray1D[Array1D[np.inexact]] + ) -> Array1D[np.inexact] | int: r""" :arg arg: an object array containing :class:`numpy.ndarray`\ s with shape ``(npoints_total,)``. """ - result = 0 + result: Array1D[np.inexact] | int = 0 for i, arg_i in enumerate(arg): result = result + self.diff(i, arg_i) return result - def curl(self, arg): + def curl(self, + arg: obj_array.ObjectArray1D[Array1D[np.inexact]] + ) -> obj_array.ObjectArray1D[Array1D[np.inexact]]: r"""Take the curl of the vector quantity *arg*. :arg arg: an object array of shape ``(3,)`` containing @@ -254,15 +286,15 @@ def eval_at_center(self, f_values): return f_values @property - def x(self): + def x(self) -> Array1D[np.floating]: return self.points[0] @property - def y(self): + def y(self) -> Array1D[np.floating]: return self.points[1] @property - def z(self): + def z(self) -> Array1D[np.floating]: return self.points[2] def norm(self, arg, p): @@ -284,7 +316,7 @@ def plot_nodes(self): self._points_shaped[1].reshape(-1), "o") - def plot(self, f): + def plot(self, f: Array1D[np.floating]): f = f.reshape(*self._pshape) import matplotlib.pyplot as plt @@ -292,7 +324,12 @@ def plot(self, f): plt.contourf(self._points_1d, self._points_1d, f) -def frequency_domain_maxwell(cpatch, e, h, k): +def frequency_domain_maxwell( + cpatch: CalculusPatch, + e: obj_array.ObjectArray1D[Array1D[np.complexfloating]], + h: obj_array.ObjectArray1D[Array1D[np.complexfloating]], + k: complex + ): mu = 1 epsilon = 1 c = 1/np.sqrt(mu*epsilon)