def differential(f, A, E):
    """Computes the differential of f at A when acting on E: (df)_A(E)."""
    n = A.size(0)
    M = torch.zeros(2*n, 2*n, dtype=A.dtype, device=A.device, requires_grad=False)
    M[:n, :n] = A
    M[n:, n:] = A
    M[:n, n:] = E
    return f(M)[:n, n:]
Computes the differential of f at A when acting on E: (df)_A(E).
analyze/convnexts4nd/src/models/nn/exprnn/expm32.py