
    e                     Z    d dl Zd dlZddlmZ dgZg dg dg ddd	dfd
Zd Zd Zd Z	dS )    N   )
autotimeitbench))d     r   r   r   r   )r   r   r   r   r   )FFTFTfloat64Cc                    t          |           t          |          k    rt          d          t          |           t          |          k    rt          d          t          d           t          dt          j        dt
          j                   t          d           t          dt          |          z             t          d           d	g}|D ]U}|r)|                    d
                    d                     -|                    d                    d                     Vt          d	                    |                     d | D             }dg|z   }t          d	                    |                     d |D             }dg|z   }t          d	                    |                     t          | |||||          }|D ]s}	|	d                             d          }
|
dz   dt          |           dz
  z  z   }t          |	d         |	d                   }t          |t          |          z             tdS )a  
    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.

    z-`shapes` and `nans` must have the same lengthz-`shapes` and `axes` must have the same lengthz Bottleneck performance benchmarkz    Bottleneck z; Numpy z2    Speed is NumPy time divided by Bottleneck timez,    NaN means approx one-fifth NaNs; %s used z           NaN   zno NaNc                     g | ]J}d                      t          |                              d                                        d          KS )r    r   joinstrsplitcenter).0shapes     :lib/python3.11/site-packages/bottleneck/benchmark/bench.py
<listcomp>zbench.<locals>.<listcomp>A   sF    LLLEbggc%jj&&s++,,33B77LLL    z            c                     g | ]M}d                      dt          |          z                       d                                        d          NS )r   zaxis=r   r   r   )r   axiss     r   r   zbench.<locals>.<listcomp>D   sK    TTTtbggwT*11#6677>>rBBTTTr   name   z%7.1fz%11.1fr   
statementssetupsN)len
ValueErrorprintbn__version__npr   appendr   r   
benchsuiteljusttimertuple)shapesaxesnansdtypeorder	functionsheadernansuitetestr   fmtspeeds                r   r   r      s3   L 6{{c$iiHIII
6{{c$iiHIII 

,---	E2>>>2>>
JKKK	
>???	
83u::
EFFF	"IIIZF / / 	/MM%,,r**++++MM(//"--....	"''&//LLVLLLFZ& F	"''&//TTtTTTFZ& F	"''&//vudD%CCE " "F|!!"%%Wnx3v;;?;;d<($x.99cE%LL !!!!	" "r   c                 :   g }t          |           dk    rt          d          |D ]s}t          j        d          5  t	          | d         |          }t	          | d         |          }d d d            n# 1 swxY w Y   |                    ||z             t|S )N   zTwo statements needed.ignore)invalidr   r   )r!   r"   r&   errstater   r'   )r   r    r7   setupt0t1s         r   r*   r*   P   s    E
:!1222  [*** 	2 	2JqM511BJqM511B	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	R"WLs   -A77A;	>A;	c                 f   t          j        t          j        |           |          }|r6t          |j        j        t           j                  rt           j        |d d d<   t           j        	                    |           }|
                    |           t          j         |j        |  |          S )N)r/      )r0   )r&   arangeprod
issubclassr/   typeinexactr3   randomRandomStateshufflearrayreshape)r   r/   r.   r0   arss         r   getarrayrN   \   s    
	"'%.....A 
17<44 ##A#			u	%	%BJJqMMM8IAIu%U3333r   c           
      2   g }d }t          j        dd          }|ddgz  }|D ]N}	||	|vr	i }
|	|
d<   dd	g|
d
<   d|	d|	d|	d|	d	} ||| ||||          |
d<   |                    |
           Oddg}|D ]H}	||	|vr	i }
|	|
d<   ddg|
d
<   d|	d|	d} ||| ||||          |
d<   |                    |
           Iddg}|D ]l}	||	|vr	i }
|	|
d<   |	dk    rddg|
d
<   n|	dk    rddg|
d
<   nt          d          d|	d|	d} ||| ||||          |
d<   |                    |
           mt          j        d d          }|D ]H}	||	|vr	i }
|	|
d<   d!d"g|
d
<   d#|	d$|	d%} ||| ||||          |
d<   |                    |
           I|S )&Nc           	      d   d}g }t          |||          D ]\  }}	}
|t          |          t          |          t          |
          t          |          t          |	          | fz  }d                    d |                    d          D                       }|                    |           |S )Nz|
        from bottleneck.benchmark.bench import getarray
        a = getarray(%s, '%s', %s, '%s')
        axis=%s
        %s
c                 6    g | ]}|                                 S  )strip)r   lines     r   r   z1benchsuite.<locals>.getsetups.<locals>.<listcomp>y   s     BBBD4::<<BBBr   )zipr   r   r   r'   )r=   r,   r.   r-   r/   r0   templater    r   r   r3   ss               r   	getsetupszbenchsuite.<locals>.getsetupsi   s    
  #FD$ 7 7 
	 
	E4E

E

CE

D		 A 		BBAGGDMMBBBCCAMM!r   reduceT)	as_stringrankdatananrankdatar   zbn_func(a, axis)zsl_func(a, axis)r   z$
            from bottleneck import z/ as bn_func
            try: from numpy import zH as sl_func
            except ImportError: from bottleneck.slow import z as sl_func
            if "zE" == "median": from bottleneck.slow import median as sl_func
        r    	partitionargpartitionzbn_func(a, n, axis)zsl_func(a, n, axis)z4 as bn_func
            from bottleneck.slow import z as sl_func
            if axis is None: n = a.size
            else: n = a.shape[axis] - 1
            n = max(n // 2, 0)
        replacepushzbn_func(a, nan, 0)zslow_func(a, nan, 0)zbn_func(a, 5, axis)zslow_func(a, 5, axis)zUnknow function namezF
            from numpy import nan
            from bottleneck import z as slow_func
        movezbn_func(a, w, 1, axis)zsw_func(a, w, 1, axis)z.
            from bottleneck.slow.move import z/ as sw_func
            from bottleneck import z7 as bn_func
            w = a.shape[axis] // 5
        )r$   get_functionsr'   r"   )r,   r/   r.   r-   r0   r1   r4   rY   funcsfuncrunr=   s               r   r(   r(   e   s   E  * X666E	j-((E   T%:%:F/1CDL DDDDDDDD

 "	%tUEJJHS .)E   T%:%:F24IJL DDDD	
 "	%tUEJJHS E   T%:%:F9!57M NCV^^!68O PC3444 DDDD
 "	%tUEJJHS Vt444E   T%:%:F57OPL DDDD
 "	%tUEJJHSLr   )
numpyr&   
bottleneckr$   r   __all__r   r*   rN   r(   rS   r   r   <module>rj      s            " " " " " ") LKK		*	*	*

E" E" E" E"P	 	 	4 4 4o o o o or   