 <p>I have resolved the issue by calculating pinv from Eigen, instead of Armadillo. </p> <p>The function definition I used for Eigen, based on this bug report: <a href="http://eigen.tuxfamily.org/bz/show_bug.cgi?id=257" rel="nofollow">http://eigen.tuxfamily.org/bz/show_bug.cgi?id=257</a></p> <p>is: </p> <pre><code>template&lt;typename _Matrix_Type_&gt; Eigen::MatrixXd pinv(const _Matrix_Type_ &amp;a, double epsilon =std::numeric_limits&lt;double&gt;::epsilon()) { Eigen::JacobiSVD&lt; _Matrix_Type_ &gt; svd(a ,Eigen::ComputeThinU | Eigen::ComputeThinV); double tolerance = epsilon * std::max(a.cols(), a.rows()) *svd.singularValues().array().abs()(0); return svd.matrixV() * (svd.singularValues().array().abs() &gt; tolerance).select(svd.singularValues().array().inverse(), 0).matrix().asDiagonal() * svd.matrixU().adjoint(); } </code></pre>