From ee40a879d763bd5d1b2c1a1faf7c8ebf90ccd0b4 Mon Sep 17 00:00:00 2001 From: conrad Date: Thu, 9 Dec 2021 22:12:28 +1000 Subject: [PATCH] further simplifications --- include/armadillo_bits/op_pinv_meat.hpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/include/armadillo_bits/op_pinv_meat.hpp b/include/armadillo_bits/op_pinv_meat.hpp index 359c1804..2be96ed8 100644 --- a/include/armadillo_bits/op_pinv_meat.hpp +++ b/include/armadillo_bits/op_pinv_meat.hpp @@ -184,9 +184,7 @@ op_pinv::apply_direct(Mat& out, const Base eigvec_use(eigvec.memptr(), eigvec.n_rows, count, false); - const Mat tmp = eigvec_use * diagmat(eigval2); - - out = tmp * eigvec_use.t(); + out = (eigvec_use * diagmat(eigval2)).eval() * eigvec_use.t(); return true; } @@ -222,26 +220,26 @@ op_pinv::apply_direct(Mat& out, const Base= tol) { s2[count2] = (val > T(0)) ? T(T(1) / val) : T(0); ++count2; } } - const Mat Vuse(V.memptr(), V.n_rows, count, false); - const Mat Uuse(U.memptr(), U.n_rows, count, false); - + const Mat U_use(U.memptr(), U.n_rows, count, false); + const Mat V_use(V.memptr(), V.n_rows, count, false); + Mat tmp; - + if(n_rows >= n_cols) { // out = ( (V.n_cols > count) ? V.cols(0,count-1) : V ) * diagmat(s2) * trans( (U.n_cols > count) ? U.cols(0,count-1) : U ); - tmp = Vuse * diagmat(s2); + tmp = V_use * diagmat(s2); - out = tmp * trans(Uuse); + out = tmp * trans(U_use); } else { // out = ( (U.n_cols > count) ? U.cols(0,count-1) : U ) * diagmat(s2) * trans( (V.n_cols > count) ? V.cols(0,count-1) : V ); - tmp = Uuse * diagmat(s2); + tmp = U_use * diagmat(s2); - out = tmp * trans(Vuse); + out = tmp * trans(V_use); } return true;