Algorith sandbox
ublas_unary_operator.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 #include <boost/numeric/ublas/functional.hpp>
11 #include <boost/numeric/ublas/vector_expression.hpp>
12 
13 namespace boost { namespace numeric { namespace ublas {
14  /*--------------------------------------------------------------------------
15  * exp
16  *------------------------------------------------------------------------*/
22  template <typename T>
23  struct scalar_exp : public scalar_unary_functor<T> {
24  typedef typename scalar_unary_functor<T>::value_type value_type;
25  typedef typename scalar_unary_functor<T>::argument_type argument_type;
26  typedef typename scalar_unary_functor<T>::result_type result_type;
27 
28  static result_type apply(argument_type t)
29  {
30  return std::exp(t);
31  }
32  };
41  template<typename E>
42  typename boost::numeric::ublas::vector_unary_traits<
43  E,
45  exp(const vector_expression<E>& e)
46  {
47  typedef typename boost::numeric::ublas::vector_unary_traits<
48  E,
49  scalar_exp<typename E::value_type> >::expression_type expression_type;
50  return expression_type(e());
51  }
59  double exp(const double e)
60  {
61  return std::exp(e);
62  }
63  /*--------------------------------------------------------------------------
64  * element_inverse
65  *------------------------------------------------------------------------*/
71  template <typename T>
72  struct scalar_inverse : public scalar_unary_functor<T> {
73  typedef typename scalar_unary_functor<T>::value_type value_type;
74  typedef typename scalar_unary_functor<T>::argument_type argument_type;
75  typedef typename scalar_unary_functor<T>::result_type result_type;
76 
77  static result_type apply(argument_type t)
78  {
79  return 1.0 / t;
80  }
81  };
90  template<typename E>
91  typename boost::numeric::ublas::vector_unary_traits<
92  E,
94  element_inverse(const vector_expression<E>& e)
95  {
96  typedef typename boost::numeric::ublas::vector_unary_traits<
97  E,
98  scalar_inverse<typename E::value_type> >::expression_type expression_type;
99  return expression_type(e());
100  }
108  double element_inverse(const double e)
109  {
110  return 1.0 / e;
111  }
112  /*--------------------------------------------------------------------------
113  * sin
114  *------------------------------------------------------------------------*/
120  template <typename T>
121  struct scalar_sin : public scalar_unary_functor<T> {
122  typedef typename scalar_unary_functor<T>::value_type value_type;
123  typedef typename scalar_unary_functor<T>::argument_type argument_type;
124  typedef typename scalar_unary_functor<T>::result_type result_type;
125 
126  static result_type apply(argument_type t)
127  {
128  return std::sin(t);
129  }
130  };
139  template<typename E>
140  typename boost::numeric::ublas::vector_unary_traits<
141  E,
143  sin(const vector_expression<E>& e)
144  {
145  typedef typename boost::numeric::ublas::vector_unary_traits<
146  E,
147  scalar_sin<typename E::value_type> >::expression_type expression_type;
148  return expression_type(e());
149  }
157  double sin(const double e)
158  {
159  return std::sin(e);
160  }
161  /*--------------------------------------------------------------------------
162  * cos
163  *------------------------------------------------------------------------*/
169  template <typename T>
170  struct scalar_cos : public scalar_unary_functor<T> {
171  typedef typename scalar_unary_functor<T>::value_type value_type;
172  typedef typename scalar_unary_functor<T>::argument_type argument_type;
173  typedef typename scalar_unary_functor<T>::result_type result_type;
174 
175  static result_type apply(argument_type t)
176  {
177  return std::cos(t);
178  }
179  };
188  template<typename E>
189  typename boost::numeric::ublas::vector_unary_traits<
190  E,
192  cos(const vector_expression<E>& e)
193  {
194  typedef typename boost::numeric::ublas::vector_unary_traits<
195  E,
196  scalar_cos<typename E::value_type> >::expression_type expression_type;
197  return expression_type(e());
198  }
206  double cos(const double e)
207  {
208  return std::cos(e);
209  }
210 } } } // namespace boost { namespace numeric { namespace ublas {
211 
Definition: ublas_unary_operator.hpp:13
Definition: ublas_unary_operator.hpp:72
Definition: ublas_unary_operator.hpp:13
Definition: ublas_unary_operator.hpp:170
Definition: ublas_unary_operator.hpp:23
Definition: ublas_unary_operator.hpp:121