o
    װi                     @   s2   d dl Z d dlZd dlmZ dd ZdddZdS )    N)specialc                 C   s2   | j |dd}| jjdkr| | } | S | | } | S )z4Normalize, preserving floating point precision of x.T)axiskeepdimsf)sumdtypekind)xr   x_sum r   T/home/ubuntu/.local/lib/python3.10/site-packages/cupyx/scipy/stats/_distributions.py
_normalize   s   r   c                 C   s   | j jdks|dur|j jdkrtd| j jdv rtjntj}| j|dd} t| |} |du r6t	
| }n|j| jkr@td|j|dd}t||}t	| |}tj||d}|durd|t| }|S )	a  Calculate the entropy of a distribution for given probability values.

    If only probabilities ``pk`` are given, the entropy is calculated as
    ``S = -sum(pk * log(pk), axis=axis)``.

    If ``qk`` is not None, then compute the Kullback-Leibler divergence
    ``S = sum(pk * log(pk / qk), axis=axis)``.

    This routine will normalize ``pk`` and ``qk`` if they don't sum to 1.

    Args:
        pk (ndarray): Defines the (discrete) distribution. ``pk[i]`` is the
            (possibly unnormalized) probability of event ``i``.
        qk (ndarray, optional): Sequence against which the relative entropy is
            computed. Should be in the same format as ``pk``.
        base (float, optional): The logarithmic base to use, defaults to ``e``
            (natural logarithm).
        axis (int, optional): The axis along which the entropy is calculated.
            Default is 0.

    Returns:
        S (cupy.ndarray): The calculated entropy.

    cNzcomplex dtype not supportedefF)copyzqk and pk must have same shape.)r   )r   r   	TypeErrorcharcupyfloat32float64astyper   r   entrshape
ValueErrorrel_entrr   mathlog)pkqkbaser   
float_typevecsr   r   r   entropy   s     

r#   )NNr   )r   r   cupyx.scipyr   r   r#   r   r   r   r   <module>   s
    
