This is not the best way in R: https://git.uibk.ac.at/c4031039/mvnchol/-/blob/master/R/dist_modchol.R#L145