
    {Kg5	                          d dl ZddlmZ ddZy)    N   )stable_cumsumc           
         | j                   }|dk(  r| d   S | j                   dk(  r| j                  d      } | j                  |j                  k7  rN| j                  d   |j                  d   k(  r/t        j                  || j                  d   df      j
                  }t        j                  | d      }t        j                  ||d      }t        |d      }|dz  |d   z  }|dk(  }t        j                  ||   ||   dz         ||<   t        j                  t        |j                  d         D 	cg c]"  }	t        j                  |dd|	f   ||	         $ c}	      }
t        j                  |
      }
|j                  d   dz
  t        j                  fd	d|

      }
t        j                  | j                  d         }||
|f   }| ||f   }|dk(  r|d   S |S c c}	w )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   Nc                 2    t        j                  | d      S )Nr   )npclip)xmax_idxs    W/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/sklearn/utils/stats.py<lambda>z&_weighted_percentile.<locals>.<lambda>?   s    "''!Q(    )r   arr)ndimreshapeshaper   tileTargsorttake_along_axisr   	nextafterarrayrangesearchsortedapply_along_axisarange)r   sample_weight
percentilen_dim
sorted_idxsorted_weights
weight_cdfadjusted_percentilemaskipercentile_idx	col_indexpercentile_in_sortedr   s                @r   _weighted_percentiler,      s   4 JJEzRyzzQg&{{m)))ekk!n@S@STU@V.VA/BCEEE*J''zJN ~A6J$s*Z^; !#D "D!#6t#<q#@! XX :++A./	
/ OOJq!t,.A!.DE/	
N XXn-Nq!A%G(((qnN 		%++a.)I%ni&?@+Y67J!QJ:a=6J6	
s   6'G")2   )numpyr   extmathr   r,   r   r   r   <module>r0      s     "?7r   