Пример #1
0
def shift(x, a, period=None, _cache=_cache):
    """ shift(x, a, period=2*pi) -> y

    Shift periodic sequence x by a: y(u) = x(u+a).

    If x_j and y_j are Fourier coefficients of periodic functions x
    and y, respectively, then

          y_j = exp(j*a*2*pi/period*sqrt(-1)) * x_f

    Optional input:
      period
        The period of the sequences x and y. Default period is 2*pi.
    """
    tmp = asarray(x)
    if iscomplexobj(tmp):
        return shift(tmp.real, a, period) + 1j * shift(tmp.imag, a, period)
    if period is not None:
        a = a * 2 * pi / period
    n = len(x)
    omega = _cache.get((n, a))
    if omega is None:
        if len(_cache) > 20:
            while _cache:
                _cache.popitem()

        def kernel_real(k, a=a):
            return cos(a * k)

        def kernel_imag(k, a=a):
            return sin(a * k)

        omega_real = convolve.init_convolution_kernel(n,
                                                      kernel_real,
                                                      d=0,
                                                      zero_nyquist=0)
        omega_imag = convolve.init_convolution_kernel(n,
                                                      kernel_imag,
                                                      d=1,
                                                      zero_nyquist=0)
        _cache[(n, a)] = omega_real, omega_imag
    else:
        omega_real, omega_imag = omega
    overwrite_x = _datacopied(tmp, x)
    return convolve.convolve_z(tmp,
                               omega_real,
                               omega_imag,
                               overwrite_x=overwrite_x)
Пример #2
0
def shift(x, a, period=None, _cache=_cache):
    """
    Shift periodic sequence x by a: y(u) = x(u+a).

    If x_j and y_j are Fourier coefficients of periodic functions x
    and y, respectively, then::

          y_j = exp(j*a*2*pi/period*sqrt(-1)) * x_f

    Parameters
    ----------
    x : array_like
        The array to take the pseudo-derivative from.
    a : float
        Defines the parameters of the sinh/sinh pseudo-differential
    period : float, optional
        The period of the sequences x and y. Default period is ``2*pi``.
    """
    tmp = asarray(x)
    if iscomplexobj(tmp):
        return shift(tmp.real,a,period)+1j*shift(tmp.imag,a,period)
    if period is not None:
        a = a*2*pi/period
    n = len(x)
    omega = _cache.get((n,a))
    if omega is None:
        if len(_cache)>20:
            while _cache: _cache.popitem()
        def kernel_real(k,a=a): return cos(a*k)
        def kernel_imag(k,a=a): return sin(a*k)
        omega_real = convolve.init_convolution_kernel(n,kernel_real,d=0,
                                                      zero_nyquist=0)
        omega_imag = convolve.init_convolution_kernel(n,kernel_imag,d=1,
                                                      zero_nyquist=0)
        _cache[(n,a)] = omega_real,omega_imag
    else:
        omega_real,omega_imag = omega
    overwrite_x = _datacopied(tmp, x)
    return convolve.convolve_z(tmp,omega_real,omega_imag,
                               overwrite_x=overwrite_x)
Пример #3
0
def shift(x, a, period=None,
          _cache = _cache):
    """ shift(x, a, period=2*pi) -> y

    Shift periodic sequence x by a: y(u) = x(u+a).

    If x_j and y_j are Fourier coefficients of periodic functions x
    and y, respectively, then

          y_j = exp(j*a*2*pi/period*sqrt(-1)) * x_f

    Optional input:
      period
        The period of the sequences x and y. Default period is 2*pi.
    """
    tmp = asarray(x)
    if iscomplexobj(tmp):
        return shift(tmp.real,a,period)+1j*shift(tmp.imag,a,period)
    if period is not None:
        a = a*2*pi/period
    n = len(x)
    omega = _cache.get((n,a))
    if omega is None:
        if len(_cache)>20:
            while _cache: _cache.popitem()
        def kernel_real(k,a=a): return cos(a*k)
        def kernel_imag(k,a=a): return sin(a*k)
        omega_real = convolve.init_convolution_kernel(n,kernel_real,d=0,
                                                      zero_nyquist=0)
        omega_imag = convolve.init_convolution_kernel(n,kernel_imag,d=1,
                                                      zero_nyquist=0)
        _cache[(n,a)] = omega_real,omega_imag
    else:
        omega_real,omega_imag = omega
    overwrite_x = _datacopied(tmp, x)
    return convolve.convolve_z(tmp,omega_real,omega_imag,
                               overwrite_x=overwrite_x)