op_cond_meat.hpp (armadillo-10.8.2.tar.xz) | : | op_cond_meat.hpp (armadillo-11.0.0.tar.xz) | ||
---|---|---|---|---|
skipping to change at line 31 | skipping to change at line 31 | |||
template<typename T1> | template<typename T1> | |||
inline | inline | |||
typename T1::pod_type | typename T1::pod_type | |||
op_cond::cond(const Base<typename T1::elem_type, T1>& X) | op_cond::cond(const Base<typename T1::elem_type, T1>& X) | |||
{ | { | |||
arma_extra_debug_sigprint(); | arma_extra_debug_sigprint(); | |||
typedef typename T1::elem_type eT; | typedef typename T1::elem_type eT; | |||
typedef typename T1::pod_type T; | typedef typename T1::pod_type T; | |||
// TODO: implement speed up for symmetric matrices, similar to op_pinv::apply_ | ||||
sym() | ||||
Mat<eT> A(X.get_ref()); | Mat<eT> A(X.get_ref()); | |||
Col<T> S; | Col<T> S; | |||
const bool status = auxlib::svd_dc(S, A); | const bool status = auxlib::svd_dc(S, A); | |||
if(status == false) | if(status == false) | |||
{ | { | |||
arma_debug_warn_level(3, "cond(): svd failed"); | arma_debug_warn_level(3, "cond(): svd failed"); | |||
return T(0); | return Datum<T>::nan; | |||
} | } | |||
return (S.n_elem > 0) ? T( max(S) / min(S) ) : T(0); | return (S.n_elem > 0) ? T( max(S) / min(S) ) : T(0); | |||
} | } | |||
template<typename T1> | template<typename T1> | |||
inline | inline | |||
typename T1::pod_type | typename T1::pod_type | |||
op_cond::rcond(const Base<typename T1::elem_type, T1>& X) | op_cond::rcond(const Base<typename T1::elem_type, T1>& X) | |||
{ | { | |||
skipping to change at line 76 | skipping to change at line 78 | |||
return auxlib::rcond_trimat(U.M, layout); | return auxlib::rcond_trimat(U.M, layout); | |||
} | } | |||
Mat<eT> A = X.get_ref(); | Mat<eT> A = X.get_ref(); | |||
arma_debug_check( (A.is_square() == false), "rcond(): matrix must be square si zed" ); | arma_debug_check( (A.is_square() == false), "rcond(): matrix must be square si zed" ); | |||
if(A.is_empty()) { return Datum<T>::inf; } | if(A.is_empty()) { return Datum<T>::inf; } | |||
if(is_op_diagmat<T1>::value || A.is_diagmat()) | ||||
{ | ||||
arma_extra_debug_print("op_cond::rcond(): detected diagonal matrix"); | ||||
const eT* colmem = A.memptr(); | ||||
const uword N = A.n_rows; | ||||
T max_abs_src_val = T(0); | ||||
T max_abs_inv_val = T(0); | ||||
for(uword i=0; i<N; ++i) | ||||
{ | ||||
const eT src_val = colmem[i]; | ||||
const eT inv_val = eT(1) / src_val; | ||||
if(src_val == eT(0)) { return T(0); } | ||||
const T abs_src_val = std::abs(src_val); | ||||
const T abs_inv_val = std::abs(inv_val); | ||||
max_abs_src_val = (abs_src_val > max_abs_src_val) ? abs_src_val : max_abs_ | ||||
src_val; | ||||
max_abs_inv_val = (abs_inv_val > max_abs_inv_val) ? abs_inv_val : max_abs_ | ||||
inv_val; | ||||
colmem += N; | ||||
} | ||||
return T(1) / (max_abs_src_val * max_abs_inv_val); | ||||
} | ||||
const bool is_triu = trimat_helper::is_triu(A); | const bool is_triu = trimat_helper::is_triu(A); | |||
const bool is_tril = (is_triu) ? false : trimat_helper::is_tril(A); | const bool is_tril = (is_triu) ? false : trimat_helper::is_tril(A); | |||
if(is_triu || is_tril) | if(is_triu || is_tril) | |||
{ | { | |||
const uword layout = (is_triu) ? uword(0) : uword(1); | const uword layout = (is_triu) ? uword(0) : uword(1); | |||
return auxlib::rcond_trimat(A, layout); | return auxlib::rcond_trimat(A, layout); | |||
} | } | |||
#if defined(ARMA_OPTIMISE_SYMPD) | const bool try_sympd = arma_config::optimise_sympd && (auxlib::crippled_lapack | |||
const bool try_sympd = auxlib::crippled_lapack(A) ? false : sympd_helper::gu | (A) ? false : sympd_helper::guess_sympd(A)); | |||
ess_sympd(A); | ||||
#else | ||||
const bool try_sympd = false; | ||||
#endif | ||||
if(try_sympd) | if(try_sympd) | |||
{ | { | |||
arma_extra_debug_print("op_cond::rcond(): attempting sympd optimisation"); | arma_extra_debug_print("op_cond::rcond(): attempting sympd optimisation"); | |||
bool calc_ok = false; | bool calc_ok = false; | |||
const T out_val = auxlib::rcond_sympd(A, calc_ok); | const T out_val = auxlib::rcond_sympd(A, calc_ok); | |||
if(calc_ok) { return out_val; } | if(calc_ok) { return out_val; } | |||
End of changes. 4 change blocks. | ||||
7 lines changed or deleted | 37 lines changed or added |