// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_misc //! @{ //! \brief //! Generate a vector with 'num' elements. //! The values of the elements linearly increase from 'start' upto (and including) 'end'. template inline typename enable_if2 < is_Mat::value, vec_type >::result linspace ( const typename vec_type::pod_type start, const typename vec_type::pod_type end, const uword num = 100u ) { arma_extra_debug_sigprint(); typedef typename vec_type::elem_type eT; typedef typename vec_type::pod_type T; vec_type x; if(num >= 2) { x.set_size(num); eT* x_mem = x.memptr(); const uword num_m1 = num - 1; if(is_non_integral::value == true) { const T delta = (end-start)/T(num_m1); for(uword i=0; i= start) ? double(end-start)/double(num_m1) : -double(start-end)/double(num_m1); for(uword i=0; i(start, end, num); } // // log_exp_add template inline typename arma_real_only::result log_add_exp(eT log_a, eT log_b) { if(log_a < log_b) { std::swap(log_a, log_b); } const eT negdelta = log_b - log_a; if( (negdelta < Datum::log_min) || (arma_isfinite(negdelta) == false) ) { return log_a; } else { return (log_a + arma_log1p(std::exp(negdelta))); } } // for compatibility with earlier versions template inline typename arma_real_only::result log_add(eT log_a, eT log_b) { return log_add_exp(log_a, log_b); } template arma_inline arma_warn_unused bool is_finite(const eT x, const typename arma_scalar_only::result* junk = 0) { arma_ignore(junk); return arma_isfinite(x); } template inline arma_warn_unused typename enable_if2 < is_arma_type::value, bool >::result is_finite(const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X); const bool have_direct_mem = (is_Mat::stored_type>::value) || (is_subview_col::stored_type>::value); if(have_direct_mem) { const quasi_unwrap::stored_type> tmp(P.Q); return tmp.M.is_finite(); } if(Proxy::prefer_at_accessor == false) { const typename Proxy::ea_type Pea = P.get_ea(); const uword n_elem = P.get_n_elem(); uword i,j; for(i=0, j=1; j inline arma_warn_unused bool is_finite(const SpBase& X) { arma_extra_debug_sigprint(); const SpProxy P(X.get_ref()); if(is_SpMat::stored_type>::value) { const unwrap_spmat::stored_type> tmp(P.Q); return tmp.M.is_finite(); } else { typename SpProxy::const_iterator_type it = P.begin(); typename SpProxy::const_iterator_type it_end = P.end(); while(it != it_end) { if(arma_isfinite(*it) == false) { return false; } ++it; } } return true; } template inline arma_warn_unused bool is_finite(const BaseCube& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube tmp(X.get_ref()); const Cube& A = tmp.M; return A.is_finite(); } //! DO NOT USE IN NEW CODE; change instances of inv(sympd(X)) to inv_sympd(X) template arma_deprecated inline const T1& sympd(const Base& X) { arma_extra_debug_sigprint(); return X.get_ref(); } template inline void swap(Mat& A, Mat& B) { arma_extra_debug_sigprint(); A.swap(B); } template inline void swap(Cube& A, Cube& B) { arma_extra_debug_sigprint(); A.swap(B); } template arma_inline const Op orth(const Base& X, const typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; return Op(X.get_ref(), eT(tol)); } template inline bool orth(Mat& out, const Base& X, const typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); try { out = orth(X,tol); } catch (std::runtime_error&) { return false; } return true; } template arma_inline const Op null(const Base& X, const typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; return Op(X.get_ref(), eT(tol)); } template inline bool null(Mat& out, const Base& X, const typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); try { out = null(X,tol); } catch (std::runtime_error&) { return false; } return true; } inline uvec ind2sub(const SizeMat& s, const uword i) { arma_extra_debug_sigprint(); arma_debug_check( (i >= (s.n_rows * s.n_cols) ), "ind2sub(): index out of range" ); uvec out(2); out[0] = i % s.n_rows; out[1] = i / s.n_rows; return out; } inline uvec ind2sub(const SizeCube& s, const uword i) { arma_extra_debug_sigprint(); arma_debug_check( (i >= (s.n_rows * s.n_cols * s.n_slices) ), "ind2sub(): index out of range" ); const uword n_elem_slice = s.n_rows * s.n_cols; const uword slice = i / n_elem_slice; const uword j = i - (slice * n_elem_slice); const uword row = j % s.n_rows; const uword col = j / s.n_rows; uvec out(3); out[0] = row; out[1] = col; out[2] = slice; return out; } arma_inline uword sub2ind(const SizeMat& s, const uword row, const uword col) { arma_extra_debug_sigprint(); arma_debug_check( ((row >= s.n_rows) || (col >= s.n_cols)), "sub2ind(): subscript out of range" ); return uword(row + col*s.n_rows); } arma_inline uword sub2ind(const SizeCube& s, const uword row, const uword col, const uword slice) { arma_extra_debug_sigprint(); arma_debug_check( ((row >= s.n_rows) || (col >= s.n_cols) || (slice >= s.n_slices)), "sub2ind(): subscript out of range" ); return uword( (slice * s.n_rows * s.n_cols) + (col * s.n_rows) + row ); } //! @}