o
    \h	                     @   s"   d dl ZddlmZ dddZdS )    N   )stable_cumsum2   c           
         sP  | j }|dkr| d S | j dkr| d} | j|jkr1| jd |jd kr1t|| jd dfj}tj| dd}tj||dd}t|dd|d d    dk}t	 |  | d  |< t
 fdd	tjd D }t
|}|jd d tjfd
dd|d}t| jd }|||f }	| |	|f }|dkr|d S |S )a  Compute weighted percentile

    Computes lower weighted percentile. If `array` is a 2D array, the
    `percentile` is computed along the axis 0.

        .. versionchanged:: 0.24
            Accepts 2D `array`.

    Parameters
    ----------
    array : 1D or 2D array
        Values to take the weighted percentile of.

    sample_weight: 1D or 2D array
        Weights for each value in `array`. Must be same shape as `array` or
        of shape `(array.shape[0],)`.

    percentile: int or float, default=50
        Percentile to compute. Must be value between 0 and 100.

    Returns
    -------
    percentile : int if `array` 1D, ndarray if `array` 2D
        Weighted percentile.
    r    r   )r   )axisd   r   c                    s(   g | ]}t d d |f  | qS )N)npsearchsorted).0i)adjusted_percentile
weight_cdfr   V/home/air/segue/gemini/backup/venv/lib/python3.10/site-packages/sklearn/utils/stats.py
<listcomp>9   s    z(_weighted_percentile.<locals>.<listcomp>c                    s   t | d S )Nr   )r	   clip)x)max_idxr   r   <lambda>B   s    z&_weighted_percentile.<locals>.<lambda>)r   arr)ndimreshapeshaper	   tileTargsorttake_along_axisr   	nextafterarrayrangeapply_along_axisarange)
r   sample_weight
percentilen_dim
sorted_idxsorted_weightsmaskpercentile_idx	col_indexpercentile_in_sortedr   )r   r   r   r   _weighted_percentile	   s:   

 
r+   )r   )numpyr	   extmathr   r+   r   r   r   r   <module>   s   