
    Yc[                         d Z ddlZddlZg dZddZddZddZddZdd	Z	dd
Z
ddZddZddZddZddZd ZddZdS )z<Alternative methods of calculating moving window statistics.    N)
move_sum	move_meanmove_stdmove_varmove_minmove_maxmove_argminmove_argmaxmove_median	move_rankc                 >    t          t          j        | |||          S )z%Slow move_sum for unaccelerated dtypeaxis)	move_funcnpnansumawindow	min_countr   s       4lib/python3.11/site-packages/bottleneck/slow/move.pyr   r          RY694@@@@    c                 >    t          t          j        | |||          S )z&Slow move_mean for unaccelerated dtyper   )r   r   nanmeanr   s       r   r   r      s    RZFIDAAAAr   c                 @    t          t          j        | ||||          S )z%Slow move_std for unaccelerated dtyper   ddof)r   r   nanstdr   r   r   r   r   s        r   r   r          RY694dKKKKr   c                 @    t          t          j        | ||||          S )z%Slow move_var for unaccelerated dtyper   )r   r   nanvarr!   s        r   r   r   $   r"   r   c                 >    t          t          j        | |||          S )z%Slow move_min for unaccelerated dtyper   )r   r   nanminr   s       r   r   r   )   r   r   c                 >    t          t          j        | |||          S )z%Slow move_max for unaccelerated dtyper   )r   r   nanmaxr   s       r   r   r   .   r   r   c                 0    d }t          || |||          S )z(Slow move_argmin for unaccelerated dtypec                 v   t          j        | d          } t          d           g| j        z  }t          d d d          ||<   | t	          |                   } 	 t          j        | |          }n# t          $ r |                                 } t          j        |           }t          j	        | t           j
        |           t          j        | |                              t           j                  }|j        dk    rt           j        }n%t          j        ||          }t           j        ||<   Y nw xY w|S NFcopyr   r   )wherer   )r   arrayslicendimtuple	nanargmin
ValueErrorr-   isnancopytoinfargminastypefloat64nanallr   r   flipidxmasks        r   r8   zmove_argmin.<locals>.argmin6   s   HQU###d}qv%4r**T
eDkkN	#,qt,,,CC 
	# 
	# 
	#A8A;;DIat,,,,)AD)))00<<Cx1} #fvd...FD	
	# 
s   A0 0CD65D6r   r   )r   r   r   r   r8   s        r   r	   r	   3   ,      ( VQ	====r   c                 0    d }t          || |||          S )z(Slow move_argmax for unaccelerated dtypec                 x   t          j        | d          } t          d           g| j        z  }t          d d d          ||<   | t	          |                   } 	 t          j        | |          }n# t          $ r |                                 } t          j        |           }t          j	        | t           j
         |           t          j        | |                              t           j                  }|j        dk    rt           j        }n%t          j        ||          }t           j        ||<   Y nw xY w|S r+   )r   r/   r0   r1   r2   	nanargmaxr4   r-   r5   r6   r7   argmaxr9   r:   r;   r<   r=   s        r   rF   zmove_argmax.<locals>.argmaxP   s   HQU###d}qv%4r**T
eDkkN	#,qt,,,CC 
	# 
	# 
	#A8A;;DIa"&----)AD)))00<<Cx1} #fvd...FD	
	# 
s   A0 0CD76D7r   rA   )r   r   r   r   rF   s        r   r
   r
   M   rB   r   c                 >    t          t          j        | |||          S )z(Slow move_median for unaccelerated dtyper   )r   r   	nanmedianr   s       r   r   r   g   s    R\1fidCCCCr   c                 4    t          t          | |||          S )z&Slow move_rank for unaccelerated dtyper   )r   lastrankr   s       r   r   r   l   s    Xq&)$????r   c                    t          j        |d          }||}n3|}||k    rd}t          |||fz            |dk    rt          d          |j        dk    rt          d          |t          d          |d	k     rt          d
          ||j        |         k    rt          d          t          |j        j        t           j                  rt          j	        |          }nt          j
        |j                  }t          d          g|j        z  }	t          |	          }
t          j                    5  t          j        d           t!          |j        |                   D ]d}t#          ||d	z             }t          |d	z   |z
  |d	z             |	|<   ||
|<    | |t%          |	                   fd|i||t%          |
          <   e	 ddd           n# 1 swxY w Y   t'          ||||          }t           j        ||<   |S )z>Generic moving window function implemented with a python loop.Fr,   Nz1min_count (%d) cannot be greater than window (%d)r   z&`min_count` must be greater than zero.z(moving window functions require ndim > 0z)An `axis` value of None is not supported.   z`window` must be at least 1.z`window` is too long.ignorer   )r   r/   r4   r1   shape
