Ë
    –\;j.y  ã                   óÄ   — d dl Z d dl mZ d dlmZ d dlmZmZ ddlmZm	Z	 ddl
mZ ddlmZmZ d	d
lmZ d	dlmZ g Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zy)é    N)Ú_C_ops)ÚDataType)Úin_dynamic_modeÚin_dynamic_or_pir_modeé   )Ú
check_typeÚcheck_variable_and_dtype)ÚVariable)ÚLayerHelperÚcoreé   )Ú_get_reduce_axis_with_tensor)Úwherec                 óÎ  — t        «       rt        j                  | ||«      S t        || «      \  }}t	        | dg d¢d«       t        |dt        t        t        t        fd«       t        |t        t        f«      r|D ]  }t        |dt        t        fd«       Œ t        di t        «       ¤Ž}|||dœ}|j                  | j                  «      }|j                  dd| id	|i|¬
«       |S )a{	  
    Computes the mean of the input tensor's elements along ``axis``.

    Args:
        x (Tensor): The input Tensor with data type float32, float64.
        axis (int|list|tuple, optional): The axis along which to perform mean
            calculations. ``axis`` should be int, list(int) or tuple(int). If
            ``axis`` is a list/tuple of dimension(s), mean is calculated along
            all element(s) of ``axis`` . ``axis`` or element(s) of ``axis``
            should be in range [-D, D), where D is the dimensions of ``x`` . If
            ``axis`` or element(s) of ``axis`` is less than 0, it works the
            same way as :math:`axis + D` . If ``axis`` is None, mean is
            calculated over all elements of ``x``. Default is None.
        keepdim (bool, optional): Whether to reserve the reduced dimension(s)
            in the output Tensor. If ``keepdim`` is True, the dimensions of
            the output Tensor is the same as ``x`` except in the reduced
            dimensions(it is of size 1 in this case). Otherwise, the shape of
            the output Tensor is squeezed in ``axis`` . Default is False.
        name (str, optional): Name for the operation (optional, default is None).
            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        Tensor, results of average along ``axis`` of ``x``, with the same data
        type as ``x``.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> x = paddle.to_tensor([[[1., 2., 3., 4.],
            ...                        [5., 6., 7., 8.],
            ...                        [9., 10., 11., 12.]],
            ...                       [[13., 14., 15., 16.],
            ...                        [17., 18., 19., 20.],
            ...                        [21., 22., 23., 24.]]])
            >>> out1 = paddle.mean(x)
            >>> print(out1.numpy())
            12.5
            >>> out2 = paddle.mean(x, axis=-1)
            >>> print(out2.numpy())
            [[ 2.5  6.5 10.5]
             [14.5 18.5 22.5]]
            >>> out3 = paddle.mean(x, axis=-1, keepdim=True)
            >>> print(out3.numpy())
            [[[ 2.5]
              [ 6.5]
              [10.5]]
             [[14.5]
              [18.5]
              [22.5]]]
            >>> out4 = paddle.mean(x, axis=[0, 2])
            >>> print(out4.numpy())
            [ 8.5 12.5 16.5]
    zx/input)Úuint16Úfloat16Úfloat32Úfloat64zmean/reduce_meanzaxis/dimzelements of axis/dim)ÚdimÚkeep_dimÚ
reduce_allÚreduce_meanÚXÚOut©ÚtypeÚinputsÚoutputsÚattrs)Úmean)r   r   r    r   r	   r   ÚintÚlistÚtupler
   Ú
