Large reconstruction error in torch.svd() compared to svd() function in MATLAB


As seen in the above two images, I’m getting different(extremely) reconstruction errors while using the torch.svd() and svd() function from MATLAB. What might be the reason? Is it solely because of the ways in which SVD is computed are different? Or, are there any factors in play here?
Is there any method by which I can reduce the error while using torch.svd() ?

Thanks in advance

1 Like

MATLAB uses double precision by default, so you could also apply the same in PyTorch:

W = torch.randn(1000, 1000, dtype=torch.float64)
U, S, V = torch.svd(W)
error = torch.norm(W - U@torch.diag(S)@V.t())
> tensor(3.3153e-12, dtype=torch.float64)
1 Like

I completely overlooked this difference.
Really appreciate your help. Thanks! :+1:t5: