
    \ciR                         d dl Z d dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZmZ d dlmc mZ d dlmZmZ d Z edgd          d	d d
dddd            Zd Zd Zd Zd Z edg          dddd            ZdS )    N)betainc)xp_capabilitiesxp_ravelarray_namespace
xp_promote	xp_device_length_nonmaskedis_torch)_broadcast_arrays_contains_nanc                 x   t          | ||          }|                    |                    |           j        d          st	          d          |                    |                    |          j        d          st	          d          |=|                    |                    |          j        d          st	          d          t          | ||d|          \  } }}|                    |t          |                     }| j        }|d u }	t          | j        |j                  }
|	r!t          |           } t          |          }d	}nVt          j        |          st          |          |k    rd
}t	          |          ||
k    s||
 k     rd}t	          |          t          |          }h d}||vrd| }t	          |          h d}|||v rd| d}t	          |          t          | |d|          }|dvrd}t	          |          | j        |         d	k    rDt          | j                  }d||<   |                    ||j        |t          |                     } |1|                    | |d          }t'          ||f|          \  }}d }n|                    | |          \  } }|d	k    }|                    ||d          }t-          j        |           |                             |j        d          } |                    | |d          }|                    | ||          }|                    |||          }t'          |||||f|          \  }}}}}|du r"|j        |         dk    rd}t	          |          ||j        |         dk    n|}|                    ||d          }|                    ||d          }||n|                    ||d          }||n|                    ||d          }t;          |d|d          }||n||z
  }|rf|                    |          }|dk    r|                    |d          }n||                    |dd          z
  }|                     ||          }|                    |d	k    d          }t-          j        ||                              |j        d                   }|                    |          rE|                    |d          }t-          j        ||                              |j                  }nZ|                    |          rE|dk    r?|                    |d          }t-          j        ||                              d	          }|                    ||t          |                    }|dk    |d	k     z  |                    |          z  }|                    |          r?|                    |d          }t-          j        ||                              d           }||||||||	|
