ó
˜íYc           @   sƒ   d  d l  Z d  d l  m Z m Z d d d d d g Z d d „ Z d d	 „ Z d
 „  Z d „  Z	 e j
 d  d „ Z d d „ Z d S(   iÿÿÿÿN(   t	   partitiont   argpartitiont   rankdatat   nanrankdataR    R   t   pushc         C   s   t  t |  | ƒ S(   s5   Slow rankdata function used for unaccelerated dtypes.(   t   _rankt   scipy_rankdata(   t   at   axis(    (    s=   lib/python2.7/site-packages/bottleneck/slow/nonreduce_axis.pyR      s    c         C   s   t  t |  | ƒ S(   s8   Slow nanrankdata function used for unaccelerated dtypes.(   R   t   _nanrankdata_1d(   R   R   (    (    s=   lib/python2.7/site-packages/bottleneck/slow/nonreduce_axis.pyR      s    c         C   s    t  j | d t ƒ} | d  k r6 | j ƒ  } d } n  | j d k r` | j t  j d t ƒ} n< t  j	 |  | | ƒ } | j
 t  j k rœ | j t  j ƒ } n  | S(   Nt   copyi    (   t   npt   arrayt   Falset   Nonet   ravelt   sizet   astypet   float64t   Truet   apply_along_axist   dtype(   t   func1dR   R   t   y(    (    s=   lib/python2.7/site-packages/bottleneck/slow/nonreduce_axis.pyR      s    	c         C   sS   t  j |  j d t  j ƒ} | j t  j ƒ t  j |  ƒ } t |  | ƒ | | <| S(   NR   (   R   t   emptyt   shapeR   t   fillt   nant   isnanR   (   R   R   t   idx(    (    s=   lib/python2.7/site-packages/bottleneck/slow/nonreduce_axis.pyR	      s
    c   
   	   C   sï  | d k r t d ƒ ‚ n  t j |  ƒ } | j } | d k sO | | d k rg t j | | | ƒ } n  | d k rŒ | d d d … f } n | d k rœ | St j | ƒ } t j | j d  ƒ } t j | j d  ƒ } | j	 t j
 ƒ | j	 t j
 ƒ t j d d ƒ “ x‹ t | j d ƒ D]v } | | | k }	 t j
 | |	 <| d | f }	 | |	 | |	 | f <| d | f }	 | | |	 <| |	 | f | |	 <qWWd QX| d k s»| | d k r×t j | | d | ƒ } n  | d k rë| d S| S(	   s(   Slow push used for unaccelerated dtypes.s   `axis` cannot be Noneiÿÿÿÿi   Ni    t   invalidt   ignore.(   R   t
   ValueErrorR   R   t   ndimt   rollaxisR   R   R   R   R   t   errstatet   range(
   R   t   nR   R   R!   t   fidxt   recentt   countt   iR   (    (    s=   lib/python2.7/site-packages/bottleneck/slow/nonreduce_axis.pyR   '   s:    	
t   averagec         C   st  | d k r$ t  d j | ƒ ƒ ‚ n  t j t j |  ƒ ƒ }  | d k rN d n d } t j |  d	 | ƒ} t j | j d
 t j ƒ} t j	 | j d
 t j ƒ| | <| d k r· | d S|  | }  t j
 t |  d |  d  k f } | j ƒ  | } | d k r| St j
 t j | ƒ d t | ƒ f } | d k r<| | S| d k rX| | d d Sd | | | | d d S(   sè  
    rankdata(a, method='average')
    Assign ranks to data, dealing with ties appropriately.
    Ranks begin at 1.  The `method` argument controls how ranks are assigned
    to equal values.  See [1]_ for further discussion of ranking methods.
    Parameters
    ----------
    a : array_like
        The array of values to be ranked.  The array is first flattened.
    method : str, optional
        The method used to assign ranks to tied elements.
        The options are 'average', 'min', 'max', 'dense' and 'ordinal'.
        'average':
            The average of the ranks that would have been assigned to
            all the tied values is assigned to each value.
        'min':
            The minimum of the ranks that would have been assigned to all
            the tied values is assigned to each value.  (This is also
            referred to as "competition" ranking.)
        'max':
            The maximum of the ranks that would have been assigned to all
            the tied values is assigned to each value.
        'dense':
            Like 'min', but the rank of the next highest element is assigned
            the rank immediately after those assigned to the tied elements.
        'ordinal':
            All values are given a distinct rank, corresponding to the order
            that the values occur in `a`.
        The default is 'average'.
    Returns
    -------
    ranks : ndarray
         An array of length equal to the size of `a`, containing rank
         scores.
    References
    ----------
    .. [1] "Ranking", http://en.wikipedia.org/wiki/Ranking
    Examples
    --------
    >>> from scipy.stats import rankdata
    >>> rankdata([0, 2, 3, 2])
    array([ 1. ,  2.5,  4. ,  2.5])
    >>> rankdata([0, 2, 3, 2], method='min')
    array([ 1,  2,  4,  2])
    >>> rankdata([0, 2, 3, 2], method='max')
    array([ 1,  3,  4,  3])
    >>> rankdata([0, 2, 3, 2], method='dense')
    array([ 1,  2,  3,  2])
    >>> rankdata([0, 2, 3, 2], method='ordinal')
    array([ 1,  2,  4,  3])
    R*   t   mint   maxt   denset   ordinals   unknown method "{0}"t	   mergesortt	   quicksortt   kindR   i   iÿÿÿÿi    g      à?(   R*   R+   R,   R-   R.   (   R    t   formatR   R   t   asarrayt   argsortR   R   t   intpt   aranget   r_R   t   cumsumt   nonzerot   len(   R   t   methodt   algot   sortert   invt   obsR-   R(   (    (    s=   lib/python2.7/site-packages/bottleneck/slow/nonreduce_axis.pyR   S   s(    4
!&(   t   numpyR   R    R   t   __all__R   R   R   R   R	   t   infR   R   (    (    (    s=   lib/python2.7/site-packages/bottleneck/slow/nonreduce_axis.pyt   <module>   s   		,