"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "include/armadillo_bits/op_sqrtmat_meat.hpp" between
armadillo-10.8.2.tar.xz and armadillo-11.0.0.tar.xz

About: Armadillo is a C++ linear algebra library (matrix maths) aiming towards a good balance between speed and ease of use.

op_sqrtmat_meat.hpp  (armadillo-10.8.2.tar.xz):op_sqrtmat_meat.hpp  (armadillo-11.0.0.tar.xz)
skipping to change at line 135 skipping to change at line 135
} }
else else
{ {
out.at(i,i) = std::sqrt( out_T(val) ); out.at(i,i) = std::sqrt( out_T(val) );
} }
} }
return true; return true;
} }
#if defined(ARMA_OPTIMISE_SYMPD) const bool try_sympd = arma_config::optimise_sympd && sympd_helper::guess_symp
const bool try_sympd = sympd_helper::guess_sympd(A); d(A);
#else
const bool try_sympd = false;
#endif
if(try_sympd) if(try_sympd)
{ {
arma_extra_debug_print("op_sqrtmat: attempting sympd optimisation"); arma_extra_debug_print("op_sqrtmat: attempting sympd optimisation");
// if matrix A is sympd, all its eigenvalues are positive // if matrix A is sympd, all its eigenvalues are positive
Col<in_T> eigval; Col<in_T> eigval;
Mat<in_T> eigvec; Mat<in_T> eigvec;
skipping to change at line 175 skipping to change at line 171
eigval = sqrt(eigval); eigval = sqrt(eigval);
out = conv_to< Mat<out_T> >::from( eigvec * diagmat(eigval) * eigvec.t() ); out = conv_to< Mat<out_T> >::from( eigvec * diagmat(eigval) * eigvec.t() );
return true; return true;
} }
} }
arma_extra_debug_print("op_sqrtmat: sympd optimisation failed"); arma_extra_debug_print("op_sqrtmat: sympd optimisation failed");
// fallthrough if eigen decomposition failed or an eigenvalue is zero // fallthrough if eigen decomposition failed or an eigenvalue is <= 0
} }
Mat<out_T> U; Mat<out_T> U;
Mat<out_T> S(A.n_rows, A.n_cols, arma_nozeros_indicator()); Mat<out_T> S(A.n_rows, A.n_cols, arma_nozeros_indicator());
const in_T* Amem = A.memptr(); const in_T* Amem = A.memptr();
out_T* Smem = S.memptr(); out_T* Smem = S.memptr();
const uword n_elem = A.n_elem; const uword n_elem = A.n_elem;
skipping to change at line 327 skipping to change at line 323
const uword N = S.n_rows; const uword N = S.n_rows;
out.zeros(N,N); // aliasing can't happen as S is generated out.zeros(N,N); // aliasing can't happen as S is generated
for(uword i=0; i<N; ++i) { out.at(i,i) = std::sqrt( S.at(i,i) ); } for(uword i=0; i<N; ++i) { out.at(i,i) = std::sqrt( S.at(i,i) ); }
return true; return true;
} }
#if defined(ARMA_OPTIMISE_SYMPD) const bool try_sympd = arma_config::optimise_sympd && sympd_helper::guess_symp
const bool try_sympd = sympd_helper::guess_sympd(S); d(S);
#else
const bool try_sympd = false;
#endif
if(try_sympd) if(try_sympd)
{ {
arma_extra_debug_print("op_sqrtmat_cx: attempting sympd optimisation"); arma_extra_debug_print("op_sqrtmat_cx: attempting sympd optimisation");
// if matrix S is sympd, all its eigenvalues are positive // if matrix S is sympd, all its eigenvalues are positive
Col< T> eigval; Col< T> eigval;
Mat<eT> eigvec; Mat<eT> eigvec;
skipping to change at line 367 skipping to change at line 359
eigval = sqrt(eigval); eigval = sqrt(eigval);
out = eigvec * diagmat(eigval) * eigvec.t(); out = eigvec * diagmat(eigval) * eigvec.t();
return true; return true;
} }
} }
arma_extra_debug_print("op_sqrtmat_cx: sympd optimisation failed"); arma_extra_debug_print("op_sqrtmat_cx: sympd optimisation failed");
// fallthrough if eigen decomposition failed or an eigenvalue is zero // fallthrough if eigen decomposition failed or an eigenvalue is <= 0
} }
const bool schur_ok = auxlib::schur(U, S); const bool schur_ok = auxlib::schur(U, S);
if(schur_ok == false) if(schur_ok == false)
{ {
arma_extra_debug_print("sqrtmat(): schur decomposition failed"); arma_extra_debug_print("sqrtmat(): schur decomposition failed");
out.soft_reset(); out.soft_reset();
return false; return false;
} }
skipping to change at line 463 skipping to change at line 455
template<typename T1> template<typename T1>
inline inline
bool bool
op_sqrtmat_sympd::apply_direct(Mat<typename T1::elem_type>& out, const Base<type name T1::elem_type,T1>& expr) op_sqrtmat_sympd::apply_direct(Mat<typename T1::elem_type>& out, const Base<type name T1::elem_type,T1>& expr)
{ {
arma_extra_debug_sigprint(); arma_extra_debug_sigprint();
#if defined(ARMA_USE_LAPACK) #if defined(ARMA_USE_LAPACK)
{ {
typedef typename T1::pod_type T;
typedef typename T1::elem_type eT; typedef typename T1::elem_type eT;
typedef typename T1::pod_type T;
const unwrap<T1> U(expr.get_ref()); const unwrap<T1> U(expr.get_ref());
const Mat<eT>& X = U.M; const Mat<eT>& X = U.M;
arma_debug_check( (X.is_square() == false), "sqrtmat_sympd(): given matrix m ust be square sized" ); arma_debug_check( (X.is_square() == false), "sqrtmat_sympd(): given matrix m ust be square sized" );
if((arma_config::debug) && (is_cx<eT>::yes) && (sympd_helper::check_diag_ima
g(X) == false))
{
arma_debug_warn_level(1, "sqrtmat_sympd(): imaginary components on the dia
gonal are non-zero");
}
if(is_op_diagmat<T1>::value || X.is_diagmat())
{
arma_extra_debug_print("op_sqrtmat_sympd: detected diagonal matrix");
out = X;
eT* colmem = out.memptr();
const uword N = X.n_rows;
for(uword i=0; i<N; ++i)
{
eT& out_ii = colmem[i];
T out_ii_real = access::tmp_real(out_ii);
if(out_ii_real < T(0)) { return false; }
out_ii = std::sqrt(out_ii);
colmem += N;
}
return true;
}
Col< T> eigval; Col< T> eigval;
Mat<eT> eigvec; Mat<eT> eigvec;
const bool status = eig_sym_helper(eigval, eigvec, X, 'd', "sqrtmat_sympd()" ); const bool status = eig_sym_helper(eigval, eigvec, X, 'd', "sqrtmat_sympd()" );
if(status == false) { return false; } if(status == false) { return false; }
const uword N = eigval.n_elem; const uword N = eigval.n_elem;
const T* eigval_mem = eigval.memptr(); const T* eigval_mem = eigval.memptr();
 End of changes. 7 change blocks. 
13 lines changed or deleted 39 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)