ó
˜íYc           @   s˜   d  d l  Z d  d l Z d d l m Z d g Z d d d d d g d d d d d g e e e e e g d d	 d d
 „ Z	 d „  Z
 d „  Z d „  Z d S(   iÿÿÿÿNi   (   t
   autotimeitt   benchid   iè  i    t   float64t   Cc         C   s  t  |  ƒ t  | ƒ k r' t d ƒ ‚ n  t  |  ƒ t  | ƒ k rN t d ƒ ‚ n  d GHd t j t j f GHd GHd t | ƒ GHd GHd g } xC | D]; } | r¶ | j d
 j d	 ƒ ƒ q‘ | j d j d	 ƒ ƒ q‘ Wd j | ƒ GHg  |  D]- } d j t | ƒ j	 d ƒ ƒ j d	 ƒ ^ qå } d g | } d j | ƒ GHg  | D]1 }	 d j d t |	 ƒ j	 d ƒ ƒ j d	 ƒ ^ q:} d g | } d j | ƒ GHt
 |  | | | | | ƒ }
 xc |
 D][ } | d j d ƒ } | d d t  |  ƒ d } t | d | d ƒ } | t | ƒ GHq®Wd S(   sö  
    Bottleneck benchmark.

    Parameters
    ----------
    shapes : list, optional
        A list of tuple shapes of input arrays to use in the benchmark.
    axes : list, optional
        List of axes along which to perform the calculations that are being
        benchmarked.
    nans : list, optional
        A list of the bools (True or False), one for each tuple in the
        `shapes` list, that tells whether the input arrays should be randomly
        filled with one-fifth NaNs.
    dtype : str, optional
        Data type string such as 'float64', which is the default.
    order : {'C', 'F'}, optional
        Whether to store multidimensional data in C- or Fortran-contiguous
        (row- or column-wise) order in memory.
    functions : {list, None}, optional
        A list of strings specifying which functions to include in the
        benchmark. By default (None) all functions are included in the
        benchmark.

    Returns
    -------
    A benchmark report is printed to stdout.

    s-   `shapes` and `nans` must have the same lengths-   `shapes` and `axes` must have the same lengths    Bottleneck performance benchmarks       Bottleneck %s; Numpy %ss2       Speed is NumPy time divided by Bottleneck times,       NaN means approx one-fifth NaNs; %s usedt    t    i   t   NaNs   no NaNi   s   axis=t   names   %7.1fs   %11.1fi   t
   statementst   setupsNs              s               s               (   t   lent
   ValueErrort   bnt   __version__t   npt   strt   appendt   centert   joint   splitt
   benchsuitet   ljustt   timert   tuple(   t   shapest   axest   nanst   dtypet   ordert	   functionst   headert   nant   shapet   axist   suitet   testR   t   fmtt   speed(    (    s9   lib/python2.7/site-packages/bottleneck/benchmark/bench.pyR   	   s8    %	:;c         C   sŒ   g  } t  |  ƒ d k r' t d ƒ ‚ n  x^ | D]V } t j d d ƒ + t |  d | ƒ } t |  d | ƒ } Wd  QX| j | | ƒ q. W| S(   Ni   s   Two statements needed.t   invalidt   ignorei    i   (   R
   R   R   t   errstateR    R   (   R   R	   R%   t   setupt   t0t   t1(    (    s9   lib/python2.7/site-packages/bottleneck/benchmark/bench.pyR   Q   s    c         C   s   t  j t  j |  ƒ d | ƒ} | rU t | j j t  j ƒ rU t  j | d  d  d … <n  t  j j	 |  ƒ } | j
 | ƒ t  j | j |  Œ  d | ƒS(   NR   i   R   (   R   t   aranget   prodt
   issubclassR   t   typet   inexactR   t   randomt   RandomStatet   shufflet   arrayt   reshape(   R    R   R   R   t   at   rs(    (    s9   lib/python2.7/site-packages/bottleneck/benchmark/bench.pyt   getarray]   s    c         C   sÑ  g  } d „  } t  j d d t ƒ} | d d g 7} xŽ | D]† }	 | d  k	 r_ |	 | k r_ q; n  i  }
 |	 |
 d <d d g |
 d	 <d
 |	 |	 |	 |	 f } | | |  | | | | ƒ |
 d <| j |
 ƒ q; Wd d g } xˆ | D]€ }	 | d  k	 rü |	 | k rü qØ n  i  }
 |	 |
 d <d d g |
 d	 <d |	 |	 f } | | |  | | | | ƒ |
 d <| j |
 ƒ qØ Wd d g } xÂ | D]º }	 | d  k	 r“|	 | k r“qon  i  }
 |	 |
 d <|	 d k rÂd d g |
 d	 <n+ |	 d k rád d g |
 d	 <n t d ƒ ‚ d |	 |	 f } | | |  | | | | ƒ |
 d <| j |
 ƒ qoWt  j d d t ƒ} xˆ | D]€ }	 | d  k	 rm|	 | k rmqIn  i  }
 |	 |
 d <d d g |
 d	 <d |	 |	 f } | | |  | | | | ƒ |
 d <| j |
 ƒ qIW| S(   Nc         S   s®   d } g  } x› t  | | | ƒ D]‡ \ } }	 }
 | t | ƒ t | ƒ t |
 ƒ t | ƒ t |	 ƒ |  f } d j g  | j d ƒ D] } | j ƒ  ^ q~ ƒ } | j | ƒ q W| S(   Ns|   
        from bottleneck.benchmark.bench import getarray
        a = getarray(%s, '%s', %s, '%s')
        axis=%s
        %ss   
(   t   zipR   R   R   t   stripR   (   R)   R   R   R   R   R   t   templateR	   R    R!   R   t   st   line(    (    s9   lib/python2.7/site-packages/bottleneck/benchmark/bench.pyt	   getsetupsj   s    "'1t   reducet	   as_stringt   rankdatat   nanrankdataR   s   bn_func(a, axis)s   sl_func(a, axis)R   s  
            from bottleneck import %s as bn_func
            try: from numpy import %s as sl_func
            except ImportError: from bottleneck.slow import %s as sl_func
            if "%s" == "median": from bottleneck.slow import median as sl_func
        R	   t	   partitiont   argpartitions   bn_func(a, n, axis)s   sl_func(a, n, axis)sÞ   
            from bottleneck import %s as bn_func
            from bottleneck.slow import %s as sl_func
            if axis is None: n = a.size
            else: n = a.shape[axis] - 1
            n = max(n / 2, 0)
        t   replacet   pushs   bn_func(a, nan, 0)s   slow_func(a, nan, 0)s   bn_func(a, 5, axis)s   slow_func(a, 5, axis)s   Unknow function names”   
            from numpy import nan
            from bottleneck import %s as bn_func
            from bottleneck.slow import %s as slow_func
        t   moves   bn_func(a, w, 1, axis)s   sw_func(a, w, 1, axis)s˜   
            from bottleneck.slow.move import %s as sw_func
            from bottleneck import %s as bn_func
            w = a.shape[axis] // 5
        (   R   t   get_functionst   Truet   NoneR   R   (   R   R   R   R   R   R   R"   R>   t   funcst   funct   runR)   (    (    s9   lib/python2.7/site-packages/bottleneck/benchmark/bench.pyR   f   sh    	



(   id   (   iè  iè  (   iè  iè  (   iè  iè  (   iè  iè  (   t   numpyR   t
   bottleneckR   R    t   __all__t   FalseRI   RJ   R   R   R8   R   (    (    (    s9   lib/python2.7/site-packages/bottleneck/benchmark/bench.pyt   <module>   s   	B			