issubclassdtypetypeinexact
empty_likeemptyr0   listwarningscatch_warningssimplefilterrangeminr2   _maskr;   )funcr   r   r   r   kwargsmcmsgyidx1idx2iwinr?   s                 r   r   r   t   sy   
A G; 	GECSB</0001W 	GEFFFv{ ECDDD FDEEEz 97888 20111!',
++ M!HQW$KK=16!D::D		 	"	" G Gh'''qwt}%% 	G 	GAfa!e$$Cq1us{AE22DJDJ!T!E$KK.FFtFvFFAeDkkNN		GG G G G G G G G G G G G G G G 62t
$
$CVAcFHs   ;BGG #G c                 6   | | k                         |          }t          d           g| j        z  }t          d           g| j        z  }t          d           g| j        z  }t          |d           ||<   t          d |           ||<   t          d |          ||<   t          |          }t          |          }t          |          }||         }|||         z
  }t	          j        | j        t          j                  }	||k     |	|<   ||         |k     |	|<   |	S )NrP   )cumsumr0   r1   r2   r   rT   rN   bool_)
r   r   r   r   nra   rb   idx3nidx1r?   s
             r   r[   r[      s   	
aA$KK=16!D$KK=16!D$KK=16!Dvt$$DJtfW%%DJtV$$DJ;;D;;D;;DdGEAdGOE
(17"(
+
+
+C	!CI$)#CIJr   c                 *   t          j        | d          } | j        }| j        dk    rt	          | j                  }|                    |           t          j        || j                  }|	                    t           j
                   |j        dk    r|j        dk    rt           j
        }|S t          d          g|z  }t          dd          ||<   t          |          }t          d          g|z  }d||<   t          |          }t          j        |                                |          }| |         }|| k                        |          }	|| k                        |          }
|	|	z   |
z   dz
  d	z  }||dz
  z  }d	|d
z
  z  }|dk    r/|dk    rd}t          j        | |                   rt           j
        }nRt          j        ||dk    d           t          j        |t          j        | |                   t           j
                   |S )a  
    The ranking of the last element along the axis, ignoring NaNs.

    The ranking is normalized to be between -1 and 1 instead of the more
    common 1 and N. The results are adjusted for ties.

    Parameters
    ----------
    a : ndarray
        Input array. If `a` is not an array, a conversion is attempted.
    axis : int, optional
        The axis over which to rank. By default (axis=-1) the ranking
        (and reducing) is performed over the last axis.

    Returns
    -------
    d : array
        In the case of, for example, a 2d array of shape (n, m) and
        axis=1, the output will contain the rank (normalized to be between
        -1 and 1 and adjusted for ties) of the the last element of each row.
        The output in this example will have shape (n,).

    Examples
    --------
    Create an array:

    >>> y1 = larry([1, 2, 3])

    What is the rank of the last element (the value 3 in this example)?
    It is the largest element so the rank is 1.0:

    >>> import numpy as np
    >>> from la.afunc import lastrank
    >>> x1 = np.array([1, 2, 3])
    >>> lastrank(x1)
    1.0

    Now let's try an example where the last element has the smallest
    value:

    >>> x2 = np.array([3, 2, 1])
    >>> lastrank(x2)
    -1.0

    Here's an example where the last element is not the minimum or maximum
    value:

    >>> x3 = np.array([1, 3, 4, 5, 2])
    >>> lastrank(x3)
    -0.5

    Fr,   r   rf   rL   Nr   g      ?g       @g      ?)r   r/   r1   sizerU   rN   poprT   rP   fillr;   r0   r2   r5   sumputmask)r   r   r1   rN   rindlastindlast2ri   	a_indlastges              r   rJ   rJ      s   j 	A6Dv{ QW		$HU!'***	rvFaK 	afk 	AT{{md"G"dOOGDMGnnGd}t#HHTNXH
(1++4  A'
I	QD!!A	aT""A	
QSCA	QWAq3wAqy 56 	A8AhK   	A

1a1fa   

1bhq{++RV444Hr   )Nr   )Nr   r   )r   )__doc__rV   numpyr   __all__r   r   r   r   r   r   r	   r
   r   r   r   r[   rJ    r   r   <module>r|      sa   > >       A A A A
B B B B
L L L L
L L L L
A A A A
A A A A
> > > >4> > > >4D D D D
@ @ @ @# # # #L  ,U U U U U Ur   