isinstancer   ÚlocalsÚ"create_variable_for_type_inferenceÚdtypeÚ	append_op)	ÚxÚaxisÚkeepdimÚnamer   ÚitemÚhelperr   Úouts	            ú[G:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/tensor/stat.pyr    r       sñ   € ôp ÔÜ�{‰{˜1˜d GÓ,Ð,ä7¸¸aÓ@Ñˆ
�DÜ ØØÚ7Øô		
ô 	Ø�*œs¤D¬%´Ð:Ð<Nô	
ô �dœT¤5˜MÔ*Û�ÜØØ*Üœ(�OØ&õ	ð ô Ñ0¤v£xÑ0ˆà¨'ÀÑLˆØ×7Ñ7¸¿¹Ó@ˆØ×ÑØØ˜�8Ø˜C�LØð	 	ô 	
ð ˆ
ó    c                 ó  — t        «       st        | dg d¢d«       t        | |d|«      }t        j                  t        j
                  | |z
  d«      |||¬«      }| j                  }t        j                  t        j                  | «      d«      t        j                  t        j                  |«      d«      z  }|j                  |«      }|r3t        j                  g | j                  «      }	t        ||	kD  |dz
  |	«      }d|_        ||z  }|S )	a  
    Computes the variance of ``x`` along ``axis`` .

    Args:
        x (Tensor): The input Tensor with data type float16, float32, float64.
        axis (int|list|tuple, optional): The axis along which to perform variance calculations. ``axis`` should be int, list(int) or tuple(int).

            - If ``axis`` is a list/tuple of dimension(s), variance is calculated along all element(s) of ``axis`` . ``axis`` or element(s) of ``axis`` should be in range [-D, D), where D is the dimensions of ``x`` .
            - If ``axis`` or element(s) of ``axis`` is less than 0, it works the same way as :math:`axis + D` .
            - If ``axis`` is None, variance is calculated over all elements of ``x``. Default is None.

        unbiased (bool, optional): Whether to use the unbiased estimation. If ``unbiased`` is True, the divisor used in the computation is :math:`N - 1`, where :math:`N` represents the number of elements along ``axis`` , otherwise the divisor is :math:`N`. Default is True.
        keep_dim (bool, optional): Whether to reserve the reduced dimension in the output Tensor. The result tensor will have one fewer dimension than the input unless keep_dim is true. Default is False.
        name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        Tensor, results of variance along ``axis`` of ``x``, with the same data type as ``x``.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> x = paddle.to_tensor([[1.0, 2.0, 3.0], [1.0, 4.0, 5.0]])
            >>> out1 = paddle.var(x)
            >>> print(out1.numpy())
            2.6666667
            >>> out2 = paddle.var(x, axis=1)
            >>> print(out2.numpy())
            [1.         4.3333335]
    r)   ©r   r   r   ÚvarTr   )r+   r,   Úint64g      ð?)r   r	   r    ÚpaddleÚsumÚpowr'   ÚcastÚnumelÚastypeÚonesr   Ústop_gradient)
r)   r*   Úunbiasedr+   r,   Úur/   r'   ÚnÚ	one_consts
             r0   r4   r4   z   sâ   € ô@ ÔÜ ØˆsÒ5°uô	
ô 	ˆQ��d˜DÓ!€AÜ
�*‰*”V—Z‘Z  Q¡¨Ó+¨T¸7ÈÔ
N€Cà�G‰G€EÜ�‰”F—L‘L “O WÓ-´·±Ü�‰�SÓ˜7ó1ñ 	€Að 	
�‰�‹€AÙÜ—K‘K  A§G¡GÓ,ˆ	Ü�!�i‘-  S¡¨)Ó4ˆØ€A„OØˆ1�H€CØ€Jr1   c                 ó†   — t        «       st        | dg d¢d«       t        di t        «       ¤Ž}t	        j
                  |«      S )aF	  
    Computes the standard-deviation of ``x`` along ``axis`` .

    Args:
        x (Tensor): The input Tensor with data type float16, float32, float64.
        axis (int|list|tuple, optional): The axis along which to perform
            standard-deviation calculations. ``axis`` should be int, list(int)
            or tuple(int). If ``axis`` is a list/tuple of dimension(s),
            standard-deviation is calculated along all element(s) of ``axis`` .
            ``axis`` or element(s) of ``axis`` should be in range [-D, D),
            where D is the dimensions of ``x`` . If ``axis`` or element(s) of
            ``axis`` is less than 0, it works the same way as :math:`axis + D` .
            If ``axis`` is None, standard-deviation is calculated over all
            elements of ``x``. Default is None.
        unbiased (bool, optional): Whether to use the unbiased estimation. If
            ``unbiased`` is True, the standard-deviation is calculated via the
            unbiased estimator. If ``unbiased`` is True,  the divisor used in
            the computation is :math:`N - 1`, where :math:`N` represents the
            number of elements along ``axis`` , otherwise the divisor is
            :math:`N`. Default is True.
        keepdim (bool, optional): Whether to reserve the reduced dimension(s)
            in the output Tensor. If ``keepdim`` is True, the dimensions of
            the output Tensor is the same as ``x`` except in the reduced
            dimensions(it is of size 1 in this case). Otherwise, the shape of
            the output Tensor is squeezed in ``axis`` . Default is False.
        name (str, optional): Name for the operation (optional, default is None).
            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        Tensor, results of standard-deviation along ``axis`` of ``x``, with the
        same data type as ``x``.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> x = paddle.to_tensor([[1.0, 2.0, 3.0], [1.0, 4.0, 5.0]])
            >>> out1 = paddle.std(x)
            >>> print(out1.numpy())
            1.6329932
            >>> out2 = paddle.std(x, unbiased=False)
            >>> print(out2.numpy())
            1.490712
            >>> out3 = paddle.std(x, axis=1)
            >>> print(out3.numpy())
            [1.       2.081666]

    r)   r3   Ústd© )r   r	   r4   r%   r6   Úsqrt)r)   r*   r>   r+   r,   r/   s         r0   rC   rC   ¯   s;   € ôd "Ô#Ü ØˆsÒ5°uô	
