def kullback_leibler(x, y, return_sum=False):
    """Calculate the Kullback-Leibler divergence between two distributions.

    Parameters
    ----------
    x : array-like
        Discrete probability distribution.

    y : array-like
        Discrete probability distribution.

    return_sum : bool
        Return sum of kullback-leibler values.

    Returns
    -------
    kullback_leibler : float or numpy.ndarray
    """
    x, y = _check_x_y(x, y)

    if return_sum:
        return special.xlogy(x, x / y).sum()
    else:
        return special.xlogy(x, x / y)
Calculate the Kullback-Leibler divergence between two distributions.

    Parameters
    ----------
    x : array-like
        Discrete probability distribution.

    y : array-like
        Discrete probability distribution.

    return_sum : bool
        Return sum of kullback-leibler values.

    Returns
    -------
    kullback_leibler : float or numpy.ndarray
    
optbinning/binning/metrics.py