|||fS )!N)integralreal floatingz`x` must have real dtype.r   z"`p` must have real floating dtype.z`weights` must have real dtype.T)force_floatingxpdevicer   z"`axis` must be an integer or None.z7`axis` is not compatible with the shapes of the inputs.>   hazen_lowerlinear_higherweibull_nearest	_midpointinverted_cdfround_inwardround_nearestround_outwardmedian_unbiasednormal_unbiasedclosest_observationaveraged_inverted_cdfinterpolated_inverted_cdfharrell-davisz`method` must be one of >   r   r   r   r   r   r   r   r$   z	`method='z'` does not support `weights`.)xp_omit_okayr   >   FNTz/If specified, `keepdims` must be True or False.   dtyper   F)axisstabler)   r)   keepdimscopyzD`keepdims` may be False only if the length of `p` along `axis` is 1.)r   r-   	propagater$         ?)!r   isdtypeasarrayr(   
ValueErrorr   r   maxndimr   npiterableintr   shapelistfullnansortr   broadcast_arrayscount_nonzeroxpxatsetinfargsorttake_along_axismoveaxisr	   isnananyastype)xpmethodr)   
nan_policyr-   weightsr   r(   	axis_noner7   messagemethods
no_weightscontains_nansr;   yn_zero_weighti_zero_weighti_ynnansnan_outn_intp_masks                            e/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/scipy/stats/_quantile.py_quantile_ivr`      sy   	Aw	'	'B::bjjmm)+HII 64555::bjjmm)?;; ?=>>>Ozz"**W--35RSS :;;;q!WTbIIIMAq'


1Yq\\
**AGEIqvqvD 	"QKKQKK	T		 "c$ii4//6!!!
$,,DD5LLK!!!t99DA A AG
 W6W66!!!D D DJv33DfDDD!!!!!ZdrJJJM***C!!!
 	wt}QWdGGE26y||GDDGGADG// !Qd3331((G44
7 A((TD(QQF1IIm$((d(;;jjej44q#D11$$Wc$==,=7C/d-< -< -<)1gsM 	E 2 2X!!!'/'7""XH
AtR  A
AtR  A ggbkk'4.L.LG&3&;]]++mT2>>  	!RB666A"M(9A 'xx{{ $$ffTf++GG((B(FFFE		%''AffQ!V"f--Gq'""&&qwr{33A66'?? 	'

14
((Aq'""&&rv..AAVVD\\ 	'f77

14
((Aq$##A&&A


1E)A,,
77A!eA!,F	vvf~~ 'JJqtJ$$F1f!!#&&q&$
Hy$5 5    )z
dask.arrayzNo take_along_axis yet.F)skip_backendsjax_jitr   r1   )rN   r)   rO   r-   rP   c                <   t          | ||||||          }|\  }}}}}}}	}
}}}}|dv rt          |||	|||          }nB|dv rt          |||	|          }n+|dv rt          |||	||          }nt	          |||	||          }t          j        ||                              |j                  }|
r*|r(d|dz
  z  |j	        z   }|
                    ||          }d}|                    |d|          }|s|                    ||          }|j        dk    r|d	         n|S )
a$  
    Compute the p-th quantile of the data along the specified axis.

    Parameters
    ----------
    x : array_like of real numbers
        Data array.
    p : array_like of float
        Probability or sequence of probabilities of the quantiles to compute.
        Values must be between 0 and 1 (inclusive).
        While `numpy.quantile` can only compute quantiles according to the Cartesian
        product of the first two arguments, this function enables calculation of
        quantiles at different probabilities for each axis slice by following
        broadcasting rules like those of `scipy.stats` reducing functions.
        See `axis`, `keepdims`, and the examples.
    method : str, default: 'linear'
        The method to use for estimating the quantile.
        The available options, numbered as they appear in [1]_, are:

        1. 'inverted_cdf'
        2. 'averaged_inverted_cdf'
        3. 'closest_observation'
        4. 'interpolated_inverted_cdf'
        5. 'hazen'
        6. 'weibull'
        7. 'linear'  (default)
        8. 'median_unbiased'
        9. 'normal_unbiased'

        'harrell-davis' is also available to compute the quantile estimate
        according to [2]_.

        'round_outward', 'round_inward', and 'round_nearest' are available for use
        in trimming and winsorizing data.

        See Notes for details.
    axis : int or None, default: 0
        Axis along which the quantiles are computed.
        ``None`` ravels both `x` and `p` before performing the calculation,
        without checking whether the original shapes were compatible.
        As in other `scipy.stats` functions, a positive integer `axis` is resolved
        after prepending 1s to the shape of `x` or `p` as needed until the two arrays
        have the same dimensionality. When providing `x` and `p` with different
        dimensionality, consider using negative `axis` integers for clarity.
    nan_policy : str, default: 'propagate'
        Defines how to handle NaNs in the input data `x`.

        - ``propagate``: if a NaN is present in the axis slice (e.g. row) along
          which the  statistic is computed, the corresponding slice of the output
          will contain NaN(s).
        - ``omit``: NaNs will be omitted when performing the calculation.
          If insufficient data remains in the axis slice along which the
          statistic is computed, the corresponding slice of the output will
          contain NaN(s).
        - ``raise``: if a NaN is present, a ``ValueError`` will be raised.

        If NaNs are present in `p`, a ``ValueError`` will be raised.
    keepdims : bool, optional
        Consider the case in which `x` is 1-D and `p` is a scalar: the quantile
        is a reducing statistic, and the default behavior is to return a scalar.
        If `keepdims` is set to True, the axis will not be reduced away, and the
        result will be a 1-D array with one element.

        The general case is more subtle, since multiple quantiles may be
        requested for each axis-slice of `x`. For instance, if both `x` and `p`
        are 1-D and ``p.size > 1``, no axis can be reduced away; there must be an
        axis to contain the number of quantiles given by ``p.size``. Therefore:

        - By default, the axis will be reduced away if possible (i.e. if there is
          exactly one element of `p` per axis-slice of `x`).
        - If `keepdims` is set to True, the axis will not be reduced away.
        - If `keepdims` is set to False, the axis will be reduced away
          if possible, and an error will be raised otherwise.
    weights : array_like of finite, non-negative real numbers
        Frequency weights; e.g., for counting number weights,
        ``quantile(x, p, weights=weights)`` is equivalent to
        ``quantile(np.repeat(x, weights), p)``. Values other than finite counting
        numbers are accepted, but may not have valid statistical interpretations.
        Not compatible with ``method='harrell-davis'`` or those that begin with
        ``'round_'``.

    Returns
    -------
    quantile : scalar or ndarray
        The resulting quantile(s). The dtype is the result dtype of `x` and `p`.

    See Also
    --------
    numpy.quantile
    :ref:`outliers`

    Notes
    -----
    Given a sample `x` from an underlying distribution, `quantile` provides a
    nonparametric estimate of the inverse cumulative distribution function.

    By default, this is done by interpolating between adjacent elements in
    ``y``, a sorted copy of `x`::

        (1-g)*y[j] + g*y[j+1]

    where the index ``j`` and coefficient ``g`` are the integral and
    fractional components of ``p * (n-1)``, and ``n`` is the number of
    elements in the sample.

    This is a special case of Equation 1 of H&F [1]_. More generally,

    - ``j = (p*n + m - 1) // 1``, and
    - ``g = (p*n + m - 1) % 1``,

    where ``m`` may be defined according to several different conventions.
    The preferred convention may be selected using the ``method`` parameter:

    =============================== =============== ===============
    ``method``                      number in H&F   ``m``
    =============================== =============== ===============
    ``interpolated_inverted_cdf``   4               ``0``
    ``hazen``                       5               ``1/2``
    ``weibull``                     6               ``p``
    ``linear`` (default)            7               ``1 - p``
    ``median_unbiased``             8               ``p/3 + 1/3``
    ``normal_unbiased``             9               ``p/4 + 3/8``
    =============================== =============== ===============

    Note that indices ``j`` and ``j + 1`` are clipped to the range ``0`` to
    ``n - 1`` when the results of the formula would be outside the allowed
    range of non-negative indices. When ``j`` is clipped to zero, ``g`` is
    set to zero as well. The ``-1`` in the formulas for ``j`` and ``g``
    accounts for Python's 0-based indexing.

    The table above includes only the estimators from [1]_ that are continuous
    functions of probability `p` (estimators 4-9). SciPy also provides the
    three discontinuous estimators from [1]_ (estimators 1-3), where ``j`` is
    defined as above, ``m`` is defined as follows, and ``g`` is ``0`` when
    ``index = p*n + m - 1`` is less than ``0`` and otherwise is defined below.

    1. ``inverted_cdf``: ``m = 0`` and ``g = int(index - j > 0)``
    2. ``averaged_inverted_cdf``: ``m = 0`` and
       ``g = (1 + int(index - j > 0)) / 2``
    3. ``closest_observation``: ``m = -1/2`` and
       ``g = 1 - int((index == j) & (j%2 == 1))``

    Note that for methods ``inverted_cdf`` and ``averaged_inverted_cdf``, only the
    relative proportions of tied observations (and relative weights) affect the
    results; for all other methods, the total number of observations (and absolute
    weights) matter.

    A different strategy for computing quantiles from [2]_, ``method='harrell-davis'``,
    uses a weighted combination of all elements. The weights are computed as:

    .. math::

        w_{n, i} = I_{i/n}(a, b) - I_{(i - 1)/n}(a, b)

    where :math:`n` is the number of elements in the sample,
    :math:`i` are the indices :math:`1, 2, ..., n-1, n` of the sorted elements,
    :math:`a = p (n + 1)`, :math:`b = (1 - p)(n + 1)`,
    :math:`p` is the probability of the quantile, and
    :math:`I` is the regularized, lower incomplete beta function
    (`scipy.special.betainc`).

    ``method='round_nearest'`` is equivalent to indexing ``y[j]``, where::

        j = int(np.round(p*n) if p < 0.5 else np.round(n*p - 1))

    This is useful when winsorizing data: replacing ``p*n`` of the most extreme
    observations with the next most extreme observation. ``method='round_outward'``
    adjusts the direction of rounding to winsorize fewer elements::

        j = int(np.floor(p*n) if p < 0.5 else np.ceil(n*p - 1))

    and ``method='round_inward'`` rounds to winsorize more elements::

        j = int(np.ceil(p*n) if p < 0.5 else np.floor(n*p - 1))

    These methods are also useful for trimming data: removing ``p*n`` of the most
    extreme observations. See :ref:`outliers` for example applications.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy import stats
    >>> x = np.asarray([[10, 8, 7, 5, 4],
    ...                 [0, 1, 2, 3, 5]])

    Take the median of each row.

    >>> stats.quantile(x, 0.5, axis=-1)
    array([7.,  2.])

    Take a different quantile for each row.

    >>> stats.quantile(x, [[0.25], [0.75]], axis=-1, keepdims=True)
    array([[5.],
           [3.]])

    Take multiple quantiles for each row.

    >>> stats.quantile(x, [0.25, 0.75], axis=-1)
    array([[5., 8.],
           [1., 3.]])

    Take different quantiles for each row.

    >>> p = np.asarray([[0.25, 0.75],
    ...                 [0.5, 1.0]])
    >>> stats.quantile(x, p, axis=-1)
    array([[5., 8.],
           [2., 5.]])

    Take different quantiles for each column.

    >>> stats.quantile(x.T, p.T, axis=0)
    array([[5., 2.],
           [8., 5.]])

    References
    ----------
    .. [1] R. J. Hyndman and Y. Fan,
       "Sample quantiles in statistical packages,"
       The American Statistician, 50(4), pp. 361-365, 1996
    .. [2] Harrell, Frank E., and C. E. Davis.
       "A new distribution-free quantile estimator."
       Biometrika 69.3 (1982): 635-640.

    >	   r   r   r   r   r   r    r!   r"   r#   >   r$   >   r   r   r   r   r&   r&   r0   r+   r    )r`   _quantile_hf_quantile_hd_quantile_bc_quantile_winsorrB   rC   rD   r>   r;   reshaperH   squeezer7   )rL   rM   rN   r)   rO   r-   rP   temprV   rZ   rQ   r7   r^   r   resr;   s                   r_   quantilero      sp   P 1fdJ'JJD04.Q64X	4" C C C 1aFGR88	$	$	$1aB''	A	A	A1aFB//q!Q33
