inline bool qr_econ ( Mat<typename T1::elem_type>& Q, Mat<typename T1::elem_type>& R, const Base<typename T1::elem_type,T1>& X, const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( (&Q == &R), "qr_econ(): Q and R are the same object"); const bool status = auxlib::qr_econ(Q, R, X); if(status == false) { Q.soft_reset(); R.soft_reset(); arma_debug_warn("qr_econ(): decomposition failed"); } return status; }
arma_warn_unused inline Mat<typename T1::elem_type> hess ( const Base<typename T1::elem_type,T1>& X, const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; Mat<eT> H; Col<eT> tao; const bool status = auxlib::hess(H, X.get_ref(), tao); if(H.n_rows > 2) { for(uword i=0; i < H.n_rows-2; ++i) { H(span(i+2, H.n_rows-1), i).zeros(); } } if(status == false) { H.soft_reset(); arma_stop_runtime_error("hess(): decomposition failed"); } return H; }
inline void op_inv::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_inv>& X) { arma_extra_debug_sigprint(); const strip_diagmat<T1> strip(X.m); bool status; if(strip.do_diagmat == true) { status = op_inv::apply_diagmat(out, strip.M); } else { status = auxlib::inv(out, X.m); } if(status == false) { out.soft_reset(); arma_stop_runtime_error("inv(): matrix seems singular"); } }
inline bool syl ( Mat <typename T1::elem_type> & out, const Base<typename T1::elem_type,T1>& in_A, const Base<typename T1::elem_type,T2>& in_B, const Base<typename T1::elem_type,T3>& in_C, const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap_check<T1> tmp_A(in_A.get_ref(), out); const unwrap_check<T2> tmp_B(in_B.get_ref(), out); const unwrap_check<T3> tmp_C(in_C.get_ref(), out); const Mat<eT>& A = tmp_A.M; const Mat<eT>& B = tmp_B.M; const Mat<eT>& C = tmp_C.M; const bool status = auxlib::syl(out, A, B, C); if(status == false) { out.soft_reset(); arma_debug_warn("syl(): solution not found"); } return status; }
inline void op_inv_sympd::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_inv_sympd>& X) { arma_extra_debug_sigprint(); const bool status = auxlib::inv_sympd(out, X.m); if(status == false) { out.soft_reset(); arma_stop_runtime_error("inv_sympd(): matrix is singular or not positive definite"); } }
inline void op_inv_tr::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_inv_tr>& X) { arma_extra_debug_sigprint(); const bool status = auxlib::inv_tr(out, X.m, X.aux_uword_a); if(status == false) { out.soft_reset(); arma_stop_runtime_error("inv(): matrix seems singular"); } }
inline void op_logmat_sympd::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_logmat_sympd>& in) { arma_extra_debug_sigprint(); const bool status = op_logmat_sympd::apply_direct(out, in.m); if(status == false) { out.soft_reset(); arma_stop_runtime_error("logmat_sympd(): transformation failed"); } }
inline void op_logmat::apply(Mat< std::complex<typename T1::elem_type> >& out, const mtOp<std::complex<typename T1::elem_type>,T1,op_logmat>& in) { arma_extra_debug_sigprint(); const bool status = op_logmat::apply_direct(out, in.m, in.aux_uword_a); if(status == false) { out.soft_reset(); arma_stop_runtime_error("logmat(): transformation failed"); } }
inline void op_chol::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_chol>& X) { arma_extra_debug_sigprint(); const bool status = op_chol::apply_direct(out, X.m, X.aux_uword_a); if(status == false) { out.soft_reset(); arma_stop_runtime_error("chol(): decomposition failed"); } }
inline void op_inv::apply(Mat<eT>& out, const Mat<eT>& A) { arma_extra_debug_sigprint(); // no need to check for aliasing, due to: // - auxlib::inv() copies A to out before inversion // - for 2x2 and 3x3 matrices the code is alias safe bool status = auxlib::inv(out, A); if(status == false) { out.soft_reset(); arma_stop_runtime_error("inv(): matrix seems singular"); } }
arma_warn_unused inline Mat<typename T1::elem_type> syl ( const Base<typename T1::elem_type,T1>& in_A, const Base<typename T1::elem_type,T2>& in_B, const Base<typename T1::elem_type,T3>& in_C, const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap<T1> tmp_A( in_A.get_ref() ); const unwrap<T2> tmp_B( in_B.get_ref() ); const unwrap<T3> tmp_C( in_C.get_ref() ); const Mat<eT>& A = tmp_A.M; const Mat<eT>& B = tmp_B.M; const Mat<eT>& C = tmp_C.M; Mat<eT> out; const bool status = auxlib::syl(out, A, B, C); if(status == false) { out.soft_reset(); arma_stop_runtime_error("syl(): solution not found"); } return out; }
inline bool hess ( Mat<typename T1::elem_type>& U, Mat<typename T1::elem_type>& H, const Base<typename T1::elem_type,T1>& X, const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( void_ptr(&U) == void_ptr(&H), "hess(): 'U' is an alias of 'H'" ); typedef typename T1::elem_type eT; Col<eT> tao; const bool status = auxlib::hess(H, X.get_ref(), tao); if(H.n_rows == 0) { U.reset(); } else if(H.n_rows == 1) { U.ones(1, 1); } else if(H.n_rows == 2) { U.eye(2, 2); } else { U.eye(size(H)); Col<eT> v; for(uword i=0; i < H.n_rows-2; ++i) { // TODO: generate v in a more efficient manner; // TODO: the .ones() operation is an overkill, as most of v is overwritten afterwards v.ones(H.n_rows-i-1); v(span(1, H.n_rows-i-2)) = H(span(i+2, H.n_rows-1), i); U(span::all, span(i+1, H.n_rows-1)) -= tao(i) * (U(span::all, span(i+1, H.n_rows-1)) * v * v.t()); } U(span::all, H.n_rows-1) = U(span::all, H.n_rows-1) * (eT(1) - tao(H.n_rows-2)); for(uword i=0; i < H.n_rows-2; ++i) { H(span(i+2, H.n_rows-1), i).zeros(); } } if(status == false) { U.soft_reset(); H.soft_reset(); arma_debug_warn("hess(): decomposition failed"); } return status; }
inline bool op_pinv::apply_direct(Mat<typename T1::elem_type>& out, const Base<typename T1::elem_type,T1>& expr, typename T1::pod_type tol, const bool use_divide_and_conquer) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; arma_debug_check((tol < T(0)), "pinv(): tolerance must be >= 0"); const Proxy<T1> P(expr.get_ref()); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if( (n_rows*n_cols) == 0 ) { out.set_size(n_cols,n_rows); return true; } // economical SVD decomposition Mat<eT> U; Col< T> s; Mat<eT> V; bool status = false; if(use_divide_and_conquer) { status = (n_cols > n_rows) ? auxlib::svd_dc_econ(U, s, V, trans(P.Q)) : auxlib::svd_dc_econ(U, s, V, P.Q); } else { status = (n_cols > n_rows) ? auxlib::svd_econ(U, s, V, trans(P.Q), 'b') : auxlib::svd_econ(U, s, V, P.Q, 'b'); } if(status == false) { out.soft_reset(); return false; } const uword s_n_elem = s.n_elem; const T* s_mem = s.memptr(); // set tolerance to default if it hasn't been specified if( (tol == T(0)) && (s_n_elem > 0) ) { tol = (std::max)(n_rows, n_cols) * s_mem[0] * std::numeric_limits<T>::epsilon(); } uword count = 0; for(uword i = 0; i < s_n_elem; ++i) { count += (s_mem[i] >= tol) ? uword(1) : uword(0); } if(count > 0) { Col<T> s2(count); T* s2_mem = s2.memptr(); uword count2 = 0; for(uword i=0; i < s_n_elem; ++i) { const T val = s_mem[i]; if(val >= tol) { s2_mem[count2] = T(1) / val; ++count2; } } 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 ); } 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 ); } } else { out.zeros(n_cols, n_rows); } return true; }