max@0: // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-2011 Conrad Sanderson max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup fn_misc max@0: //! @{ max@0: max@0: max@0: max@0: //! \brief max@0: //! Generate a vector with 'num' elements. max@0: //! The values of the elements linearly increase from 'start' upto (and including) 'end'. max@0: max@0: template max@0: inline max@0: vec_type max@0: linspace max@0: ( max@0: const typename vec_type::pod_type start, max@0: const typename vec_type::pod_type end, max@0: const uword num = 100u, max@0: const typename arma_Mat_Col_Row_only::result* junk = 0 max@0: ) max@0: { max@0: arma_extra_debug_sigprint(); max@0: arma_ignore(junk); max@0: max@0: typedef typename vec_type::elem_type eT; max@0: typedef typename vec_type::pod_type T; max@0: max@0: vec_type x; max@0: max@0: if(num >= 2) max@0: { max@0: x.set_size(num); max@0: max@0: eT* x_mem = x.memptr(); max@0: max@0: const uword num_m1 = num - 1; max@0: max@0: if(is_non_integral::value == true) max@0: { max@0: const T delta = (end-start)/T(num_m1); max@0: max@0: for(uword i=0; i= start) ? double(end-start)/double(num_m1) : -double(start-end)/double(num_m1); max@0: max@0: for(uword i=0; i(start, end, num); max@0: } max@0: max@0: max@0: max@0: // max@0: // log_add max@0: max@0: template max@0: inline max@0: typename arma_float_only::result max@0: log_add(eT log_a, eT log_b) max@0: { max@0: if(log_a < log_b) max@0: { max@0: std::swap(log_a, log_b); max@0: } max@0: max@0: const eT negdelta = log_b - log_a; max@0: max@0: if( (negdelta < Math::log_min()) || (arma_isfinite(negdelta) == false) ) max@0: { max@0: return log_a; max@0: } max@0: else max@0: { max@0: #if defined(ARMA_HAVE_LOG1P) max@0: return (log_a + log1p(std::exp(negdelta))); max@0: #else max@0: return (log_a + std::log(1.0 + std::exp(negdelta))); max@0: #endif max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: arma_warn_unused max@0: bool max@0: is_finite(const eT x, const typename arma_scalar_only::result* junk = 0) max@0: { max@0: arma_ignore(junk); max@0: max@0: return arma_isfinite(x); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: bool max@0: is_finite(const Base& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const unwrap tmp(X.get_ref()); max@0: const Mat& A = tmp.M; max@0: max@0: return A.is_finite(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: arma_warn_unused max@0: bool max@0: is_finite(const BaseCube& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const unwrap_cube tmp(X.get_ref()); max@0: const Cube& A = tmp.M; max@0: max@0: return A.is_finite(); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: Op max@0: sympd(const Base& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return Op(X.get_ref()); max@0: } max@0: max@0: max@0: max@0: //! @}