fn_misc.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
00002 // Copyright (C) 2008-2011 Conrad Sanderson
00003 // 
00004 // This file is part of the Armadillo C++ library.
00005 // It is provided without any warranty of fitness
00006 // for any purpose. You can redistribute this file
00007 // and/or modify it under the terms of the GNU
00008 // Lesser General Public License (LGPL) as published
00009 // by the Free Software Foundation, either version 3
00010 // of the License or (at your option) any later version.
00011 // (see http://www.opensource.org/licenses for more info)
00012 
00013 
00016 
00017 
00018 
00022 
00023 template<typename vec_type>
00024 inline
00025 vec_type
00026 linspace
00027   (
00028   const typename vec_type::pod_type start,
00029   const typename vec_type::pod_type end,
00030   const uword num = 100u,
00031   const typename arma_Mat_Col_Row_only<vec_type>::result* junk = 0
00032   )
00033   {
00034   arma_extra_debug_sigprint();
00035   arma_ignore(junk);
00036   
00037   typedef typename vec_type::elem_type eT;
00038   typedef typename vec_type::pod_type   T;
00039   
00040   vec_type x;
00041     
00042   if(num >= 2)
00043     {
00044     x.set_size(num);
00045     
00046     eT* x_mem = x.memptr();
00047     
00048     const uword num_m1 = num - 1;
00049     
00050     if(is_non_integral<T>::value == true)
00051       {
00052       const T delta = (end-start)/T(num_m1);
00053       
00054       for(uword i=0; i<num_m1; ++i)
00055         {
00056         x_mem[i] = eT(start + i*delta);
00057         }
00058       
00059       x_mem[num_m1] = eT(end);
00060       }
00061     else
00062       {
00063       const double delta = (end >= start) ? double(end-start)/double(num_m1) : -double(start-end)/double(num_m1);
00064       
00065       for(uword i=0; i<num_m1; ++i)
00066         {
00067         x_mem[i] = eT(double(start) + i*delta);
00068         }
00069       
00070       x_mem[num_m1] = eT(end);
00071       }
00072     
00073     return x;
00074     }
00075   else
00076     {
00077     x.set_size(1);
00078     
00079     x[0] = eT(end);
00080     }
00081   
00082   return x;
00083   }
00084 
00085 
00086 
00087 inline
00088 mat
00089 linspace(const double start, const double end, const uword num = 100u)
00090   {
00091   arma_extra_debug_sigprint();
00092   return linspace<mat>(start, end, num);
00093   }
00094 
00095 
00096 
00097 //
00098 // log_add
00099 
00100 template<typename eT>
00101 inline
00102 typename arma_float_only<eT>::result
00103 log_add(eT log_a, eT log_b)
00104   {
00105   if(log_a < log_b)
00106     {
00107     std::swap(log_a, log_b);
00108     }
00109   
00110   const eT negdelta = log_b - log_a;
00111   
00112   if( (negdelta < Math<eT>::log_min()) || (arma_isfinite(negdelta) == false) )
00113     {
00114     return log_a;
00115     }
00116   else
00117     {
00118     #if defined(ARMA_HAVE_LOG1P)
00119       return (log_a + log1p(std::exp(negdelta)));
00120     #else
00121       return (log_a + std::log(1.0 + std::exp(negdelta)));
00122     #endif
00123     }
00124   }
00125 
00126 
00127 
00128 template<typename eT>
00129 arma_inline
00130 arma_warn_unused
00131 bool
00132 is_finite(const eT x, const typename arma_scalar_only<eT>::result* junk = 0)
00133   {
00134   arma_ignore(junk);
00135   
00136   return arma_isfinite(x);
00137   }
00138 
00139 
00140 
00141 template<typename T1>
00142 inline
00143 arma_warn_unused
00144 bool
00145 is_finite(const Base<typename T1::elem_type,T1>& X)
00146   {
00147   arma_extra_debug_sigprint();
00148   
00149   typedef typename T1::elem_type eT;
00150   
00151   const unwrap<T1>   tmp(X.get_ref());
00152   const Mat<eT>& A = tmp.M;
00153   
00154   return A.is_finite();
00155   }
00156 
00157 
00158 
00159 template<typename T1>
00160 inline
00161 arma_warn_unused
00162 bool
00163 is_finite(const BaseCube<typename T1::elem_type,T1>& X)
00164   {
00165   arma_extra_debug_sigprint();
00166   
00167   typedef typename T1::elem_type eT;
00168   
00169   const unwrap_cube<T1> tmp(X.get_ref());
00170   const Cube<eT>& A =   tmp.M;
00171   
00172   return A.is_finite();
00173   }
00174 
00175 
00176 
00177 template<typename T1>
00178 arma_inline
00179 Op<T1, op_sympd>
00180 sympd(const Base<typename T1::elem_type,T1>& X)
00181   {
00182   arma_extra_debug_sigprint();
00183   
00184   return Op<T1, op_sympd>(X.get_ref());
00185   }
00186 
00187 
00188 


armadillo_matrix
Author(s): Conrad Sanderson - NICTA (www.nicta.com.au), (Wrapper by Sjoerd van den Dries)
autogenerated on Tue Jan 7 2014 11:42:04