
    
9j8                        S SK Jr  S SKrS SKrS SKrS SKJr  S SKJr  S SKJ	r	  S SK
Jr  SS jrSS jrSS	 jrSS
 jrSS jr    SS jrS r    SSS.S jjr    SSS.S jjrS rg)    )annotationsN)_core)_routines_statistics)_fusion_thread_local)contentc                    [         R                  " 5       (       a6  U(       a  [        S5      e[         R                  " [        R
                  XUS9$ U R                  XUS9$ )a  Returns the minimum of an array or the minimum along an axis.

.. note::

   When at least one element is NaN, the corresponding min value will be
   NaN.

Args:
    a (cupy.ndarray): Array to take the minimum.
    axis (int): Along which axis to take the minimum. The flattened array
        is used by default.
    out (cupy.ndarray): Output array.
    keepdims (bool): If ``True``, the axis is remained as an axis of
        size one.

Returns:
    cupy.ndarray: The minimum of ``a``, along the axis if specified.

.. note::
   When cuTENSOR accelerator is used, the output value might be collapsed
   for reduction axes that have one or more NaN elements.

.. seealso:: :func:`numpy.amin`

z4cupy.amin does not support `keepdims` in fusion yet.axisoutr
   r   keepdims)r   	is_fusingNotImplementedErrorcall_reduction_statisticsaminminar
   r   r   s       P/home/wildlama/miniconda3/lib/python3.13/site-packages/cupy/_statistics/order.pyr   r      ]    4 %%''%FH H#22a5 	5 55dh577    c                    [         R                  " 5       (       a6  U(       a  [        S5      e[         R                  " [        R
                  XUS9$ U R                  XUS9$ )a  Returns the maximum of an array or the maximum along an axis.

.. note::

   When at least one element is NaN, the corresponding min value will be
   NaN.

Args:
    a (cupy.ndarray): Array to take the maximum.
    axis (int): Along which axis to take the maximum. The flattened array
        is used by default.
    out (cupy.ndarray): Output array.
    keepdims (bool): If ``True``, the axis is remained as an axis of
        size one.

Returns:
    cupy.ndarray: The maximum of ``a``, along the axis if specified.

.. note::
   When cuTENSOR accelerator is used, the output value might be collapsed
   for reduction axes that have one or more NaN elements.

.. seealso:: :func:`numpy.amax`

