1 #ifndef STAN_MATH_PRIM_MAT_FUN_LOG_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_LOG_HPP
3 
4 #include <stan/math/prim/mat/vectorize/apply_scalar_unary.hpp>
5 #include <stan/math/prim/scal/fun/log.hpp>
6 #include <cmath>
7 
8 namespace stan {
9 namespace math {
10 
11 /**
12  * Structure to wrap log() so that it can be vectorized.
13  */
14 struct log_fun {
15   /**
16    * Return natural log of specified argument.
17    *
18    * @tparam T Scalar argument type.
19    * @param[in] x Argument.
20    * @return Natural log of x.
21    */
22   template <typename T>
funstan::math::log_fun23   static inline T fun(const T& x) {
24     using std::log;
25     return log(x);
26   }
27 };
28 
29 /**
30  * Return the elementwise natural log of the specified argument,
31  * which may be a scalar or any Stan container of numeric scalars.
32  * The return type is the same as the argument type.
33  *
34  * @tparam T Argument type.
35  * @param[in] x Argument.
36  * @return Elementwise application of natural log to the argument.
37  */
38 template <typename T>
log(const T & x)39 inline typename apply_scalar_unary<log_fun, T>::return_t log(const T& x) {
40   return apply_scalar_unary<log_fun, T>::apply(x);
41 }
42 
43 }  // namespace math
44 }  // namespace stan
45 #endif
46