&f


!
!"&
)
)C  X dQh#)+jje$$
++c2t
$
$C )jj4j((h!mm3r77,ra   c                 z   t          ddddd|d|z
  |dz  dz   |dz  dz   		  	        }||         }|||z  |z   }|dz  }	|	dz
  }
n|                    |d
          }|                    ||j                  }|                    ||j        d d
         dz             }|                    ||dz
  d
          }||z  |z   }t          ||d          }	t          ||dz
  d          }
|                    |
| j	                  |                    |	| j	                  }	}
|dz  }|dk    r |                    |dk    |j	                  }n^|dk    r&d|                    |dk    |j	                  z   dz  }n2|dk    r,d|                    |dk    |
dz  dk    z  |j	                  z
  }|dv rA|                    |          }t          j        ||dk                                   d          }t          j        |          |
dk                                  d          }|                    |
d|dz
            }
|                    |	d|dz
            }	d|z
  |                    | |                    |
|j                  d
          z  ||                    | |                    |	|j                  d
          z  z   S )Nr   g      r2   r&      gUUUUUU?   g      ?)	r   r"   r!   r#   r   r   r   r   r    r0   r+   )r(   re   rightsider   r"      r!   >   r   r!   r"   g        )dictcumulative_sumr4   int64broadcast_tor;   rG   _xp_searchsortedrK   r(   rB   rC   rD   clip)rV   rM   rZ   rN   rP   r   msmjgjp1jcumulative_weightsr]   total_weightgs                  r_   rg   rg     s   	1A4()aAcCi1s
