Matrix_factorization in cpp