The problem is that a few of the values on the diagonal are negative due to floating precision error, which is why I set them to zero before doing the sqrt operation.
But I guess I could do another masking and set all those to zero again afterwards if you think that will help with stability?