import torch


def _compute_binary_accuracy(pred_y, true_y):
    """Computes the accuracy of a classifier.

    Arguments:
        pred_y: A one dimensional tensor of floats (a sigmoid will be applied to determine the classification result).
        true_y: A one dimensional tensor of floats; 1.0 corresponds to one class, 0.0 corresponds to the other.

    Returns:
        A single float describing the accuracy.
    """
    assert pred_y.shape == true_y.shape, "Shape mismatch: pred_y has shape {}, true_y has shape {}".format(pred_y.shape,
                                                                                                           true_y.shape)

    binary_prediction = (torch.sigmoid(pred_y) > 0.5).to(true_y.dtype)
    prediction_matches = (binary_prediction == true_y).to(true_y.dtype)
    proportion_correct = prediction_matches.sum() / true_y.size(0)
    return proportion_correct