z4cupy.amax does not support `keepdims` in fusion yet.r	   r   )r   r   r   r   r   amaxmaxr   s       r   r   r   3   r   r   c                    [         R                  " XX#S9n[        R                  " U5      R	                  5       (       a  [
        R                  " S[        5        U$ )as  Returns the minimum of an array along an axis ignoring NaN.

When there is a slice whose elements are all NaN, a :class:`RuntimeWarning`
is raised and NaN is returned.

Args:
    a (cupy.ndarray): Array to take the minimum.
    axis (int): Along which axis to take the minimum. The flattened array
        is used by default.
    out (cupy.ndarray): Output array.
    keepdims (bool): If ``True``, the axis is remained as an axis of
        size one.

Returns:
    cupy.ndarray: The minimum of ``a``, along the axis if specified.

.. warning::

    This function may synchronize the device.

.. seealso:: :func:`numpy.nanmin`

r   All-NaN slice encountered)r   nanminr   isnananywarningswarnRuntimeWarningr   r
   r   r   ress        r   r   r   X   @    2 ,,q
@C}}S1>BJr   c                    [         R                  " XX#S9n[        R                  " U5      R	                  5       (       a  [
        R                  " S[        5        U$ )as  Returns the maximum of an array along an axis ignoring NaN.

When there is a slice whose elements are all NaN, a :class:`RuntimeWarning`
is raised and NaN is returned.

Args:
    a (cupy.ndarray): Array to take the maximum.
    axis (int): Along which axis to take the maximum. The flattened array
        is used by default.
    out (cupy.ndarray): Output array.
    keepdims (bool): If ``True``, the axis is remained as an axis of
        size one.

Returns:
    cupy.ndarray: The maximum of ``a``, along the axis if specified.

.. warning::

    This function may synchronize the device.

.. seealso:: :func:`numpy.nanmax`

r   r   )r   nanmaxr   r   r    r!   r"   r#   r$   s        r   r(   r(   w   r&   r   c                "    U R                  XUS9$ )a  Returns the range of values (maximum - minimum) along an axis.

.. note::

   The name of the function comes from the acronym for 'peak to peak'.

   When at least one element is NaN, the corresponding ptp value will be
   NaN.

Args:
    a (cupy.ndarray): Array over which to take the range.
    axis (int): Axis along which to take the minimum. The flattened
        array is used by default.
    out (cupy.ndarray): Output array.
    keepdims (bool): If ``True``, the axis is retained as an axis of
        size one.

Returns:
    cupy.ndarray: The minimum of ``a``, along the axis if specified.

.. note::
   When cuTENSOR accelerator is used, the output value might be collapsed
   for reduction axes that have one or more NaN elements.

.. seealso:: :func:`numpy.amin`

r   )ptpr   s       r   r*   r*      s    8 55dh577r   c                	  ^  [         R                  " T U5      n[         R                  " U5      nUR                  S:X  a  US    nSnOSnUR                  S:  a$  [	        SR                  UR                  5      5      e[        U[        5      (       a  U4nU(       aM  Uc  ST R                  -  n	O:[        T R                  5      n	U H  n
SXT R                  -  '   M     [        U	5      n	Uc+  U(       a  T R                  5       nOT R                  5       nSnO[        U 4S jU 5       5      n[        [        T R                  5      5      [        U5      -
  n[        U5      n[!        [#        U5      5       H  u  pT R%                  X5      m M     U(       a"  T R'                  T R                  S U S-   5      nO/T R'                  T R                  S U S-   5      R)                  5       nS	nUR+                  US
9  UR                  U   nUUS-
  -  nUS;   a  [	        SU S35      eUS:X  a4  [         R,                  " U5      R/                  [         R0                  5      nOUS:X  a4  [         R2                  " U5      R/                  [         R0                  5      nOUS:X  a1  S[         R,                  " U5      [         R2                  " U5      -   -  nO[US:X  a4  [         R4                  " U5      R/                  [         R0                  5      nO!US:X  a  O[	        SR                  U5      5      eUR6                  [         R0                  :X  a(  [         R8                  " X5      nUR;                  USUS9nOUc0  [         R<                  " UR                  S S	 UR                  -   US9nO"[         R8                  " USUR                  5      n[         R>                  " SSSS5      " UXR                  S:  a  UR                  S	   OSUR@                  U5        [         R8                  " US	5      nU(       a  URC                  S5      nU(       a&  UR@                  S:  a  SW	-   n	UR'                  W	5      n[D        RF                  " U5      $ )Nr   TF   z4Expected q to have a dimension of 1.
Actual: {} != 1)r,   c              3  @   >#    U  H  oTR                   -  v   M     g 7f)N)ndim).0axr   s     r   	<genexpr>&_quantile_unchecked.<locals>.<genexpr>   s     04R!&&[4s   )r3   )r
         ?)inverted_cdfaveraged_inverted_cdfclosest_observationinterpolated_inverted_cdfhazenweibullmedian_unbiasednormal_unbiased'z;' method is not yet supported. Please use any other method.lowerhighermidpointg      ?nearestlinearz^Unexpected interpolation method.
Actual: '{}' not in ('linear', 'lower', 'higher', 'midpoint')r	   )dtypez0S idx, raw T a, raw int32 offset, raw int32 sizezU reta#  
            ptrdiff_t idx_below = floor(idx);
            U weight_above = idx - idx_below;

            ptrdiff_t max_idx = size - 1;
            ptrdiff_t offset_bottom = _ind.get()[0] * offset + idx_below;
            ptrdiff_t offset_top = min(offset_bottom + 1, max_idx);

            U diff = a[offset_top] - a[offset_bottom];

            if (weight_above < 0.5) {
                ret = a[offset_bottom] + diff * weight_above;
            } else {
                ret = a[offset_top] - diff * (1 - weight_above);
            }
            cupy_percentile_weightnening)$cupyresult_typeasarrayr.   
ValueErrorformat
isinstanceintlistshapetupleravelflattensetrangelen	enumeratesortedswapaxesreshapecopysortfloorastypeint32ceilaroundrC   rollaxistakeemptyElementwiseKernelsizesqueezer   _internal_ascontiguousarray)r   qr
   r   overwrite_inputmethodr   rC   zerodkeepdimr0   apnkeepkeepisNxindicesrets   `                  r   _quantile_uncheckedrs      s    Q"EQAvv{dGvvz ++16!&&>; 	;$u<QVVmG177mG'(QVV$ GnG|BB 04005=!CI-D	fTl+DA

1 A ,1776E?U23B1776E?U2388:BDGGG	$B27mG L L 2fX &8 8 9 	9	7	**W%,,TZZ8	8	))G$++DJJ7	:	G,tyy/AAB	9	++g&--djj9	8	 55;VF^E 	E }}

"mmB%hhwQCh0;**RXXcr]QWW4EBC--Q1C>  +%	
& 2ww{rxx|277C'	I( mmC$kk!n66A:goGkk'",,S11r   c                    [        U [        R                  5      (       a  [        O[        nUR	                  SU :*  5      =(       a    UR	                  U S:*  5      $ )Ng        r4   )rJ   rE   ndarraynumpycount_nonzero)rf   xps     r   _quantile_is_validry   #  sB    At||,,%BC1H%D"*:*:18*DDr   )interpolationc          
         Ub  [        XWS5      n[        U[        [        45      (       a  [        R
                  " U5      nUS-  n[        U5      (       d  [        S5      e[        XX#UUUS9$ )a  Computes the q-th percentile of the data along the specified axis.

Args:
    a (cupy.ndarray): Array for which to compute percentiles.
    q (float, tuple of floats or cupy.ndarray): Percentiles to compute
        in the range between 0 and 100 inclusive.
    axis (int or tuple of ints): Along which axis or axes to compute the
        percentiles. The flattened array is used by default.
    out (cupy.ndarray): Output array.
    overwrite_input (bool): If True, then allow the input array `a`
        to be modified by the intermediate calculations, to save
        memory. In this case, the contents of the input `a` after this
        function completes is undefined.
    method (str): Interpolation method when a quantile lies between
        two data points. ``linear`` interpolation is used by default.
        Supported interpolations are ``lower``, ``higher``, ``midpoint``,
        ``nearest`` and ``linear``.
    keepdims (bool): If ``True``, the axis is remained as an axis of
        size one.
    interpolation (str): Deprecated name for the method keyword argument.

Returns:
    cupy.ndarray: The percentiles of ``a``, along the axis if specified.

.. seealso:: :func:`numpy.percentile`

percentiled   z)Percentiles must be in the range [0, 100]r
   r   rg   rh   r   	_check_interpolation_as_methodrJ   rN   rL   rv   rG   ry   rH   rs   r   rf   r
   r   rg   rh   r   rz   s           r   r|   r|   (  sv    @  /<1!eT]## MM!	CAa  DEE	4'	 r   c          
         Ub  [        XWS5      n[        U[        [        45      (       a  [        R
                  " U5      n[        U5      (       d  [        S5      e[        XX#UUUS9$ )a  Computes the q-th quantile of the data along the specified axis.

Args:
    a (cupy.ndarray): Array for which to compute quantiles.
    q (float, tuple of floats or cupy.ndarray): Quantiles to compute
        in the range between 0 and 1 inclusive.
    axis (int or tuple of ints): Along which axis or axes to compute the
        quantiles. The flattened array is used by default.
    out (cupy.ndarray): Output array.
    overwrite_input (bool): If True, then allow the input array `a`
        to be modified by the intermediate calculations, to save
        memory. In this case, the contents of the input `a` after this
        function completes is undefined.
    method (str): Interpolation method when a quantile lies between
        two data points. ``linear`` interpolation is used by default.
        Supported interpolations are ``lower``, ``higher``, ``midpoint``,
        ``nearest`` and ``linear``.
    keepdims (bool): If ``True``, the axis is remained as an axis of
        size one.
    interpolation (str): Deprecated name for the method keyword argument.

Returns:
    cupy.ndarray: The quantiles of ``a``, along the axis if specified.

.. seealso:: :func:`numpy.quantile`
quantilez%Quantiles must be in the range [0, 1]r~   r   r   s           r   r   r   Y  sm    @  /:/!eT]## MM!a  @AA	4'	 r   c                d    [         R                  " SU S3[        SS9  U S:w  a  [        S5      eU$ )Nz!the `interpolation=` argument to z was renamed to `method=`, which has additional options.
Users of the modes 'nearest', 'lower', 'higher', or 'midpoint' are encouraged to review the method they. (Deprecated NumPy 1.22)   )
stacklevelrB   zjYou shall not pass both `method` and `interpolation`!
(`interpolation` is Deprecated in favor of `method`))r!   r"   DeprecationWarning	TypeError)rh   rz   fnames      r   r   r     sM    MM
+E7 3" 	"
 	q* CD 	D r   )NNF)NNFrB   F)
__future__r   r!   rv   rE   r   
cupy._corer   r   r   cupy._logicr   r   r   r   r(   r*   rs   ry   r|   r   r    r   r   <module>r      s    "     : + "8J"8J>>8> .2(-'!&k2\E
 %)$.
 ".b #'"-
  -br   