ô ‰/”“‰/€CÜ�;‰;�sÓÐr1   c                 ó8  — t        «       rt        j                  | «      S t        | t        «      st        d«      ‚t        di t        «       ¤Ž}|j                  t        j                  j                  j                  ¬«      }|j                  dd| id|i¬«       |S )aâ  
    Returns the number of elements for a tensor, which is a 0-D int64 Tensor with shape [].

    Args:
        x (Tensor): The input Tensor, it's data type can be bool, float16, float32, float64, int32, int64, complex64, complex128.
        name (str, optional): Name for the operation (optional, default is None).
            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        Tensor: The number of elements for the input Tensor, whose shape is [].

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> x = paddle.full(shape=[4, 5, 7], fill_value=0, dtype='int32')
            >>> numel = paddle.numel(x)
            >>> print(numel.numpy())
            140


    zx must be a Tensor in numel©r'   ÚsizeÚInputr   )r   r   r   )r:   )r   r   r:   r$   r
   Ú	TypeErrorr   r%   r&   r   ÚVarDescÚVarTypeÚINT64r(   )r)   r,   r.   r/   s       r0   r:   r:   é   s‰   € ô0 ÔÜ�|‰|˜A‹Ðä˜!œXÔ&ÜÐ9Ó:Ð:ÜÑ1¬«Ñ1ˆØ×7Ñ7Ü—,‘,×&Ñ&×,Ñ,ð 8ó 
ˆð 	×Ñ˜f¨g°q¨\ÀEÈ3À<ÐÔPØˆ
r1   c                 óh  — t        | t        t        j                  j                  f«      st        d«      ‚t        |t        t        f«      rt        |«      dk(  rt        d«      ‚|€g }n/t        |t        «      rt        |«      }nt        |t        «      r|g}t        «       rt        j                  | ||«      S t        | dg d¢d«       t        d
i t!        «       ¤Ž}||dœ}|j#                  | j$                  «      }|j#                  | j$                  «      }|j'                  dd| i||dœ|¬	«       |S )a•  
    Compute the median along the specified axis, while ignoring NaNs.

    If the valid count of elements is a even number,
    the average value of both elements in the middle is calculated as the median.

    Args:
        x (Tensor): The input Tensor, it's data type can be int32, int64, float16, bfloat16, float32, float64.
        axis (None|int|list|tuple, optional):
            The axis along which to perform median calculations ``axis`` should be int or list of int.
            ``axis`` should be in range [-D, D), where D is the dimensions of ``x`` .
            If ``axis`` is less than 0, it works the same way as :math:`axis + D`.
            If ``axis`` is None, median is calculated over all elements of ``x``. Default is None.
        keepdim (bool, optional): Whether to reserve the reduced dimension(s)
            in the output Tensor. If ``keepdim`` is True, the dimensions of
            the output Tensor is the same as ``x`` except in the reduced
            dimensions(it is of size 1 in this case). Otherwise, the shape of
            the output Tensor is squeezed in ``axis`` . Default is False.
        name (str, optional): Name for the operation (optional, default is None).
            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        Tensor, results of median along ``axis`` of ``x``. The output dtype is the same as `x`.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> x = paddle.to_tensor([[float('nan'), 2. , 3. ], [0. , 1. , 2. ]])

            >>> y1 = x.nanmedian()
            >>> print(y1.numpy())
            2.0

            >>> y2 = x.nanmedian(0)
            >>> print(y2.numpy())
            [0.  1.5 2.5]

            >>> y3 = x.nanmedian(0, keepdim=True)
            >>> print(y3.numpy())
            [[0.  1.5 2.5]]

            >>> y4 = x.nanmedian((0, 1))
            >>> print(y4.numpy())
            2.0
    ú*In median, the input x should be a Tensor.r   zAxis list should not be empty.r   )Úint32r5   r   r   r   r   Ú	nanmedian©r*   r+   )r   ÚMedianIndexr   )rQ   )r$   r
   r6   ÚpirÚValuerJ   r"   r#   ÚlenÚ
