import torch


def solve_quadratic(coefficients):
    """Solves quadratics across batches, returns only maximum root

    :param coefficients: 3-tuple of torch.tensors (a, b, c)
        Each of (a, b, c) should be of length batch_size and all on the same device. (a, b, c) corresponds to the usual
        quadratic coefficients

    :return: torch.tensor of length batch_size
    """
    a, b, c = coefficients
    sol1 = (- b + torch.sqrt(b * b - 4 * a * c)) / (2 * a)
    sol2 = (- b - torch.sqrt(b * b - 4 * a * c)) / (2 * a)
    return torch.maximum(sol1, sol2)