ó
î&]\c           @` sà   d  d l  m Z m Z m Z d  d l Z d  d l m Z m Z m Z m	 Z	 m
 Z
 m Z m Z m Z m Z m Z m Z d  d l m Z m Z m Z d  d l m Z d d d d	 d
 g Z d d „ Z d „  Z d „  Z d „  Z d S(   i    (   t   divisiont   print_functiont   absolute_importN(   t   aranget   arrayt   asarrayt
   atleast_1dt   intct   integert   isscalart
   issubdtypet   taket   uniquet   where(   t   fftshiftt	   ifftshiftt   fftfreq(   t   bisect_leftR   R   R   t   rfftfreqt   next_fast_leng      ð?c         C` sW   t  j |  ƒ }  |  d k  r. t d |  ƒ ‚ n  t d |  d d t ƒd t |  | ƒ S(   s›  DFT sample frequencies (for usage with rfft, irfft).

    The returned float array contains the frequency bins in
    cycles/unit (with zero at the start) given a window length `n` and a
    sample spacing `d`::

      f = [0,1,1,2,2,...,n/2-1,n/2-1,n/2]/(d*n)   if n is even
      f = [0,1,1,2,2,...,n/2-1,n/2-1,n/2,n/2]/(d*n)   if n is odd

    Parameters
    ----------
    n : int
        Window length.
    d : scalar, optional
        Sample spacing. Default is 1.

    Returns
    -------
    out : ndarray
        The array of length `n`, containing the sample frequencies.

    Examples
    --------
    >>> from scipy import fftpack
    >>> sig = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float)
    >>> sig_fft = fftpack.rfft(sig)
    >>> n = sig_fft.size
    >>> timestep = 0.1
    >>> freq = fftpack.rfftfreq(n, d=timestep)
    >>> freq
    array([ 0.  ,  1.25,  1.25,  2.5 ,  2.5 ,  3.75,  3.75,  5.  ])

    i    s5   n = %s is not valid. n must be a nonnegative integer.i   t   dtypei   (   t   operatort   indext
   ValueErrorR   t   intt   float(   t   nt   d(    (    s3   lib/python2.7/site-packages/scipy/fftpack/helper.pyR      s
    "c      ©   C` sD  d± } t  |  ƒ }  |  dª k r" |  S|  |  d« @s4 |  S|  | d¬ k rU | t | |  ƒ St d­ ƒ } d« } xÁ | |  k  r*| } xy | |  k  r÷ |  | } d® | d« j ƒ  } | | } | |  k rÅ | S| | k  rÚ | } n  | d¯ 9} | |  k r | Sq W| | k  r| } n  | d° 9} | |  k rj | Sqj W| | k  r@| } n  | S(²   sà  
    Find the next fast size of input data to `fft`, for zero-padding, etc.

    SciPy's FFTPACK has efficient functions for radix {2, 3, 4, 5}, so this
    returns the next composite of the prime factors 2, 3, and 5 which is
    greater than or equal to `target`. (These are also known as 5-smooth
    numbers, regular numbers, or Hamming numbers.)

    Parameters
    ----------
    target : int
        Length to start searching from.  Must be a positive integer.

    Returns
    -------
    out : int
        The first 5-smooth number greater than or equal to `target`.

    Notes
    -----
    .. versionadded:: 0.18.0

    Examples
    --------
    On a particular machine, an FFT of prime length takes 133 ms:

    >>> from scipy import fftpack
    >>> min_len = 10007  # prime length is worst case for speed
    >>> a = np.random.randn(min_len)
    >>> b = fftpack.fft(a)

    Zero-padding to the next 5-smooth length reduces computation time to
    211 us, a speedup of 630 times:

    >>> fftpack.helper.next_fast_len(min_len)
    10125
    >>> b = fftpack.fft(a, 10125)

    Rounding up to the next power of 2 is not optimal, taking 367 us to
    compute, 1.7 times as long as the 5-smooth size:

    >>> b = fftpack.fft(a, 16384)

    i   i	   i
   i   i   i   i   i   i   i   i   i   i    i$   i(   i-   i0   i2   i6   i<   i@   iH   iK   iP   iQ   iZ   i`   id   il   ix   i}   i€   i‡   i   i–   i    i¢   i´   iÀ   iÈ   iØ   iá   ið   ió   iú   i   i  i   i,  i@  iD  ih  iw  i€  i  i•  i°  iÂ  ià  iæ  iô  i   i  i@  iX  iq  i€  iˆ  i£  iÐ  iÙ  iî  i   i   i*  i`  i„  iÀ  iÌ  iè  i   i8  ie  i€  i°  i¿  iâ  i   i  iF  i   i²  iÜ  i   i@  iT  iÀ  i  iS  i€  i˜  iÐ  ié  i   ip  i‹  iÊ  i 	  i`	  i~	  iÄ	  i 
  i 
  iŒ
  i@  id  i¸  i   i5  i€  i¨  i/  i€  i  i=  i¦  i   i0  i   iÒ  i   ià  i  i”  i   iÀ  iü  iˆ  i   i@  i  iù  i€  iÈ  ip  i»  i   ij  i   iP  i¡  i^  i   i   iz  iL  i   i`  i@  i¤  i    iÀ!  i,"  i(#  i $  iŸ$  i€%  iø%  i'  i   i   iÿÿÿÿt   infi   i   i   (©   i   i	   i
   i   i   i   i   i   i   i   i   i   i    i$   i(   i-   i0   i2   i6   i<   i@   iH   iK   iP   iQ   iZ   i`   id   il   ix   i}   i€   i‡   i   i–   i    i¢   i´   iÀ   iÈ   iØ   iá   ið   ió   iú   i   i  i   i,  i@  iD  ih  iw  i€  i  i•  i°  iÂ  ià  iæ  iô  i   i  i@  iX  iq  i€  iˆ  i£  iÐ  iÙ  iî  i   i   i*  i`  i„  iÀ  iÌ  iè  i   i8  ie  i€  i°  i¿  iâ  i   i  iF  i   i²  iÜ  i   i@  iT  iÀ  i  iS  i€  i˜  iÐ  ié  i   ip  i‹  iÊ  i 	  i`	  i~	  iÄ	  i 
  i 
  iŒ
  i@  id  i¸  i   i5  i€  i¨  i/  i€  i  i=  i¦  i   i0  i   iÒ  i   ià  i  i”  i   iÀ  iü  iˆ  i   i@  i  iù  i€  iÈ  ip  i»  i   ij  i   iP  i¡  i^  i   i   iz  iL  i   i`  i@  i¤  i    iÀ!  i,"  i(#  i $  iŸ$  i€%  iø%  i'  (   R   R   R   t
   bit_length(   t   targett   hamst   matcht   p5t   p35t   quotientt   p2t   N(    (    s3   lib/python2.7/site-packages/scipy/fftpack/helper.pyR   6   sX    -             
	
	
	c         C` s—  t  |  ƒ }  | d k } | d k } | rB t |  j d t ƒ} n t | ƒ } | j d k ro | j t ƒ } n  | j d k s t d ƒ ‚ n  t	 | j
 t ƒ s® t d ƒ ‚ n  t | d k  | |  j | ƒ } | j d k r| j ƒ  |  j k s| j ƒ  d k  rt d ƒ ‚ n  | j d k rHt | ƒ j | j k rHt d ƒ ‚ n  | s]t | ƒ } nQ t |  ƒ r~t g  d t ƒ} n0 | rœt |  j d t ƒ} n t |  j | ƒ } | j d k rÏ| j t ƒ } n  | j d k rít d ƒ ‚ n  t	 | j
 t ƒ st d	 ƒ ‚ n  | j | j k r/t d
 ƒ ‚ n  t | d k t |  j ƒ | | ƒ } | j d k r| d k  j ƒ  rt d j | ƒ ƒ ‚ n  | | f S(   s  Handle shape and axes arguments for n-dimensional transforms.

    Returns the shape and axes in a standard form, taking into account negative
    values and checking for various potential errors.

    Parameters
    ----------
    x : array_like
        The input array.
    shape : int or array_like of ints or None
        The shape of the result.  If both `shape` and `axes` (see below) are
        None, `shape` is ``x.shape``; if `shape` is None but `axes` is
        not None, then `shape` is ``scipy.take(x.shape, axes, axis=0)``.
        If `shape` is -1, the size of the corresponding dimension of `x` is
        used.
    axes : int or array_like of ints or None
        Axes along which the calculation is computed.
        The default is over all axes.
        Negative indices are automatically converted to their positive
        counterpart.

    Returns
    -------
    shape : array
        The shape of the result. It is a 1D integer array.
    axes : array
        The shape of the result. It is a 1D integer array.

    R   i    i   s2   when given, axes values must be a scalar or vectors(   when given, axes values must be integerss$   axes exceeds dimensionality of inputs   all axes must be uniques3   when given, shape values must be a scalar or vectors)   when given, shape values must be integerssB   when given, axes and shape arguments have to be of the same lengthiÿÿÿÿs-   invalid number of data points ({0}) specifiedN(   R   t   NoneR   t   ndimR   R   t   sizet   astypeR   R
   R   R   R   t   maxt   minR   t   shapeR	   R   R   t   anyt   format(   t   xR,   t   axest   noshapet   noaxes(    (    s3   lib/python2.7/site-packages/scipy/fftpack/helper.pyt   _init_nd_shape_and_axes   sJ    6'%!c         C` sQ   | d k } t |  | | ƒ \ } } | sG | | j ƒ  } | j ƒ  n  | | f S(   s  Handle and sort shape and axes arguments for n-dimensional transforms.

    This is identical to `_init_nd_shape_and_axes`, except the axes are
    returned in sorted order and the shape is reordered to match.

    Parameters
    ----------
    x : array_like
        The input array.
    shape : int or array_like of ints or None
        The shape of the result.  If both `shape` and `axes` (see below) are
        None, `shape` is ``x.shape``; if `shape` is None but `axes` is
        not None, then `shape` is ``scipy.take(x.shape, axes, axis=0)``.
        If `shape` is -1, the size of the corresponding dimension of `x` is
        used.
    axes : int or array_like of ints or None
        Axes along which the calculation is computed.
        The default is over all axes.
        Negative indices are automatically converted to their positive
        counterpart.

    Returns
    -------
    shape : array
        The shape of the result. It is a 1D integer array.
    axes : array
        The shape of the result. It is a 1D integer array.

    N(   R&   R3   t   argsortt   sort(   R/   R,   R0   R2   (    (    s3   lib/python2.7/site-packages/scipy/fftpack/helper.pyt   _init_nd_shape_and_axes_sortedð   s    (   t
   __future__R    R   R   R   t   numpyR   R   R   R   R   R   R	   R
   R   R   R   t   numpy.fft.helperR   R   R   t   bisectR   t   __all__R   R   R3   R6   (    (    (    s3   lib/python2.7/site-packages/scipy/fftpack/helper.pyt   <module>   s   L*	g	S