ValueErrorr!   r   r   rQ   r	   r   r%   r&   r'   r(   )r)   r*   r+   r,   r.   r   r/   Úmedianss           r0   rQ   rQ     s  € ô^ �aœ(¤F§J¡J×$4Ñ$4Ð5Ô6ÜÐDÓEÐEä�$œœu˜Ô&¬3¨t«9¸ª>ÜÐ9Ó:Ð:à€|Ø‰Ü	�Dœ%Ô	 Ü�D‹z‰Ü	�Dœ#Ô	ØˆvˆäÔÜ×Ñ  4¨Ó1Ð1ä ØØÚIØô		
ô Ñ5¬F«HÑ5ˆØ¨'Ñ2ˆØ×7Ñ7¸¿¹Ó@ˆØ×;Ñ;¸A¿G¹GÓDˆØ×ÑØØ˜�8Ø°Ñ8Øð	 	ô 	
ð ˆ
r1   c           	      óÎ  — t        | t        t        j                  j                  f«      st        d«      ‚t        «       r| j                  dk(  rt        d«      ‚d}t        | j                  «      }|dk(  r|dv sJ d«       ‚d}|€d}|rt        j                  | «      } d}n0t        |t        «      r||k  r|| k\  st        d«      ‚|dk  r||z  }| j                  |   }|d	z	  }t        j                  | |d	z   |d¬
«      \  }}	| j                  t        j                   j"                  j$                  t&        j(                  fv rdnd}
|d	z  dk(  rZt        j*                  ||g|d	z
  g|g¬«      t        j*                  ||g|g|d	z   g¬«      z   }t        j,                  ||
