ó
î&]\c        
   @` s¤  d  Z  d d l m Z m Z m Z d d d d d d d	 d
 d d g
 Z d d l m Z m Z m	 Z	 m
 Z
 m Z m Z m Z m Z d d l m Z d d l m Z d d l Z e j e j ƒ [ i  Z d d e d „ Z [ i  Z d e d „ Z [ i  Z d e d „ Z [ i  Z e d „ Z [ d „  Z i  Z d e d „ Z [ i  Z d e d „ Z [ i  Z d e d „ Z [ i  Z d e d „ Z  [ i  Z d e d „ Z! [ d S(   s1   
Differential and pseudo-differential operators.
i    (   t   divisiont   print_functiont   absolute_importt   difft   tilbertt   itilbertt   hilbertt   ihilbertt   cs_difft   cc_difft   sc_difft   ss_difft   shift(   t   pit   asarrayt   sint   cost   sinht   cosht   tanht   iscomplexobji   (   t   convolve(   t   _datacopiedNc   
      C` sC  t  |  ƒ } | d k r | St | ƒ rR t | j | | ƒ d t | j | | ƒ S| d k	 ro d t | } n d } t |  ƒ } | j | | | f ƒ } | d k rt | ƒ d k rÑ x | rÍ | j	 ƒ  qº Wn  | | d „ } t
 j | | d | d d	 ƒ} | | | | | f <n  t | |  ƒ }	 t
 j
 | | d
 | d d |	 ƒS(   s+  
    Return k-th derivative (or integral) of a periodic sequence x.

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

      y_j = pow(sqrt(-1)*j*2*pi/period, order) * x_j
      y_0 = 0 if order is not 0.

    Parameters
    ----------
    x : array_like
        Input array.
    order : int, optional
        The order of differentiation. Default order is 1. If order is
        negative, then integration is carried out under the assumption
        that ``x_0 == 0``.
    period : float, optional
        The assumed period of the sequence. Default is ``2*pi``.

    Notes
    -----
    If ``sum(x, axis=0) = 0`` then ``diff(diff(x, k), -k) == x`` (within
    numerical accuracy).

    For odd order and even ``len(x)``, the Nyquist mode is taken zero.

    i    y              ð?i   g      ð?i   c         S` s   |  r t  | |  | ƒ Sd S(   Ni    (   t   pow(   t   kt   ordert   c(    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyt   kernelG   s    t   dt   zero_nyquisti   t   swap_real_imagt   overwrite_xN(   R   R   R   t   realt   imagt   NoneR   t   lent   gett   popitemR   t   init_convolution_kernelR   (
   t   xR   t   periodt   _cachet   tmpR   t   nt   omegaR   R   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR      s*    *		c   	      C` s  t  |  ƒ } t | ƒ rB t | j | | ƒ d t | j | | ƒ S| d	 k	 rc | d t | } n  t |  ƒ } | j | | f ƒ } | d	 k ró t | ƒ d k r¼ x | r¸ | j	 ƒ  q¥ Wn  | d „ } t
 j | | d d ƒ} | | | | f <n  t | |  ƒ } t
 j
 | | d d d | ƒS(
   s  
    Return h-Tilbert transform of a periodic sequence x.

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

        y_j = sqrt(-1)*coth(j*h*2*pi/period) * x_j
        y_0 = 0

    Parameters
    ----------
    x : array_like
        The input array to transform.
    h : float
        Defines the parameter of the Tilbert transform.
    period : float, optional
        The assumed period of the sequence.  Default period is ``2*pi``.

    Returns
    -------
    tilbert : ndarray
        The result of the transform.

    Notes
    -----
    If ``sum(x, axis=0) == 0`` and ``n = len(x)`` is odd then
    ``tilbert(itilbert(x)) == x``.

    If ``2 * pi * h / period`` is approximately 10 or larger, then
    numerically ``tilbert == hilbert``
    (theoretically oo-Tilbert == Hilbert).

    For even ``len(x)``, the Nyquist mode of ``x`` is taken zero.

    y              ð?i   i   c         S` s   |  r d t  | |  ƒ Sd S(   Ng      ð?i    (   R   (   R   t   h(    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   Œ   s    R   i   R   R   N(   R   R   R   R    R!   R"   R   R#   R$   R%   R   R&   R   (	   R'   R-   R(   R)   R*   R+   R,   R   R   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   Y   s"    $	c   	      C` s  t  |  ƒ } t | ƒ rB t | j | | ƒ d t | j | | ƒ S| d	 k	 rc | d t | } n  t |  ƒ } | j | | f ƒ } | d	 k ró t | ƒ d k r¼ x | r¸ | j	 ƒ  q¥ Wn  | d „ } t
 j | | d d ƒ} | | | | f <n  t | |  ƒ } t
 j
 | | d d d | ƒS(
   s  
    Return inverse h-Tilbert transform of a periodic sequence x.

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

      y_j = -sqrt(-1)*tanh(j*h*2*pi/period) * x_j
      y_0 = 0

    For more details, see `tilbert`.

    y              ð?i   i   c         S` s   |  r t  | |  ƒ Sd S(   Ni    (   R   (   R   R-   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   ¹   s    R   i   R   R   N(   R   R   R   R    R!   R"   R   R#   R$   R%   R   R&   R   (	   R'   R-   R(   R)   R*   R+   R,   R   R   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   Ÿ   s"    	c         C` sâ   t  |  ƒ } t | ƒ r6 t | j ƒ d t | j ƒ St |  ƒ } | j | ƒ } | d k r· t | ƒ d k r‰ x | r… | j ƒ  qr Wn  d „  } t	 j
 | | d d ƒ} | | | <n  t | |  ƒ } t	 j	 | | d d d | ƒS(	   sû  
    Return Hilbert transform of a periodic sequence x.

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

      y_j = sqrt(-1)*sign(j) * x_j
      y_0 = 0

    Parameters
    ----------
    x : array_like
        The input array, should be periodic.
    _cache : dict, optional
        Dictionary that contains the kernel used to do a convolution with.

    Returns
    -------
    y : ndarray
        The transformed input.

    See Also
    --------
    scipy.signal.hilbert : Compute the analytic signal, using the Hilbert
                           transform.

    Notes
    -----
    If ``sum(x, axis=0) == 0`` then ``hilbert(ihilbert(x)) == x``.

    For even len(x), the Nyquist mode of x is taken zero.

    The sign of the returned transform does not have a factor -1 that is more
    often than not found in the definition of the Hilbert transform.  Note also
    that `scipy.signal.hilbert` does have an extra -1 factor compared to this
    function.

    y              ð?i   c         S` s$   |  d k r d S|  d k  r  d Sd S(   Ni    g      ð?g      ð¿g        (    (   R   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   ú   s
    R   i   R   R   N(   R   R   R   R    R!   R#   R$   R"   R%   R   R&   R   (   R'   R)   R*   R+   R,   R   R   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   É   s    '		c         C` s   t  |  ƒ S(   så   
    Return inverse Hilbert transform of a periodic sequence x.

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

      y_j = -sqrt(-1)*sign(j) * x_j
      y_0 = 0

    (   R   (   R'   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   	  s    c   
      C` s?  t  |  ƒ } t | ƒ rH t | j | | | ƒ d t | j | | | ƒ S| d	 k	 r{ | d t | } | d t | } n  t |  ƒ } | j | | | f ƒ } | d	 k rt | ƒ d k r× x | rÓ | j	 ƒ  qÀ Wn  | | d „ } t
 j | | d d ƒ} | | | | | f <n  t | |  ƒ }	 t
 j
 | | d d d |	 ƒS(
   sô  
    Return (a,b)-cosh/sinh pseudo-derivative of a periodic sequence.

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

      y_j = -sqrt(-1)*cosh(j*a*2*pi/period)/sinh(j*b*2*pi/period) * x_j
      y_0 = 0

    Parameters
    ----------
    x : array_like
        The array to take the pseudo-derivative from.
    a, b : float
        Defines the parameters of the cosh/sinh pseudo-differential
        operator.
    period : float, optional
        The period of the sequence. Default period is ``2*pi``.

    Returns
    -------
    cs_diff : ndarray
        Pseudo-derivative of periodic sequence `x`.

    Notes
    -----
    For even len(`x`), the Nyquist mode of `x` is taken as zero.

    y              ð?i   i   c         S` s'   |  r# t  | |  ƒ t | |  ƒ Sd S(   Ni    (   R   R   (   R   t   at   b(    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   F  s    R   i   R   R   N(   R   R   R   R    R!   R"   R   R#   R$   R%   R   R&   R   (
   R'   R.   R/   R(   R)   R*   R+   R,   R   R   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR     s$    	c   
      C` s?  t  |  ƒ } t | ƒ rH t | j | | | ƒ d t | j | | | ƒ S| d	 k	 r{ | d t | } | d t | } n  t |  ƒ } | j | | | f ƒ } | d	 k rt | ƒ d k r× x | rÓ | j	 ƒ  qÀ Wn  | | d „ } t
 j | | d d ƒ} | | | | | f <n  t | |  ƒ }	 t
 j
 | | d d d |	 ƒS(
   sˆ  
    Return (a,b)-sinh/cosh pseudo-derivative of a periodic sequence x.

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

      y_j = sqrt(-1)*sinh(j*a*2*pi/period)/cosh(j*b*2*pi/period) * x_j
      y_0 = 0

    Parameters
    ----------
    x : array_like
        Input array.
    a,b : float
        Defines the parameters of the sinh/cosh pseudo-differential
        operator.
    period : float, optional
        The period of the sequence x. Default is 2*pi.

    Notes
    -----
    ``sc_diff(cs_diff(x,a,b),b,a) == x``
    For even ``len(x)``, the Nyquist mode of x is taken as zero.

    y              ð?i   i   c         S` s&   |  r" t  | |  ƒ t | |  ƒ Sd S(   Ni    (   R   R   (   R   R.   R/   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   ~  s    R   i   R   R   N(   R   R   R
   R    R!   R"   R   R#   R$   R%   R   R&   R   (
   R'   R.   R/   R(   R)   R*   R+   R,   R   R   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR
   V  s$    	c   
      C` s3  t  |  ƒ } t | ƒ rH t | j | | | ƒ d t | j | | | ƒ S| d k	 r{ | d t | } | d t | } n  t |  ƒ } | j | | | f ƒ } | d k rt | ƒ d k r× x | rÓ | j	 ƒ  qÀ Wn  | | d „ } t
 j | | ƒ } | | | | | f <n  t | |  ƒ }	 t
 j
 | | d |	 ƒS(   sc  
    Return (a,b)-sinh/sinh pseudo-derivative of a periodic sequence x.

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

      y_j = sinh(j*a*2*pi/period)/sinh(j*b*2*pi/period) * x_j
      y_0 = a/b * x_0

    Parameters
    ----------
    x : array_like
        The array to take the pseudo-derivative from.
    a,b
        Defines the parameters of the sinh/sinh pseudo-differential
        operator.
    period : float, optional
        The period of the sequence x. Default is ``2*pi``.

    Notes
    -----
    ``ss_diff(ss_diff(x,a,b),b,a) == x``

    y              ð?i   i   c         S` s0   |  r" t  | |  ƒ t  | |  ƒ St | ƒ | S(   N(   R   t   float(   R   R.   R/   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   µ  s    R   N(   R   R   R   R    R!   R"   R   R#   R$   R%   R   R&   R   (
   R'   R.   R/   R(   R)   R*   R+   R,   R   R   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   Ž  s$    	c   
      C` s3  t  |  ƒ } t | ƒ rH t | j | | | ƒ d t | j | | | ƒ S| d k	 r{ | d t | } | d t | } n  t |  ƒ } | j | | | f ƒ } | d k rt | ƒ d k r× x | rÓ | j	 ƒ  qÀ Wn  | | d „ } t
 j | | ƒ } | | | | | f <n  t | |  ƒ }	 t
 j
 | | d |	 ƒS(   s¶  
    Return (a,b)-cosh/cosh pseudo-derivative of a periodic sequence.

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

      y_j = cosh(j*a*2*pi/period)/cosh(j*b*2*pi/period) * x_j

    Parameters
    ----------
    x : array_like
        The array to take the pseudo-derivative from.
    a,b : float
        Defines the parameters of the sinh/sinh pseudo-differential
        operator.
    period : float, optional
        The period of the sequence x. Default is ``2*pi``.

    Returns
    -------
    cc_diff : ndarray
        Pseudo-derivative of periodic sequence `x`.

    Notes
    -----
    ``cc_diff(cc_diff(x,a,b),b,a) == x``

    y              ð?i   i   c         S` s   t  | |  ƒ t  | |  ƒ S(   N(   R   (   R   R.   R/   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   ð  s    R   N(   R   R   R	   R    R!   R"   R   R#   R$   R%   R   R&   R   (
   R'   R.   R/   R(   R)   R*   R+   R,   R   R   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR	   Å  s$    	c         C` s]  t  |  ƒ } t | ƒ rB t | j | | ƒ d t | j | | ƒ S| d k	 rc | d t | } n  t |  ƒ } | j | | f ƒ } | d k r)t | ƒ d k r¼ x | r¸ | j	 ƒ  q¥ Wn  | d „ } | d „ } t
 j | | d d d d ƒ}	 t
 j | | d d	 d d ƒ}
 |	 |
 f | | | f <n | \ }	 }
 t | |  ƒ } t
 j | |	 |
 d
 | ƒS(   sò  
    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``.
    y              ð?i   i   c         S` s   t  | |  ƒ S(   N(   R   (   R   R.   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyt   kernel_real  s    c         S` s   t  | |  ƒ S(   N(   R   (   R   R.   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyt   kernel_imag  s    R   i    R   i   R   N(   R   R   R   R    R!   R"   R   R#   R$   R%   R   R&   R   t
   convolve_z(   R'   R.   R(   R)   R*   R+   R,   R1   R2   t
   omega_realt
   omega_imagR   (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyR   þ  s,    *			("   t   __doc__t
   __future__R    R   R   t   __all__t   numpyR   R   R   R   R   R   R   R   t    R   t   scipy.fftpack.basicR   t   atexitt   registert   destroy_convolve_cacheR)   R"   R   R   R   R   R   R   R
   R   R	   R   (    (    (    s9   lib/python2.7/site-packages/scipy/fftpack/pseudo_diffs.pyt   <module>   sN   	:9@$=	6213/