import torch

def Jtest(X, p):
    X = X.to(torch.float64).to('cpu')
    d = X.shape[-1]
    J = torch.eye(d).to(torch.float64)
    J[p:, p:] = -1 * torch.eye(d - p)
    temp = torch.mm(X.T, torch.mm(J, X))-J
    Jerr = torch.mean(torch.abs(temp))
    return Jerr