¬«      dz  }n4t        j,                  t        j*                  ||g|g|d	z   g¬«      |
¬«      }|t        j.                  t        j,                  t        j0                  | «      |
¬«      | z  |d¬«      z   }|r,|r|j3                  d	g|z  «      }|S |j3                  g «      }|S |s|j5                  |«      }|S )a>	  
    Compute the median along the specified axis.

    Args:
        x (Tensor): The input Tensor, it's data type can be bool, float16, float32, float64, int32, int64.
        axis (int, optional): The axis along which to perform median calculations ``axis`` should be int.
            ``axis`` should be in range [-D, D), where D is the dimensions of ``x`` .
            If ``axis`` is less than 0, it works the same way as :math:`axis + D`.
            If ``axis`` is None, median is calculated over all elements of ``x``. Default is None.
        keepdim (bool, optional): Whether to reserve the reduced dimension(s)
            in the output Tensor. If ``keepdim`` is True, the dimensions of
            the output Tensor is the same as ``x`` except in the reduced
            dimensions(it is of size 1 in this case). Otherwise, the shape of
            the output Tensor is squeezed in ``axis`` . Default is False.
        name (str, optional): Name for the operation (optional, default is None).
            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        Tensor, results of median along ``axis`` of ``x``. If data type of ``x`` is float64, data type of results will be float64, otherwise data type will be float32.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> x = paddle.arange(12).reshape([3, 4])
            >>> print(x)
            Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0 , 1 , 2 , 3 ],
             [4 , 5 , 6 , 7 ],
             [8 , 9 , 10, 11]])

            >>> y1 = paddle.median(x)
            >>> print(y1)
            Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
            5.50000000)

            >>> y2 = paddle.median(x, axis=0)
            >>> print(y2)
            Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
            [4., 5., 6., 7.])

            >>> y3 = paddle.median(x, axis=1)
            >>> print(y3)
            Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
            [1.50000000, 5.50000000, 9.50000000])

            >>> y4 = paddle.median(x, axis=0, keepdim=True)
            >>> print(y4)
            Tensor(shape=[1, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
            [[4., 5., 6., 7.]])

    rO   r   z/In median, the size of input x should not be 0.F)éÿÿÿÿr   Nz8when input 0-D, axis can only be [-1, 0] or default NoneTzJIn median, axis should be none or an integer in range [-rank(x), rank(x)).r   )r*   Úlargestr   r   )ÚaxesÚstartsÚendsrG   r   rR   )r$   r
   r6   rT   rU   rJ   r   rH   rW   rV   ÚshapeÚflattenr!   Útopkr'   r   rK   rL   ÚFP64r   ÚFLOAT64Úslicer9   r7   ÚisnanÚreshapeÚsqueeze)r)   r*   r+   r,   Ú
is_flattenÚdimsÚszÚkthÚtensor_topkÚidxr'   Ú
out_tensors               r0   Úmedianro   a  sw  € ôl �aœ(¤F§J¡J×$4Ñ$4Ð5Ô6ÜÐDÓEÐEäÔ˜QŸV™V qš[äÐJÓKÐKà€JÜˆq�w‰w‹<€DØˆq‚yØð 
ñ 
ð 	Fð Fó		Fð 
ð
 ˆ
à€|Øˆ
áÜ�N‰N˜1ÓˆØ‰ä˜$¤Ô$¨T°Dª[¸TÀdÀUº]ÜØ\óð ð �!Š8Ø�D‰LˆDØ	
�‰�‰€BØ
�‰'€CÜ—{‘{ 1 c¨A¡g°DÀ%ÔHÑ€K�ð �7‰7”t—|‘|×+Ñ+×0Ñ0´(×2BÑ2BÐCÑCñ 	àð 
ð
 
ˆA�v�‚{Ü—\‘\Ø˜t˜f¨c°A©g¨Y¸c¸Uô
ä�L‰L˜¨D¨6¸3¸%ÀsÈQÁwÀiÔPñQˆ
ô —[‘[ °5Ô9¸AÑ=‰
ä—[‘[Ü�L‰LØ 4 &°#°¸cÀA¹g¸Yôð ô	
ˆ
ð œfŸj™jÜ�‰”F—L‘L “O¨5Ô1°AÑ5¸DÈ$ôñ €Jñ ÙØ#×+Ñ+¨Q¨C°$©JÓ7ˆJð Ðð	 $×+Ñ+¨BÓ/ˆJð Ðñ Ø#×+Ñ+¨DÓ1ˆJØÐr1   c                 óX  — t        | t        «      st        d«      ‚t        |t        t        f«      r|g}n:t        |t
        t        f«      rt        |«      dk  rt        d«      ‚t        d«      ‚t        | j                  «      }t        | j                  «      }|€t        j                  | «      } d}dg|z  }�nt        |t
        «      rÐg g }}|D ]H  }	t        |	t        «      r|	|k  r|	| k\  st        d«      ‚|	dk  r|	|z   }	|j                  |	«       d||	<   ŒJ t        t        t        |«       d«      «      }t        j                  | ||«      } t        |«      dk(  rt        j                  | «      } d}nXt        j                  | |d   |d   «      } |d   }n5t        |t        «      r||k  r|| k\  st        d«      ‚|dk  r||z  }d||<   | j                  «       }
|
j!                  «       j#                  |dd	¬
«      }g }|D ]¼  }|dk  s|dkD  rt        d«      ‚t%        «       rt        j&                  |d	¬«      }|r|j                  ||dz
  z  «       ŒS||dz
  z  }| j                  |   dz
  }t        j(                  ||¬«      }t        j*                  |
