'Compute a definite integral over a piecewise polynomial.
Parameters
a : float
Lower integration bound
b : float
Upper integration bound
extrapolate : {bool, \'periodic\', None}, optional
If bool, determines whether to extrapolate to out-of-bounds points
based on first and last intervals, or to return NaNs.
If \'periodic\', periodic extrapolation is used.
If None (default), use `self.extrapolate`.
Returns
ig : array_like
Definite integral of the piecewise polynomial over [a, b]'

def integrate(self, a, b, extrapolate=None):

    if (extrapolate is None):
        extrapolate = self.extrapolate
    sign = 1
    if (b < a):
        (a, b) = (b, a)
        sign = (-1)
    range_int = np.empty((prod(self.c.shape[2:]),), dtype=self.c.dtype)
    self._ensure_c_contiguous()
    if (extrapolate == 'periodic'):
        (xs, xe) = (self.x[0], self.x[(-1)])
        period = (xe - xs)
        interval = (b - a)
        (n_periods, left) = divmod(interval, period)
        if (n_periods > 0):
            _ppoly.integrate(self.c.reshape(self.c.shape[0], self.c.shape[1], (-1)), self.x, xs, xe, False, out=range_int)
            range_int *= n_periods
        else:
            range_int.fill(0)
        a = (xs + ((a - xs) % period))
        b = (a + left)
        remainder_int = np.empty_like(range_int)
        if (b <= xe):
            _ppoly.integrate(self.c.reshape(self.c.shape[0], self.c.shape[1], (-1)), self.x, a, b, False, out=remainder_int)
            range_int += remainder_int
        else:
            _ppoly.integrate(self.c.reshape(self.c.shape[0], self.c.shape[1], (-1)), self.x, a, xe, False, out=remainder_int)
            range_int += remainder_int
            _ppoly.integrate(self.c.reshape(self.c.shape[0], self.c.shape[1], (-1)), self.x, xs, (((xs + left) + a) - xe), False, out=remainder_int)
            range_int += remainder_int
    else:
        _ppoly.integrate(self.c.reshape(self.c.shape[0], self.c.shape[1], (-1)), self.x, a, b, bool(extrapolate), out=range_int)
    range_int *= sign
    return range_int.reshape(self.c.shape[2:])
