B
    î&]\i#  ã               @   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d	„Zdd
„ Zdd„ Zdd„ ZdS )é    )ÚdivisionÚprint_functionÚabsolute_importN)ÚarangeÚarrayÚasarrayÚ
atleast_1dÚintcÚintegerÚisscalarÚ
issubdtypeÚtakeÚuniqueÚwhere)ÚfftshiftÚ	ifftshiftÚfftfreq)Úbisect_leftr   r   r   ÚrfftfreqÚnext_fast_lenç      ð?c             C   s@   t  | ¡} | dk rtd|  ƒ‚td| d tdd t| | ƒ S )a›  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.  ])

    r   z5n = %s is not valid. n must be a nonnegative integer.é   )Údtypeé   )ÚoperatorÚindexÚ
ValueErrorr   ÚintÚfloat)ÚnÚd© r!   ú3lib/python3.7/site-packages/scipy/fftpack/helper.pyr      s
    "
c             C   sî   d}t | ƒ} | dkr| S | | d @ s(| S | |d krB|t|| ƒ S tdƒ}d}xŽ|| k rÜ|}x\|| k r¸|  |  }d|d  ¡  }|| }|| kr–|S ||k r¢|}|d9 }|| kr^|S q^W ||k rÆ|}|d9 }|| krP|S qPW ||k rê|}|S )	aà  
    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)

    )©é   é	   é
   é   é   é   é   é   é   é   é   é   é    é$   é(   é-   é0   é2   é6   é<   é@   éH   éK   éP   éQ   éZ   é`   éd   él   éx   é}   é€   é‡   é   é–   é    é¢   é´   éÀ   éÈ   éØ   éá   éð   éó   éú   é   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   éÿÿÿÿÚinfr   é   é   )r   r   r   Ú
bit_length)ÚtargetZhamsÚmatchZp5Zp35ZquotientZp2ÚNr!   r!   r"   r   6   s>    -

c             C   s¸  t | ƒ} |dk}|dk}|r,t| jtd}nt|ƒ}|jdkrH| t¡}|jdksZtdƒ‚t|j	t
ƒsntdƒ‚t|dk || j |ƒ}|jdkr°| ¡ | jks¨| ¡ dk r°tdƒ‚|jdkrÒt|ƒj|jkrÒtdƒ‚|sàt|ƒ}n8t| ƒrötg td}n"|rt| jtd}nt| j|ƒ}|jdkr.| t¡}|jdkrBtd	ƒ‚t|j	t
ƒsXtd
ƒ‚|j|jkrntdƒ‚t|dkt| jƒ| |ƒ}|jdkr°|dk  ¡ r°td |¡ƒ‚||fS )a  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.

    N)r   r   r   z2when given, axes values must be a scalar or vectorz(when given, axes values must be integersz$axes exceeds dimensionality of inputzall axes must be uniquez3when given, shape values must be a scalar or vectorz)when given, shape values must be integerszBwhen given, axes and shape arguments have to be of the same lengthrR   z-invalid number of data points ({0}) specified)r   r   Úndimr	   r   ÚsizeZastyper   r   r   r
   r   ÚmaxÚminr   Úshaper   r   r   ÚanyÚformat)Úxr^   ÚaxesZnoshapeÚnoaxesr!   r!   r"   Ú_init_nd_shape_and_axes   sJ    


$

rd   c             C   s8   |dk}t | ||ƒ\}}|s0|| ¡  }| ¡  ||fS )a  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)rd   ZargsortÚsort)ra   r^   rb   rc   r!   r!   r"   Ú_init_nd_shape_and_axes_sortedð   s    rf   )r   )Z
__future__r   r   r   r   Znumpyr   r   r   r   r	   r
   r   r   r   r   r   Znumpy.fft.helperr   r   r   Zbisectr   Ú__all__r   r   rd   rf   r!   r!   r!   r"   Ú<module>   s   4
*gS