def gini_node(n_classes, w_samples, y_sum):
    """Computes the gini impurity criterion in a node.

    Parameters
    ----------
    n_classes : int
        Number of label classes

    w_samples : float
        Weighted number of samples in the node

    y_sum : ndarray
        Array of shape (n_classes,) and float dtype containing the weighted number of
        samples in each label class

    Returns
    -------
    output : float
        Gini impurity criterion in the node
    """
    y_sum_sq = 0.0
    w_samples_sq = w_samples * w_samples
    for k in range(n_classes):
        y_sum_sq += y_sum[k] * y_sum[k]
    return 1.0 - y_sum_sq / w_samples_sq