rework eig_sym()

This commit is contained in:
conrad
2021-11-30 09:48:11 +10:00
parent cbdec3e63e
commit 28f79c0220
3 changed files with 25 additions and 31 deletions
+4 -4
View File
@@ -139,11 +139,11 @@ class auxlib
//
// eig_sym
template<typename eT, typename T1>
inline static bool eig_sym(Col<eT>& eigval, const Base<eT,T1>& X);
template<typename eT>
inline static bool eig_sym(Col<eT>& eigval, Mat<eT>& A);
template<typename T, typename T1>
inline static bool eig_sym(Col<T>& eigval, const Base<std::complex<T>,T1>& X);
template<typename T>
inline static bool eig_sym(Col<T>& eigval, Mat< std::complex<T> >& A);
template<typename eT>
inline static bool eig_sym(Col<eT>& eigval, Mat<eT>& eigvec, const Mat<eT>& X);
+8 -20
View File
@@ -2066,24 +2066,18 @@ auxlib::eig_pair_twosided
//! eigenvalues of a symmetric real matrix
template<typename eT, typename T1>
template<typename eT>
inline
bool
auxlib::eig_sym(Col<eT>& eigval, const Base<eT,T1>& X)
auxlib::eig_sym(Col<eT>& eigval, Mat<eT>& A)
{
arma_extra_debug_sigprint();
#if defined(ARMA_USE_LAPACK)
{
Mat<eT> A(X.get_ref());
arma_debug_check( (A.is_square() == false), "eig_sym(): given matrix must be square sized" );
if(A.is_empty())
{
eigval.reset();
return true;
}
if(A.is_empty()) { eigval.reset(); return true; }
// if(auxlib::rudimentary_sym_check(A) == false)
// {
@@ -2117,7 +2111,7 @@ auxlib::eig_sym(Col<eT>& eigval, const Base<eT,T1>& X)
#else
{
arma_ignore(eigval);
arma_ignore(X);
arma_ignore(A);
arma_stop_logic_error("eig_sym(): use of LAPACK must be enabled");
return false;
}
@@ -2127,10 +2121,10 @@ auxlib::eig_sym(Col<eT>& eigval, const Base<eT,T1>& X)
//! eigenvalues of a hermitian complex matrix
template<typename T, typename T1>
template<typename T>
inline
bool
auxlib::eig_sym(Col<T>& eigval, const Base<std::complex<T>,T1>& X)
auxlib::eig_sym(Col<T>& eigval, Mat< std::complex<T> >& A)
{
arma_extra_debug_sigprint();
@@ -2138,15 +2132,9 @@ auxlib::eig_sym(Col<T>& eigval, const Base<std::complex<T>,T1>& X)
{
typedef typename std::complex<T> eT;
Mat<eT> A(X.get_ref());
arma_debug_check( (A.is_square() == false), "eig_sym(): given matrix must be square sized" );
if(A.is_empty())
{
eigval.reset();
return true;
}
if(A.is_empty()) { eigval.reset(); return true; }
// if(auxlib::rudimentary_sym_check(A) == false)
// {
@@ -2181,7 +2169,7 @@ auxlib::eig_sym(Col<T>& eigval, const Base<std::complex<T>,T1>& X)
#else
{
arma_ignore(eigval);
arma_ignore(X);
arma_ignore(A);
arma_stop_logic_error("eig_sym(): use of LAPACK must be enabled");
return false;
}
+13 -7
View File
@@ -32,10 +32,11 @@ eig_sym
{
arma_extra_debug_sigprint();
// unwrap_check not used as T1::elem_type and T1::pod_type may not be the same.
// furthermore, it doesn't matter if X is an alias of eigval, as auxlib::eig_sym() makes a copy of X
typedef typename T1::elem_type eT;
const bool status = auxlib::eig_sym(eigval, X);
Mat<eT> A(X.get_ref());
const bool status = auxlib::eig_sym(eigval, A);
if(status == false)
{
@@ -60,16 +61,21 @@ eig_sym
{
arma_extra_debug_sigprint();
Col<typename T1::pod_type> out;
const bool status = auxlib::eig_sym(out, X);
typedef typename T1::elem_type eT;
typedef typename T1::pod_type T;
Col< T> eigval;
Mat<eT> A(X.get_ref());
const bool status = auxlib::eig_sym(eigval, A);
if(status == false)
{
out.soft_reset();
eigval.reset();
arma_stop_runtime_error("eig_sym(): decomposition failed");
}
return out;
return eigval;
}