
    3;ji%                          d dl mZmZ 	 ddZdS )    )_find_matching_floating_dtypeget_namespace_and_device2   FNc           	      &   ! t          |           \  }}t          |           }                    | ||          }                     |||          }                    |||          }| j        }|dk    r| S | j        dk    r                    | d          } | j        |j        k    rD| j        d         |j        d         k    r(                    || j        d         df          j        }|j        }	|	dk    r                    |d          }                    | dd          }
	                    ||
d	          }| j        d         }| |
d
         
                    ||          f         }                                        |                    r0	                                        |           |
d	          }d||<                       |j        d	          !|j        d         }                    ||f||          }t          |          D ]\  }}|dz  !d         z    dk    }                     |          |         dz              |<                        !fdt%          !j        d                   D                       }|
j        d         dz
  }                    |d|          }
                    | j        d         |          }|
||f         }|r!||f          z
  }|                    |          j        k    }                    |dz   d|          }|
||f         }||||f         dk             }|D ]M}!|||         f         }                    !|df         |d          }||k    r||         }|
||f         ||<   N                    || ||f         | ||f         | ||f         z   dz            |d|f<   | ||f         |d|f<   |	dk    r|d         }|dk    r|d         n|S )a  Compute the weighted percentile.

    Implement an array API compatible (weighted version) of NumPy's 'inverted_cdf'
    method when `average=False` (default) and 'averaged_inverted_cdf' when
    `average=True`.

    For an array ordered by increasing values, when the percentile lies exactly on a
    data point:

    * 'inverted_cdf' takes the exact data point.
    * 'averaged_inverted_cdf' takes the average of the exact data point and the one
      above it (this means it gives the same result as `median` for unit weights).

    E.g., for the array [1, 2, 3, 4] the percentile rank at each data point would
    be [25, 50, 75, 100]. Percentile rank 50 lies on '2'. 'average_inverted_cdf'
    computes the average of '2' and '3', making it 'symmetrical' because if you
    reverse the array, rank 50 would fall on '3'. It also matches 'median'.
    On the other hand, 'inverted_cdf', which does not satisfy the symmetry property,
    would give '2'.

    When the requested percentile lies between two data points, both methods return
    the higher data point.
    E.g., for the array [1, 2, 3, 4, 5] the percentile rank at each data point would
    be [20, 40, 60, 80, 100]. Percentile rank 50, lies between '2' and '3'. Taking the
    higher data point is symmetrical because if you reverse the array, 50 would lie
    between '4' and '3'. Both methods match median in this case.

    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.

        .. versionchanged:: 1.8
            Supports `average`, which calculates percentile using the
            "averaged_inverted_cdf" method.

    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: scalar or 1D array, default=50
        The probability level(s) of the percentile(s) to compute, in percent. Must be
        between 0 and 100. If a 1D array, computes all percentiles (along each
        axis 0 if `array` is 2D).

    average : bool, default=False
        If `True`, uses the "averaged_inverted_cdf" quantile method, otherwise
        defaults to "inverted_cdf". "averaged_inverted_cdf" is symmetrical with
        unit `sample_weight`, such that the total of `sample_weight` below or equal to
        `_weighted_percentile(percentile_rank)` is the same as the total of
        `sample_weight` above or equal to `_weighted_percentile(100-percentile_rank)`.
        This symmetry is not guaranteed with non-unit weights.

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

    Returns
    -------
    percentile : scalar, 1D array, or 2D array
        Weighted percentile at the requested probability level(s).
        If `array` is 1D and `percentile_rank` is scalar, returns a scalar.
        If `array` is 2D and `percentile_rank` is scalar, returns a 1D array
            of shape `(array.shape[1],)`
        If `array` is 1D and `percentile_rank` is 1D, returns a 1D array
            of shape `(percentile_rank.shape[0],)`
        If `array` is 2D and `percentile_rank` is 1D, returns a 2D array
            of shape `(array.shape[1], percentile_rank.shape[0])`
    )xp)dtypedevicer      )r
   )r
   F)axisstable)r   )r   .)r	   d   ).r   c                 X    g | ]&}                     |d f         |                   'S ).)searchsorted).0feature_idxadjusted_percentile_rank
weight_cdfr   s     M/root/voice-cloning/.venv/lib/python3.11/site-packages/sklearn/utils/stats.py
<listcomp>z(_weighted_percentile.<locals>.<listcomp>   sN          {C/02J;2W       .right)side   ).r   )r   .)r   r   asarrayndimreshapeshapetileTargsorttake_along_axisarangeanyisnancumulative_sumempty	enumerate	nextafterstackrangeclipfinfoepsr   where)"arraysample_weightpercentile_rankaverager   _r	   floating_dtypen_dimn_dim_percentile
sorted_idxsorted_weights
n_featureslargest_value_per_columnsorted_nan_maskn_percentilesresultp_idxp_rankmaskpercentile_indicesmax_idxcol_indicespercentile_in_sortedfraction_aboveis_fraction_abovepercentile_plus_one_indicespercentile_plus_one_in_sortedzero_weight_colscol_idxcdf_val
next_indexr   r   s"       `                           @@r   _weighted_percentilerN   
   s   f -U33MB625R@@@NJJuN6JBBEJJ}N6JRRMjjvjVVOJEzzzQ

5'**{m)))ek!n@STU@V.V.VA/BCCE&+1**_d;; E%88J''z'JJN QJ$7RYYz&YAAA  
vvbhh/0011 ,,,RXXe__jq,QQ*+' "">#3!"<<J#)!,MXXz=1PVXWWF"?33 DJ DJv#)C<*W2E#E  (1,)+$T*,DT,JQ,N*
 *
 &  XX      $))9!)<#=#=	  
 
 "1%)WW%7GDDiiAvi>>)*<k*IJ &	J ;(::;>VV  !/.1I1I1M M*,''2Dq2H!W*U*U',6+[8-)  +;[HIQN  , Y Y$W.@.I%IJ__w|,gG -  

 ((!3G!<J9CJPWDW9X-g66!#!*K78.;<9;FGH 	" "F3: "'';['H!IF3:1"aZZ6&>>V3r   )r   FN)sklearn.utils._array_apir   r   rN    r   r   <module>rQ      sX           AEK4 K4 K4 K4 K4 K4r   