import torch


def Jacvec(y, x, v):
    """Computes a Jacobian vector product - J v

    Arguments:
    y (torch.tensor): output of differentiated function
    x (torch.tensor): differentiated input
    v (torch.tensor): vector to be multiplied with Jacobian from the left
    """
    return torch.autograd.grad(y, x, v, retain_graph=True)