diff --git a/include/armadillo_bits/auxlib_bones.hpp b/include/armadillo_bits/auxlib_bones.hpp index 81e73ead..3105bf94 100644 --- a/include/armadillo_bits/auxlib_bones.hpp +++ b/include/armadillo_bits/auxlib_bones.hpp @@ -225,11 +225,11 @@ class auxlib inline static bool svd(Col& S, Mat< std::complex >& A); - template - inline static bool svd(Mat& U, Col& S, Mat& V, const Base& X); + template + inline static bool svd(Mat& U, Col& S, Mat& V, Mat& A); - template - inline static bool svd(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X); + template + inline static bool svd(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, Mat< std::complex >& A); template inline static bool svd_econ(Mat& U, Col& S, Mat& V, Mat& A, const char mode); @@ -245,11 +245,11 @@ class auxlib inline static bool svd_dc(Col& S, Mat< std::complex >& A); - template - inline static bool svd_dc(Mat& U, Col& S, Mat& V, const Base& X); + template + inline static bool svd_dc(Mat& U, Col& S, Mat& V, Mat& A); - template - inline static bool svd_dc(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X); + template + inline static bool svd_dc(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, Mat< std::complex >& A); template inline static bool svd_dc_econ(Mat& U, Col& S, Mat& V, Mat& A); diff --git a/include/armadillo_bits/auxlib_meat.hpp b/include/armadillo_bits/auxlib_meat.hpp index e77efde7..d093ee37 100644 --- a/include/armadillo_bits/auxlib_meat.hpp +++ b/include/armadillo_bits/auxlib_meat.hpp @@ -3430,17 +3430,15 @@ auxlib::svd(Col& S, Mat< std::complex >& A) -template +template inline bool -auxlib::svd(Mat& U, Col& S, Mat& V, const Base& X) +auxlib::svd(Mat& U, Col& S, Mat& V, Mat& A) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { - Mat A(X.get_ref()); - if(A.is_empty()) { U.eye(A.n_rows, A.n_rows); @@ -3502,7 +3500,7 @@ auxlib::svd(Mat& U, Col& S, Mat& V, const Base& X) arma_ignore(U); arma_ignore(S); arma_ignore(V); - arma_ignore(X); + arma_ignore(A); arma_stop_logic_error("svd(): use of LAPACK must be enabled"); return false; } @@ -3511,10 +3509,10 @@ auxlib::svd(Mat& U, Col& S, Mat& V, const Base& X) -template +template inline bool -auxlib::svd(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X) +auxlib::svd(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, Mat< std::complex >& A) { arma_extra_debug_sigprint(); @@ -3522,8 +3520,6 @@ auxlib::svd(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, con { typedef std::complex eT; - Mat A(X.get_ref()); - if(A.is_empty()) { U.eye(A.n_rows, A.n_rows); @@ -3586,7 +3582,7 @@ auxlib::svd(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, con arma_ignore(U); arma_ignore(S); arma_ignore(V); - arma_ignore(X); + arma_ignore(A); arma_stop_logic_error("svd(): use of LAPACK must be enabled"); return false; } @@ -3967,17 +3963,15 @@ auxlib::svd_dc(Col& S, Mat< std::complex >& A) -template +template inline bool -auxlib::svd_dc(Mat& U, Col& S, Mat& V, const Base& X) +auxlib::svd_dc(Mat& U, Col& S, Mat& V, Mat& A) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { - Mat A(X.get_ref()); - if(A.is_empty()) { U.eye(A.n_rows, A.n_rows); @@ -4042,7 +4036,7 @@ auxlib::svd_dc(Mat& U, Col& S, Mat& V, const Base& X) arma_ignore(U); arma_ignore(S); arma_ignore(V); - arma_ignore(X); + arma_ignore(A); arma_stop_logic_error("svd(): use of LAPACK must be enabled"); return false; } @@ -4051,10 +4045,10 @@ auxlib::svd_dc(Mat& U, Col& S, Mat& V, const Base& X) -template +template inline bool -auxlib::svd_dc(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X) +auxlib::svd_dc(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, Mat< std::complex >& A) { arma_extra_debug_sigprint(); @@ -4062,8 +4056,6 @@ auxlib::svd_dc(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, { typedef std::complex eT; - Mat A(X.get_ref()); - if(A.is_empty()) { U.eye(A.n_rows, A.n_rows); @@ -4128,7 +4120,7 @@ auxlib::svd_dc(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, arma_ignore(U); arma_ignore(S); arma_ignore(V); - arma_ignore(X); + arma_ignore(A); arma_stop_logic_error("svd(): use of LAPACK must be enabled"); return false; } diff --git a/include/armadillo_bits/fn_svd.hpp b/include/armadillo_bits/fn_svd.hpp index ebfba107..d623cc10 100644 --- a/include/armadillo_bits/fn_svd.hpp +++ b/include/armadillo_bits/fn_svd.hpp @@ -98,6 +98,8 @@ svd arma_extra_debug_sigprint(); arma_ignore(junk); + typedef typename T1::elem_type eT; + arma_debug_check ( ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)(&V)) ), @@ -108,8 +110,9 @@ svd arma_debug_check( ((sig != 's') && (sig != 'd')), "svd(): unknown method specified" ); - // auxlib::svd() makes an internal copy of X - const bool status = (sig == 'd') ? auxlib::svd_dc(U, S, V, X) : auxlib::svd(U, S, V, X); + Mat A(X.get_ref()); + + const bool status = (sig == 'd') ? auxlib::svd_dc(U, S, V, A) : auxlib::svd(U, S, V, A); if(status == false) {