diff --git a/cpp/Matrix.cpp b/cpp/Matrix.cpp index 8704fba55..e6b2ddbb2 100644 --- a/cpp/Matrix.cpp +++ b/cpp/Matrix.cpp @@ -569,6 +569,23 @@ void svd(const Matrix& A, Matrix& U, Vector& s, Matrix& V) { svd(U,s,V); // call in-place version } +/* ************************************************************************* */ +// TODO, would be faster with Cholesky +Matrix inverse_square_root(const Matrix& A) { + size_t m = A.size2(), n = A.size1(); + if (m!=n) + throw invalid_argument("inverse_square_root: A must be square"); + + // Perform SVD, TODO: symmetric SVD? + Matrix U,V; + Vector S; + svd(A,U,S,V); + + // invert and sqrt diagonal of S + for(size_t i = 0; i