| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

apply_scalar_unary.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_VECTORIZE_APPLY_SCALAR_UNARY_HPP
2 #define STAN_MATH_PRIM_MAT_VECTORIZE_APPLY_SCALAR_UNARY_HPP
3
4 #include <Eigen/Dense>
5 #include <vector>
6
7 namespace stan {
8
9 namespace math {
10
35 template <typename F, typename T>
36 struct apply_scalar_unary {
40 typedef typename Eigen::internal::traits<T>::Scalar scalar_t;
41
46 typedef Eigen::Matrix<scalar_t, T::RowsAtCompileTime,
47 T::ColsAtCompileTime>
48 return_t;
49
58 static inline return_t apply(const T& x) {
59 return_t result(x.rows(), x.cols());
60 for (int j = 0; j < x.cols(); ++j)
61 for (int i = 0; i < x.rows(); ++i)
62 result(i, j) = apply_scalar_unary<F, scalar_t>::apply(x(i, j));
63 return result;
64 }
65 };
66
73 template <typename F>
74 struct apply_scalar_unary<F, double> {
78 typedef double return_t;
79
89 static inline return_t apply(double x) {
90 return F::fun(x);
91 }
92 };
93
102 template <typename F>
103 struct apply_scalar_unary<F, int> {
107 typedef double return_t;
108
118 static inline return_t apply(int x) {
119 return F::fun(static_cast<double>(x));
120 }
121 };
122
132 template <typename F, typename T>
133 struct apply_scalar_unary<F, std::vector<T> > {
138 typedef typename std::vector<typename apply_scalar_unary<F, T>::return_t>
139 return_t;
140
150 static inline return_t apply(const std::vector<T>& x) {
151 return_t fx(x.size());
152 for (size_t i = 0; i < x.size(); ++i)
153 fx[i] = apply_scalar_unary<F, T>::apply(x[i]);
154 return fx;
155 }
156 };
157
158 }
159 }
160 #endif
stan::math::apply_scalar_unary< F, double >::apply
static return_t apply(double x)
Apply the function specified by F to the specified argument.
Definition: apply_scalar_unary.hpp:89
stan
Definition: log_sum_exp.hpp:8
std
Definition: std_numeric_limits.hpp:7
stan::math::apply_scalar_unary::return_t
Eigen::Matrix< scalar_t, T::RowsAtCompileTime, T::ColsAtCompileTime > return_t
Return type for applying the function elementwise to a matrix expression template of type T...
Definition: apply_scalar_unary.hpp:48
stan::math::apply_scalar_unary< F, std::vector< T > >::apply
static return_t apply(const std::vector< T > &x)
Apply the function specified by F elementwise to the specified argument.
Definition: apply_scalar_unary.hpp:150
stan::math::apply_scalar_unary< F, int >::apply
static return_t apply(int x)
Apply the function specified by F to the specified argument.
Definition: apply_scalar_unary.hpp:118
stan::math::apply_scalar_unary< F, double >::return_t
double return_t
The return type, double.
Definition: apply_scalar_unary.hpp:78
stan::math::apply_scalar_unary< F, std::vector< T > >::return_t
std::vector< typename apply_scalar_unary< F, T >::return_t > return_t
Return type, which is calculated recursively as a standard vector of the return type of the contained...
Definition: apply_scalar_unary.hpp:139
stan::math::apply_scalar_unary::scalar_t
Eigen::internal::traits< T >::Scalar scalar_t
Type of underlying scalar for the matrix type T.
Definition: apply_scalar_unary.hpp:40
stan::math::apply_scalar_unary
Base template class for vectorization of unary scalar functions defined by a template class F to a sc...
Definition: apply_scalar_unary.hpp:36
stan::math::apply_scalar_unary< F, int >::return_t
double return_t
The return type, double.
Definition: apply_scalar_unary.hpp:107
stan::math::apply_scalar_unary::apply
static return_t apply(const T &x)
Return the result of applying the function defined by the template parameter F to the specified matri...
Definition: apply_scalar_unary.hpp:58

[ Stan Home Page ] © 2011–2016, Stan Development Team.