D 
D 
DB 	6
AUQYAg!G..wR.@@

1BH
--'9'?'Dt'KLL))*<eAgB)OO!12GDDD/AGDDD1ag&&		#qw(?(?3
QAIIq1urx((	*	*	*AEBH---2	(	(	(AFq1uz2BH===QQQJJqMMF1b1f!!!$$q		!a%QA
2q1uA
''#r1q5
!
!CUb((BIIa,B,B(LLL"$$Q		#rx(@(@r$JJJK Lra   c                    |                     |dd          d|j        f         }||dz   z  }d|z
  |dz   z  }|                    | j        d         dz   | j        t          |                     }t          ||||z            }|ddd f         |dd df         z
  }t          j        ||	                    |                    
                    d          }|                    || d          }|                     |dd          S )Nr0   r   .r&   r'   r+   )rH   newaxisaranger;   r(   r   r   rB   rC   rI   rD   vecdot)	rV   rM   rZ   r   abiwrn   s	            r_   rh   rh     s     	Ar1c2:o.A	QUA	
Q1q5A
		!'"+/1	FFA1a!eA	#qrr'
QsCRCx[ Aq"((1++""1%%A
))Aqr)
"
"C;;sAr"""ra   c                 R   t          |j        |j        f|j        |j        f|j        |j        f          }||         \  }}|                    |dk      |||z             |||z  dz
                      }|                    | |                    ||j                  d          S )N)r   r   r   r2   r&   r0   r+   )rw   floorceilroundwhererG   rK   ry   )	rV   rM   rZ   rN   r   opsop_leftop_rightr   s	            r_   rj   rj     s    
