

def diff(x, order=1, period=None, _cache=_cache):
    '\n    Return k-th derivative (or integral) of a periodic sequence x.\n\n    If x_j and y_j are Fourier coefficients of periodic functions x\n    and y, respectively, then::\n\n      y_j = pow(sqrt(-1)*j*2*pi/period, order) * x_j\n      y_0 = 0 if order is not 0.\n\n    Parameters\n    ----------\n    x : array_like\n        Input array.\n    order : int, optional\n        The order of differentiation. Default order is 1. If order is\n        negative, then integration is carried out under the assumption\n        that ``x_0 == 0``.\n    period : float, optional\n        The assumed period of the sequence. Default is ``2*pi``.\n\n    Notes\n    -----\n    If ``sum(x, axis=0) = 0`` then ``diff(diff(x, k), -k) == x`` (within\n    numerical accuracy).\n\n    For odd order and even ``len(x)``, the Nyquist mode is taken zero.\n\n    '
    tmp = asarray(x)
    if (order == 0):
        return tmp
    if iscomplexobj(tmp):
        return (diff(tmp.real, order, period) + (1j * diff(tmp.imag, order, period)))
    if (period is not None):
        c = ((2 * pi) / period)
    else:
        c = 1.0
    n = len(x)
    omega = _cache.get((n, order, c))
    if (omega is None):
        if (len(_cache) > 20):
            while _cache:
                _cache.popitem()

        def kernel(k, order=order, c=c):
            if k:
                return pow((c * k), order)
            return 0
        omega = convolve.init_convolution_kernel(n, kernel, d=order, zero_nyquist=1)
        _cache[(n, order, c)] = omega
    overwrite_x = _datacopied(tmp, x)
    return convolve.convolve(tmp, omega, swap_real_imag=(order % 2), overwrite_x=overwrite_x)

dataset/ETHPy150Open scipy/scipy/scipy/fftpack/pseudo_diffs.py diff/original