Skip to content

Commit

Permalink
updated spectral-derivatives such that some of the checks I had in th…
Browse files Browse the repository at this point in the history
…is PR are no longer necessary
  • Loading branch information
pavelkomarov committed Jan 18, 2025
1 parent 859a87a commit 6766e52
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
21 changes: 4 additions & 17 deletions derivative/dglobal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 6766e52

Please sign in to comment.