
    `i(                     x    d dl Z d dlZd dlZd dlmZ ddZddZddddZddZ	dd	Z
dd
ZddZddZddZdS )    N)_routines_statisticsFc                 2    t          j        | ||||          S )a?  Compute the median along the specified axis.

    Returns the median of the array elements.

    Args:
        a (cupy.ndarray): Array to compute the median.
        axis (int, sequence of int or None): Axis along which the medians are
             computed. The flattened array is used by default.
        out (cupy.ndarray): Output array.
        overwrite_input (bool): If ``True``, then allow use of memory of input
            array a for calculations. The input array will be modified by the
            call to median. This will save memory when you do not need to
            preserve the contents of the input array. Treat the input as
            undefined, but it will probably be fully or partially sorted.
            Default is ``False``. If ``overwrite_input`` is ``True`` and ``a``
            is not already an ndarray, an error will be raised.
        keepdims (bool): If ``True``, the axis is remained as an axis of size
            one.

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

    .. seealso:: :func:`numpy.median`

    )_statistics_medianaaxisoutoverwrite_inputkeepdimss        l/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/_statistics/meanvar.pymedianr      s    4 q$_hGGG    c                 v    | j         j        dv rt          j        | ||||          S t	          | ||||          S )aV  Compute the median along the specified axis, while ignoring NaNs.

    Returns the median of the array elements.

    Args:
        a (cupy.ndarray): Array to compute the median.
        axis (int, sequence of int or None): Axis along which the medians are
            computed. The flattened array is used by default.
        out (cupy.ndarray): Output array.
        overwrite_input (bool): If ``True``, then allow use of memory of input
            array a for calculations. The input array will be modified by the
            call to median. This will save memory when you do not need to
            preserve the contents of the input array. Treat the input as
            undefined, but it will probably be fully or partially sorted.
            Default is ``False``. If ``overwrite_input`` is ``True`` and ``a``
            is not already an ndarray, an error will be raised.
        keepdims (bool): If ``True``, the axis is remained as an axis of size
            one.

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

    .. seealso:: :func:`numpy.nanmedian`

    efdFD)r	   r
   r   r   )dtypecharr   
_nanmedianr   r   s        r   	nanmedianr   %   sN    4 	w|w%asOXNNNad_') ) ) 	)r   r   c                   t          j        |           } |@|                     ||          }|j                            | j        |j        z            }nt          j        |          }t          | j        j        t          j        t          j	        f          r-t          j        t          j        | j        |j        df          }nt          j        | j        |j                  }| j        |j        k    r|t          d          |j        dk    rt          d          |j        d         | j        |         k    rt!          d          t          j        || j        dz
  d	z  |j        z             }|                    d
|          }|                    |||          }t          j        |dk              rt+          d          t          j        | ||                              ||          |z  }|rR|j        |j        k    r>t          j        t          j        |          |j                                                  }||fS |S )a  Returns the weighted average along an axis.

    Args:
        a (cupy.ndarray): Array to compute average.
        axis (int): Along which axis to compute average. The flattened array
            is used by default.
        weights (cupy.ndarray): Array of weights where each element
            corresponds to the value in ``a``. If ``None``, all the values
            in ``a`` have a weight equal to one.
        returned (bool): If ``True``, a tuple of the average and the sum
            of weights is returned, otherwise only the average is returned.
        keepdims (bool): If ``True``, the axis is remained as an axis of size
            one.

    Returns:
        cupy.ndarray or tuple of cupy.ndarray: The average of the input array
        along the axis and the sum of weights.

    .. warning::

        This function may synchronize the device if ``weight`` is given.

    .. seealso:: :func:`numpy.average`
    N)r	   r   f8z;Axis must be specified when shapes of a and weights differ.   z81D weights expected when shapes of a and weights differ.r   z5Length of weights not compatible with specified axis.)r   )r	   r   r   g        z(Weights sum to zero, can't be normalized)r   r   )cupyasarraymeanr   typesize
issubclassnumpyintegerbool_	functoolsreducepromote_typesshape	TypeErrorndim
ValueErrorbroadcast_toswapaxessumanyZeroDivisionErrormultiplyarraycopy)	r   r	   weightsreturnedr   avgsclwgtresult_dtypes	            r   averager9   F   s>   4 	QAff$f22innQVch.//l7##aglU]EK$@AA 	C$+E,?-.Wci,FH HLL !.qw	BBL 7ci|   x1}}NP P Py|qwt},, KM M M #C!&1*)<sy)HIIC,,r4((Cgg4|hgGG8C3J 	=#;= = = mAs,777;;8 < % %'*+  9	!!#DJsOOSY??DDFFCCx
r   c                 4    |                      ||||          S )a  Returns the arithmetic mean along an axis.

    Args:
        a (cupy.ndarray): Array to compute mean.
        axis (int, sequence of int or None): Along which axis to compute mean.
            The flattened array is used by default.
        dtype: Data type specifier.
        out (cupy.ndarray): Output array.
        keepdims (bool): If ``True``, the axis is remained as an axis of
            size one.

    Returns:
        cupy.ndarray: The mean of the input array along the axis.

    .. seealso:: :func:`numpy.mean`

    r	   r   r
   r   )r   r   r	   r   r
   r   s        r   r   r      s    & 66t5cH6EEEr   c                 6    |                      |||||          S )a  Returns the variance along an axis.

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

    Returns:
        cupy.ndarray: The variance of the input array along the axis.

    .. seealso:: :func:`numpy.var`

    r	   r   r
   ddofr   )varr   r	   r   r
   r?   r   s         r   r@   r@      *    & 55d%St"  $ $ $r   c                 6    |                      |||||          S )a$  Returns the standard deviation along an axis.

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

    Returns:
        cupy.ndarray: The standard deviation of the input array along the axis.

    .. seealso:: :func:`numpy.std`

    r>   )stdrA   s         r   rD   rD      rB   r   c                     | j         j        dv r|                     ||||          S t          j        | ||||          S )a6  Returns the arithmetic mean along an axis ignoring NaN values.

    Args:
        a (cupy.ndarray): Array to compute mean.
        axis (int, sequence of int or None): Along which axis to compute mean.
            The flattened array is used by default.
        dtype: Data type specifier.
        out (cupy.ndarray): Output array.
        keepdims (bool): If ``True``, the axis is remained as an axis of
            size one.

    Returns:
        cupy.ndarray: The mean of the input array along the axis ignoring NaNs.

    .. seealso:: :func:`numpy.nanmean`

    biur;   )r   kindr   r   _nanmeanr<   s        r   nanmeanrI      sT    $ 	w|uvv4u#vIII 	EsX? ? ? ?r   c                     | j         j        dv r|                     |||||          S t          j        | |||||          S )a  Returns the variance along an axis ignoring NaN values.

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

    Returns:
        cupy.ndarray: The variance of the input array along the axis.

    .. seealso:: :func:`numpy.nanvar`

    rF   r>   )r   rG   r@   r   _nanvarrA   s         r   nanvarrL      f    $ 	w|uuu$e4&  ( ( 	( 	EsJ J J Jr   c                     | j         j        dv r|                     |||||          S t          j        | |||||          S )a;  Returns the standard deviation along an axis ignoring NaN values.

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

    Returns:
        cupy.ndarray: The standard deviation of the input array along the axis.

    .. seealso:: :func:`numpy.nanstd`

    rF   r>   )r   rG   rD   r   _nanstdrA   s         r   nanstdrP     rM   r   )NNFF)NNF)NNNF)NNNr   F)r$   r!   r   
cupy._corer   r   r   r   r9   r   r@   rD   rI   rL   rP    r   r   <module>rS      s         : : : : : :H H H H:) ) ) )BFE F F F F FRF F F F,$ $ $ $.$ $ $ $.? ? ? ?4J J J J6J J J J J Jr   