Just code it directly. Assuming a batch of N outputs
x = output
y = target

vx = x - torch.mean(x)
vy = y - torch.mean(y)

cost = torch.sum(vx * vy) / (torch.sqrt(torch.sum(vx ** 2)) * torch.sqrt(torch.sum(vy ** 2)))

or you could probably use
cost = vx * vy * torch.rsqrt(torch.sum(vx ** 2)) * torch.rsqrt(torch.sum(vy ** 2)))
Where the rsqrt() function is just the reciprocal of the square root.