j-                  |d¬«      ||«      }|j                  |«       Œ¾ t        j.                  | |«      }g }|D �]  }t        j0                  |«      j3                  t        j4                  «      }t        j6                  |«      j3                  t        j4                  «      }t        j8                  |||¬«      }t        j8                  |||¬«      }||j3                  d	«      z
  }t        j:                  |j3                  d	«      |j3                  d	«      |«      }|st        j<                  ||¬«      }n|j?                  |«      }|j                  |«       �Œ t        |«      dkD  rt        j@                  |d«      }|S |d   }|S )aQ  
    Compute the quantile of the input along the specified axis.

    Args:
        x (Tensor): The input Tensor, it's data type can be float32, float64, int32, int64.
        q (int|float|list): The q for calculate quantile, which should be in range [0, 1]. If q is a list,
            each q will be calculated and the first dimension of output is same to the number of ``q`` .
        axis (int|list, optional): The axis along which to calculate quantile. ``axis`` should be int or list of int.
            ``axis`` should be in range [-D, D), where D is the dimensions of ``x`` .
            If ``axis`` is less than 0, it works the same way as :math:`axis + D`.
            If ``axis`` is a list, quantile is calculated over all elements of given axises.
            If ``axis`` is None, quantile is calculated over all elements of ``x``. Default is None.
        keepdim (bool, optional): Whether to reserve the reduced dimension(s)
            in the output Tensor. If ``keepdim`` is True, the dimensions of
            the output Tensor is the same as ``x`` except in the reduced
            dimensions(it is of size 1 in this case). Otherwise, the shape of
            the output Tensor is squeezed in ``axis`` . Default is False.
        ignore_nan: (bool, optional): Whether to ignore NaN of input Tensor.
            If ``ignore_nan`` is True, it will calculate nanquantile.
            Otherwise it will calculate quantile. Default is False.

    Returns:
        Tensor, results of quantile along ``axis`` of ``x``.
        In order to obtain higher precision, data type of results will be float64.
    zinput x should be a Tensor.r   zq should not be emptyz.Type of q should be int, float, list or tuple.r   zQAxis should be None, int, or a list, element should in range [-rank(x), rank(x)).rZ   Tr   )r*   r+   r'   zq should be in range [0, 1]rG   )Ú
fill_valuerR   )r*   )!r$   r
   rJ   r!   Úfloatr"   r#   rV   rW   r_   r6   r`   ÚappendÚrangeÚmoveaxisre   Úlogical_notr7   r   Ú	to_tensorÚ	full_liker   ÚanyÚsortÚfloorr;   rP   ÚceilÚtake_along_axisÚlerprg   rf   Ústack)r)   Úqr*   r+   Ú