bh0Wbh/ h13 3 3C FGX
S''!A#,,1q(9(9::Aa1bh!7!7bAAAra   c           	      >   ||dz
  z  }|dk    r|                     | |                    |                    |          |j                  d          |                     | |                    |                    |          |j                  d          z   dz  S |dk    r|                    |          }n7|dk    r|                    |          }n|dk    r|                    |          }|                     | |                    ||j                  d          S )	Nr&   r   r0   r+   rv   r   r   r   )rG   rK   r   ry   r   r   )rV   rM   rZ   rN   r   ijks          r_   ri   ri     s    
a!eB""1biibh&G&Gb"QQ$$Q		"''"++rx(H(Hr$RRSVWX 	X	8		HHRLL	9		GGBKK	:		HHRLLa1bh!7!7bAAAra   )rb   left)ru   r   c          
         |t          | |          n|}|                    d          j        }|                    |          j        dk    }t	          | |fd|          \  } }| j        dk    }|st          |          rN|r|r|                    |d          n|}|                    | ||          }|                    ||d          }|S |	                    |j
        dt          |           	          }| j
        d         dk    r|S |                    |                    |            dd
          }	|                    |	|j
                  }
|dk    r|j        n|j        }t#          t%          t'          j        | j
        d                             dz             D ]\}||
z   dz  }|                    | |d          } |||          }|                    |||
          }
|                    |||          }]|                     |||                    | dd
                    d|
          }|dk    r5|                    |                    |          | j
        d         |          n|}|                    ||d          }|S )Nr&   r   r0   )r)   r   rf   rt   Fr.   r   Tr,   r   rv   r+   rs   )r   r4   r(   r7   r   r
   rk   searchsortedrK   r=   r;   r   rA   rI   rz   
less_equallessranger:   mathlog2rG   r   min)rL   rV   ru   r   xp_default_inty_0dx_1doutr   rZ   r   comparer   cx0r   s                   r_   r{   r{     st   
 #%*A			"BZZ]](N::a=="DaV"444DAq6Q;D x|| "&747BJJq"aooao..ii^%i88

9Q<<00Awr{a
"((1++B>>A
17##A#v~~bmm27G 3ty--..233  UqL12..GArNNHHQ1HHQ1
((771bffQR$f??@@!Q
G
GC59W__"((288A;;S
1
1
1#C
))Ce)
4
4CJra   )r   numpyr8   scipy.specialr   scipy._lib._array_apir   r   r   r   r   r	   r
   scipy._lib.array_api_extra_libarray_api_extrarB   scipy.stats._axis_nan_policyr   r   r`   ro   rg   rh   rj   ri   r{   rf   ra   r_   <module>r      s        ! ! ! ! ! !                  ) ( ( ( ( ( ( ( ( I I I I I I I Iv5 v5 v5r  IJ     %A+PTB- B- B- B-   B-J$L $L $LN# # #"B B BB B B"  IJKKK#)d & & & & LK& & &ra   