def hinge_loss(x, y, w):
    """ Calculate hinge loss.
    Params:
        x(csr_matrix): feature vector
        y(int): label
        w(csr_matrix): weight vector
    Returns:
        hinge(float): hinge loss
    """
    # hinge = max(0.0, 1.0 - y * w^{T}x)
    return max(0.0, 1.0 - y * w.multiply(x).sum())