ignore_nanri   Ú	out_shapeÚaxis_srcÚaxis_dstÚaxis_singleÚmaskÚvalid_countsÚindicesÚq_numÚindexÚ
last_indexÚnumsÚsorted_tensorr   Úindices_belowÚindices_upperÚtensor_upperÚtensor_belowÚweightsr/   s                            r0   Ú_compute_quantiler“   ×  sá  € ô6 �aœÔ"ÜÐ5Ó6Ð6ô �!”cœ5�\Ô"ØˆC‰Ü	�Aœœe�}Ô	%Üˆq‹6�QŠ;ÜÐ4Ó5Ð5äÐHÓIÐIô ˆq�w‰w‹<€DÜ�Q—W‘W“€IØ€|Ü�N‰N˜1ÓˆØˆØ�C˜$‘JŠ	ä�dœDÔ!Ø!# R�hˆHÛ#�Ü! +¬sÔ3Ø $Ò&¨;¸4¸%Ò+?ä$Økóð ð  ’?Ø"-°Ñ"4�KØ—‘ Ô,Ø)*�	˜+Ò&ð  $ô œE¤3 t£9 *¨aÓ0Ó1ˆHÜ—‘  8¨XÓ6ˆAÜ�8‹} Ò!Ü—N‘N 1Ó%�Ø‘ä—N‘N 1 h¨q¡k°8¸B±<Ó@�Ø ‘{‘ä˜d¤CÔ(°¸²ÀÈ$ÈÂÜ Øgóð ð �aŠxØ˜‘�ØˆI�d‰Oà�7‰7‹9€DØ×#Ñ#Ó%×)Ñ)Ø˜4 yð *ó €Lð €GãˆØ�1Š9˜ š	ÜÐ:Ó;Ð;ÜÔÜ×$Ñ$ U°)Ô<ˆEÙØ�N‰N˜5 L°1Ñ$4Ñ5Õ6ð ˜\¨AÑ-Ñ.ˆEØŸ™ ™¨Ñ*ˆJÜ×#Ñ# E°jÔAˆDÜ—L‘L §¡¨t¸T Ó!BÀDÈ%ÓPˆEØ�N‰N˜5Õ!ð ô —K‘K  4Ó(€Mà€Gô ˆÜŸ™ UÓ+×2Ñ2´6·<±<Ó@ˆÜŸ™ EÓ*×1Ñ1´&·,±,Ó?ˆÜ×-Ñ-Ø˜=¨tô
ˆô ×-Ñ-Ø˜=¨tô
ˆð ˜-×.Ñ.¨yÓ9Ñ9ˆÜ�k‰kØ×Ñ 	Ó*Ø×Ñ 	Ó*Øó
ˆñ
 Ü—.‘. ¨4Ô0‰Cà—+‘+˜iÓ(ˆCØ�‰�sÖð' ô* ˆ1ƒv�‚zÜ—,‘,˜w¨Ó*ˆð €Nð ˜!‘*ˆà€Nr1   c                 ó"   — t        | |||d¬«      S )aÃ  
    Compute the quantile of the input along the specified axis.
    If any values in a reduced row are NaN, then the quantiles for that reduction will be NaN.

    Args:
        x (Tensor): The input Tensor, it's data type can be float32, float64, int32, int64.
        q (int|float|list): The q for calculate quantile, which should be in range [0, 1]. If q is a list,
            each q will be calculated and the first dimension of output is same to the number of ``q`` .
        axis (int|list, optional): The axis along which to calculate quantile. ``axis`` should be int or list of int.
            ``axis`` should be in range [-D, D), where D is the dimensions of ``x`` .
            If ``axis`` is less than 0, it works the same way as :math:`axis + D`.
            If ``axis`` is a list, quantile is calculated over all elements of given axises.
            If ``axis`` is None, quantile is calculated over all elements of ``x``. Default is None.
        keepdim (bool, optional): Whether to reserve the reduced dimension(s)
            in the output Tensor. If ``keepdim`` is True, the dimensions of
            the output Tensor is the same as ``x`` except in the reduced
            dimensions(it is of size 1 in this case). Otherwise, the shape of
            the output Tensor is squeezed in ``axis`` . Default is False.
        name (str, optional): Name for the operation (optional, default is None).
            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        Tensor, results of quantile along ``axis`` of ``x``.
        In order to obtain higher precision, data type of results will be float64.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> y = paddle.arange(0, 8 ,dtype="float32").reshape([4, 2])
            >>> print(y)
            Tensor(shape=[4, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
            [[0., 1.],
             [2., 3.],
             [4., 5.],
             [6., 7.]])

            >>> y1 = paddle.quantile(y, q=0.5, axis=[0, 1])
            >>> print(y1)
            Tensor(shape=[], dtype=float64, place=Place(cpu), stop_gradient=True,
            3.50000000)

            >>> y2 = paddle.quantile(y, q=0.5, axis=1)
            >>> print(y2)
            Tensor(shape=[4], dtype=float64, place=Place(cpu), stop_gradient=True,
            [0.50000000, 2.50000000, 4.50000000, 6.50000000])

            >>> y3 = paddle.quantile(y, q=[0.3, 0.5], axis=0)
            >>> print(y3)
            Tensor(shape=[2, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
            [[1.80000000, 2.80000000],
             [3.        , 4.        ]])

            >>> y[0,0] = float("nan")
            >>> y4 = paddle.quantile(y, q=0.8, axis=1, keepdim=True)
            >>> print(y4)
            Tensor(shape=[4, 1], dtype=float64, place=Place(cpu), stop_gradient=True,
            [[nan       ],
             [2.80000000],
             [4.80000000],
             [6.80000000]])

    F©r*   r+   r�   ©r“   ©r)   r€   r*   r+   s       r0   Úquantiler˜   ]  s   € ôB ˜Q ¨°gÈ%ÔPÐPr1   c                 ó"   — t        | |||d¬«      S )a€  
    Compute the quantile of the input as if NaN values in input did not exist.
    If all values in a reduced row are NaN, then the quantiles for that reduction will be NaN.

    Args:
        x (Tensor): The input Tensor, it's data type can be float32, float64, int32, int64.
        q (int|float|list): The q for calculate quantile, which should be in range [0, 1]. If q is a list,
            each q will be calculated and the first dimension of output is same to the number of ``q`` .
        axis (int|list, optional): The axis along which to calculate quantile. ``axis`` should be int or list of int.
            ``axis`` should be in range [-D, D), where D is the dimensions of ``x`` .
            If ``axis`` is less than 0, it works the same way as :math:`axis + D`.
            If ``axis`` is a list, quantile is calculated over all elements of given axises.
            If ``axis`` is None, quantile is calculated over all elements of ``x``. Default is None.
        keepdim (bool, optional): Whether to reserve the reduced dimension(s)
            in the output Tensor. If ``keepdim`` is True, the dimensions of
            the output Tensor is the same as ``x`` except in the reduced
            dimensions(it is of size 1 in this case). Otherwise, the shape of
            the output Tensor is squeezed in ``axis`` . Default is False.
        name (str, optional): Name for the operation (optional, default is None).
            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        Tensor, results of quantile along ``axis`` of ``x``.
        In order to obtain higher precision, data type of results will be float64.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> x = paddle.to_tensor(
            ...     [[0, 1, 2, 3, 4],
            ...      [5, 6, 7, 8, 9]],
            ...     dtype="float32")
            >>> x[0,0] = float("nan")

            >>> y1 = paddle.nanquantile(x, q=0.5, axis=[0, 1])
            >>> print(y1)
            Tensor(shape=[], dtype=float64, place=Place(cpu), stop_gradient=True,
            5.)

            >>> y2 = paddle.nanquantile(x, q=0.5, axis=1)
            >>> print(y2)
            Tensor(shape=[2], dtype=float64, place=Place(cpu), stop_gradient=True,
            [2.50000000, 7.        ])

            >>> y3 = paddle.nanquantile(x, q=[0.3, 0.5], axis=0)
            >>> print(y3)
            Tensor(shape=[2, 5], dtype=float64, place=Place(cpu), stop_gradient=True,
            [[5.        , 2.50000000, 3.50000000, 4.50000000, 5.50000000],
             [5.        , 3.50000000, 4.50000000, 5.50000000, 6.50000000]])

            >>> y4 = paddle.nanquantile(x, q=0.8, axis=1, keepdim=True)
            >>> print(y4)
            Tensor(shape=[2, 1], dtype=float64, place=Place(cpu), stop_gradient=True,
            [[3.40000000],
             [8.20000000]])

            >>> nan = paddle.full(shape=[2, 3], fill_value=float("nan"))
            >>> y5 = paddle.nanquantile(nan, q=0.8, axis=1, keepdim=True)
            >>> print(y5)
            Tensor(shape=[2, 1], dtype=float64, place=Place(cpu), stop_gradient=True,
            [[nan],
             [nan]])

    Tr•   r–   r—   s       r0   Únanquantilerš   ¡  s   € ôF ˜Q ¨°gÈ$ÔOÐOr1   )NFN)NTFN)N)NFF)NF)r6   r   Úpaddle.base.libpaddler   Úpaddle.frameworkr   r   Úbase.data_feederr   r	   Úcommon_ops_importr
   Ú	frameworkr   r   Úmathr   Úsearchr   Ú__all__r    r4   rC   r:   rQ   ro   r“   r˜   rš   rD   r1   r0   Ú<module>r£      sd   ðó" Ý Ý *ß Dç CÝ (ß )Ý .Ý à
€óXóv2ój7ót"óJPófsólCóLAQôHCPr1   