Boost logo

Ublas :

From: Neal Becker (ndbecker2_at_[hidden])
Date: 2007-04-13 13:33:46


A useful addition:

namespace boost { namespace numeric { namespace ublas {
  template<class T>
  struct scalar_abs:
    public scalar_real_unary_functor<T> {
    typedef typename scalar_real_unary_functor<T>::value_type value_type;
    typedef typename scalar_real_unary_functor<T>::argument_type argument_type;
    typedef typename scalar_real_unary_functor<T>::result_type result_type;

    static BOOST_UBLAS_INLINE
    result_type apply (argument_type t) {
      return std::abs (t);
    }
  };

  template<typename E>
  inline typename vector_unary_traits<E, scalar_abs<typename E::value_type> >::result_type
  abs (vector_expression<E> const& e) {
    typedef typename vector_unary_traits<E, scalar_abs<typename E::value_type> >::expression_type expression_type;
    return expression_type (e ());
  }

}}}