fn_eps.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup fn_eps
  16. //! @{
  17. template<typename T1>
  18. arma_warn_unused
  19. inline
  20. const eOp<T1, eop_eps>
  21. eps(const Base<typename T1::elem_type, T1>& X, const typename arma_not_cx<typename T1::elem_type>::result* junk = 0)
  22. {
  23. arma_extra_debug_sigprint();
  24. arma_ignore(junk);
  25. return eOp<T1, eop_eps>(X.get_ref());
  26. }
  27. template<typename T1>
  28. arma_warn_unused
  29. inline
  30. Mat< typename T1::pod_type >
  31. eps(const Base< std::complex<typename T1::pod_type>, T1>& X, const typename arma_cx_only<typename T1::elem_type>::result* junk = 0)
  32. {
  33. arma_extra_debug_sigprint();
  34. arma_ignore(junk);
  35. typedef typename T1::pod_type T;
  36. typedef typename T1::elem_type eT;
  37. const unwrap<T1> tmp(X.get_ref());
  38. const Mat<eT>& A = tmp.M;
  39. Mat<T> out(A.n_rows, A.n_cols);
  40. T* out_mem = out.memptr();
  41. const eT* A_mem = A.memptr();
  42. const uword n_elem = A.n_elem;
  43. for(uword i=0; i<n_elem; ++i)
  44. {
  45. out_mem[i] = eop_aux::direct_eps( A_mem[i] );
  46. }
  47. return out;
  48. }
  49. template<typename eT>
  50. arma_warn_unused
  51. arma_inline
  52. typename arma_integral_only<eT>::result
  53. eps(const eT& x)
  54. {
  55. arma_ignore(x);
  56. return eT(0);
  57. }
  58. template<typename eT>
  59. arma_warn_unused
  60. arma_inline
  61. typename arma_real_only<eT>::result
  62. eps(const eT& x)
  63. {
  64. return eop_aux::direct_eps(x);
  65. }
  66. template<typename T>
  67. arma_warn_unused
  68. arma_inline
  69. typename arma_real_only<T>::result
  70. eps(const std::complex<T>& x)
  71. {
  72. return eop_aux::direct_eps(x);
  73. }
  74. //! @}