From 6766e523423d1f1e12194c525f97642a9dd799cb Mon Sep 17 00:00:00 2001 From: pavelkomarov Date: Fri, 17 Jan 2025 19:51:15 -0800 Subject: [PATCH] updated spectral-derivatives such that some of the checks I had in this PR are no longer necessary --- derivative/dglobal.py | 21 ++++----------------- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/derivative/dglobal.py b/derivative/dglobal.py index 05cba6e..0a8b564 100644 --- a/derivative/dglobal.py +++ b/derivative/dglobal.py @@ -38,23 +38,10 @@ def __init__(self, order=1, axis=0, basis='chebyshev', **kwargs): self.basis = basis def _global(self, t, x): - if basis == 'chebyshev': - # Check that t is properly cosine-spaced. `cheb_deriv` is agnostic to the domain the data actually lives - # on, but in order for the user to get back what they expect, it's important the domain actually be a - # linear map of cosine-spaced points on [-1, 1], i.e. t_n = np.cos(np.arange(N+1) * np.pi / N) - cosine_spaced = np.cos(np.arange(N+1) * np.pi / N) * (t[-1] - t[0])/2 + (t[-1] + t[0])/2 - if not numpy.allclose(t, cosine_spaced): - raise ValueError("Your domain t is not cosine-spaced. Must be `np.cos(np.arange(N+1) * np.pi / N) * (t[-1] - t[0])/2 + (t[-1] + t[0])/2`") - return cheb_deriv(x, self.order, self.axis) - - else: # basis == 'fourier' - # Check that t is an open periodic interval. `fourier_deriv` is agnostic to the domain the data actually - # lives on, but in order for the user to get back what they expect, it's important the domain actually - # be a linear map of equispaced points on [0, 2pi), i.e np.arange(0, M) * 2*np.pi / M - zero_2pi_open = np.arange(0, M) * (t[1] - t[0]) + t[0]` - if not numpy.allcose(t, zero_2pi_open): - raise ValueError("Your domain t does not map to [0, 2pi). Must be `np.arange(0, M) * (t[1] - t[0]) + t[0]`") - return fourier_deriv(x, self.order, self.axis) + if self.basis == 'chebyshev': + return cheb_deriv(x, t, self.order, self.axis) + else: # self.basis == 'fourier' + return fourier_deriv(x, t, self.order, self.axis) def compute(self, t, x, i): return next(self.compute_for(t, x, [i])) diff --git a/pyproject.toml b/pyproject.toml index e05a519..19b1870 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ numpy = ">=1.18.3" scipy = "^1.4.1" scikit-learn = "^1" importlib-metadata = ">=7.1.0" -spectral-derivatives = ">=0.5" +spectral-derivatives = ">=0.6" # docs sphinx = {version = "7.2.6", optional = true}