fn_eps.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // - Dimitrios Bouzas (dimitris dot mpouzas at gmail dot com)
00007 // 
00008 // This file is part of the Armadillo C++ library.
00009 // It is provided without any warranty of fitness
00010 // for any purpose. You can redistribute this file
00011 // and/or modify it under the terms of the GNU
00012 // Lesser General Public License (LGPL) as published
00013 // by the Free Software Foundation, either version 3
00014 // of the License or (at your option) any later version.
00015 // (see http://www.opensource.org/licenses for more info)
00016 
00017 
00018 
00019 //! \addtogroup fn_eps
00020 //! @{
00021 
00022 
00023 
00024 //! \brief
00025 //! eps version for non-complex matrices and vectors
00026 template<typename T1>
00027 inline
00028 const eOp<T1, eop_eps>
00029 eps(const Base<typename T1::elem_type, T1>& X)
00030   {
00031   arma_extra_debug_sigprint();
00032   
00033   typedef typename T1::elem_type eT;
00034   
00035   return eOp<T1, eop_eps>(X.get_ref());
00036   }
00037 
00038 
00039 
00040 //! \brief
00041 //! eps version for complex matrices and vectors
00042 template<typename T1>
00043 inline
00044 Mat< typename T1::pod_type >
00045 eps(const Base< std::complex<typename T1::pod_type>, T1>& X)
00046   {
00047   arma_extra_debug_sigprint();
00048   
00049   typedef typename T1::pod_type   T;
00050   typedef typename T1::elem_type eT;
00051   
00052   const unwrap<T1>   tmp(X.get_ref());
00053   const Mat<eT>& A = tmp.M;
00054   
00055   Mat<T> out(A.n_rows, A.n_cols);
00056   
00057          T* out_mem = out.memptr();
00058   const eT* A_mem   = A.memptr();
00059   const u32 n_elem  = A.n_elem;
00060   
00061   for(u32 i=0; i<n_elem; ++i)
00062     {
00063     out_mem[i] = eop_aux::direct_eps( A_mem[i] );
00064     }
00065   
00066   
00067   return out;
00068   }
00069 
00070 
00071 
00072 template<typename eT>
00073 arma_inline
00074 arma_warn_unused
00075 typename arma_integral_only<eT>::result
00076 eps(const eT& x)
00077   {
00078   return eT(0);
00079   }
00080 
00081 
00082 
00083 template<typename eT>
00084 arma_inline
00085 arma_warn_unused
00086 typename arma_float_only<eT>::result
00087 eps(const eT& x)
00088   {
00089   return eop_aux::direct_eps(x);
00090   }
00091 
00092 
00093 
00094 template<typename T>
00095 arma_inline
00096 arma_warn_unused
00097 typename arma_float_only<T>::result
00098 eps(const std::complex<T>& x)
00099   {
00100   return eop_aux::direct_eps(x);
00101   }
00102 
00103 
00104 
00105 //! @}