o
    i                     @   s(   d dl mZmZ dddZdddZdS )	   )_find_matching_floating_dtypeget_namespace_and_device2   Nc                    s  t | \}}t| d}j| ||d} j|||d}| j}|dkr&| S | jdkr1| d} | j|jkrM| jd |jd krM|| jd dfj}j| dd}j	||dd}	| jd }
| |d j
|
|df }|rj	| |dd}d|	|< j|	jdd|d	 d
    dk} |  | d  |<  fddtjd D }|jd d }|d|}j
| jd |d}|||f }| ||f }|dkr|d S |S )a3  Compute the weighted percentile with method 'inverted_cdf'.

    When the percentile lies between two data points of `array`, the function returns
    the lower value.

    If `array` is a 2D array, the `values` are selected along axis 0.

    `NaN` values are ignored by setting their weights to 0. If `array` is 2D, this
    is done in a column-isolated manner: a `NaN` in the second column, does not impact
    the percentile computed for the first column even if `sample_weight` is 1D.

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

        .. versionchanged:: 1.7
            Supports handling of `NaN` values.

    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_rank: int or float, default=50
        The probability level of the percentile to compute, in percent. Must be between
        0 and 100.

    xp : array_namespace, default=None
        The standard-compatible namespace for `array`. Default: infer.

    Returns
    -------
    percentile : scalar or 0D array if `array` 1D (or 0D), array if `array` 2D
        Weighted percentile at the requested probability level.
    xp)Zdtypedevice       )r	   )Zaxis)r
   .)r   d   ).r
   c                    s$   g | ]} |d f  | qS ).)Zsearchsorted).0Zfeature_idxZadjusted_percentile_rankZ
weight_cdfr    b/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/sklearn/utils/stats.py
<listcomp>a   s    z(_weighted_percentile.<locals>.<listcomp>)r   r   ZasarrayndimZreshapeshapeZtileTZargsortZtake_along_axisZarangeanyisnanZcumulative_sum	nextafterstackrangeZclip)arraysample_weightpercentile_rankr   _r   Zfloating_dtypeZn_dimZ
sorted_idxZsorted_weightsZ
n_featuresZlargest_value_per_columnZsorted_nan_maskmaskZpercentile_indicesZmax_idxZcol_indicesZpercentile_in_sortedresultr   r   r   _weighted_percentile
   sJ   '
 
		r   c                 C   s*   t | |||dt |  |d| |d d S )Nr   r   r   )r   )r   r   r   r   r   r   r   _averaged_weighted_percentilev   s
   r    )r   N)Zutils._array_apir   r   r   r    r   r   r   r   <module>   s   
l