From bc871fd9c32931a914b50730624c540c021cd3fe Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Thu, 12 Dec 2024 20:03:33 +0200 Subject: [PATCH 1/2] fix: new mypy errors due to numpy typing --- modepy/modal_decay.py | 10 +++++----- modepy/quadrature/clenshaw_curtis.py | 2 +- modepy/quadrature/jacobi_gauss.py | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modepy/modal_decay.py b/modepy/modal_decay.py index d5fe13a6..bbbb3a7e 100644 --- a/modepy/modal_decay.py +++ b/modepy/modal_decay.py @@ -103,7 +103,9 @@ def make_mode_number_vector( return mode_number_vector -def create_decay_baseline(mode_number_vector: np.ndarray, n: int) -> np.ndarray: +def create_decay_baseline( + mode_number_vector: np.ndarray[tuple[int, ...], np.dtype[np.floating]], + n: int) -> np.ndarray[tuple[int, ...], np.dtype[np.floating]]: """Create a vector of modal coefficients that exhibit 'optimal' (:math:`k^{-N}`) decay. """ @@ -111,10 +113,8 @@ def create_decay_baseline(mode_number_vector: np.ndarray, n: int) -> np.ndarray: zeros = mode_number_vector == 0 modal_coefficients = mode_number_vector**(-n) - modal_coefficients[zeros] = 1 # irrelevant, just keeps log from NaNing - - # NOTE: mypy seems to be confused by the __itruediv__ argument types - modal_coefficients /= la.norm(modal_coefficients) # type: ignore[arg-type,misc] + modal_coefficients[zeros] = 1.0 # irrelevant, just keeps log from NaNing + modal_coefficients /= la.norm(modal_coefficients) return modal_coefficients diff --git a/modepy/quadrature/clenshaw_curtis.py b/modepy/quadrature/clenshaw_curtis.py index 80bdd118..35bf448b 100644 --- a/modepy/quadrature/clenshaw_curtis.py +++ b/modepy/quadrature/clenshaw_curtis.py @@ -49,7 +49,7 @@ def _make_clenshaw_curtis_nodes_and_weights(n: int) -> tuple[np.ndarray, np.ndar # Clenshaw-Curtis weights w = np.concatenate([2 / N / (N - 2), 1 / N[-1:], np.zeros(m)]) w = 0 - w[:-1] - w[-1:0:-1] - g0 = -np.ones(n) + g0: np.ndarray[tuple[int, ...], np.dtype[np.floating]] = -np.ones(n) g0[r] = g0[r] + n g0[m] = g0[m] + n g0 = g0 / (n**2 - 1 + (n % 2)) diff --git a/modepy/quadrature/jacobi_gauss.py b/modepy/quadrature/jacobi_gauss.py index 8fd41597..dc56eb28 100644 --- a/modepy/quadrature/jacobi_gauss.py +++ b/modepy/quadrature/jacobi_gauss.py @@ -50,7 +50,6 @@ THE SOFTWARE. """ - import numpy as np import numpy.linalg as la @@ -267,7 +266,7 @@ def jacobi_gauss_lobatto_nodes( Exact to degree :math:`2N - 3`. """ - x = np.zeros((N + 1,)) + x: np.ndarray[tuple[int, ...], np.dtype[np.floating]] = np.zeros((N + 1,)) if N == 0: x[0] = 0 return x From 7b735267c91a7a4df97c93cb5caac42a74bf7050 Mon Sep 17 00:00:00 2001 From: Addison Alvey-Blanco Date: Fri, 6 Dec 2024 15:11:32 -0600 Subject: [PATCH 2/2] fix failing ruff test --- contrib/weights-from-festa-sommariva.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/weights-from-festa-sommariva.py b/contrib/weights-from-festa-sommariva.py index baab0f9e..ca720466 100644 --- a/contrib/weights-from-festa-sommariva.py +++ b/contrib/weights-from-festa-sommariva.py @@ -76,17 +76,17 @@ def generate_festa_sommariva_quadrature_rules(outfile): # # DEGREE: - _re_degree = re.compile(r"DEGREE:\s+(\d+)") - _re_xw = re.compile(r"xw\s?=\s?\[(.+?)\];", re.DOTALL) + re_degree = re.compile(r"DEGREE:\s+(\d+)") + re_xw = re.compile(r"xw\s?=\s?\[(.+?)\];", re.DOTALL) # NOTE: some degrees have multiple quadrature rules with a repeated # header, so we just take the unique ones here degrees = np.unique( - np.fromiter(_re_degree.findall(mfile), dtype=np.int64) + np.fromiter(re_degree.findall(mfile), dtype=np.int64) ) rules = {} - for imatch, match in enumerate(_re_xw.findall(mfile)): + for imatch, match in enumerate(re_xw.findall(mfile)): d = degrees[imatch] assert d == imatch + 1, (d, imatch + 1)