From b0d91573085db805d9094f3b3261267ff61021b3 Mon Sep 17 00:00:00 2001 From: Per A Brodtkorb Date: Mon, 5 Sep 2016 15:27:32 +0200 Subject: [PATCH] Removed duplicated code --- wafo/integrate_oscillating.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/wafo/integrate_oscillating.py b/wafo/integrate_oscillating.py index bbcd942..dc36db6 100644 --- a/wafo/integrate_oscillating.py +++ b/wafo/integrate_oscillating.py @@ -25,38 +25,43 @@ dea3 = nd.dea3 class PolyBasis(object): @staticmethod - def derivative(t, k, n=1): - c = np.zeros(k + 1) - c[k] = 1 - dc = polynomial.polyder(c, m=n) - return polynomial.polyval(t, dc) + def _derivative(c, m): + return polynomial.polyder(c, m) @staticmethod def eval(t, c): return polynomial.polyval(t, c) + def _coefficients(self, k): + c = np.zeros(k + 1) + c[k] = 1 + return c + + def derivative(self, t, k, n=1): + c = self._coefficients(k) + dc = self._derivative(c, m=n) + return self.eval(t, dc) + def __call__(self, t, k): return t**k poly_basis = PolyBasis() -class ChebyshevBasis(object): +class ChebyshevBasis(PolyBasis): + @staticmethod - def derivative(t, k, n=1): - c = np.zeros(k + 1) - c[k] = 1 + def _derivative(c, m): cheb = Chebyshev(c) - dcheb = cheb.deriv(m=n) - return chebval(t, dcheb.coef) + dcheb = cheb.deriv(m=m) + return dcheb.coef @staticmethod def eval(t, c): return chebval(t, c) def __call__(self, t, k): - c = np.zeros(k + 1) - c[k] = 1 - return chebval(t, c) + c = self._coefficients(k) + return self.eval(t, c) chebyshev_basis = ChebyshevBasis()