1 #ifndef STAN_MATH_PRIM_FUN_EXP2_HPP 2 #define STAN_MATH_PRIM_FUN_EXP2_HPP 3 4 #include <stan/math/prim/meta.hpp> 5 #include <stan/math/prim/functor/apply_scalar_unary.hpp> 6 #include <cmath> 7 8 namespace stan { 9 namespace math { 10 11 /** 12 * Structure to wrap `exp2()` so it can be vectorized. 13 */ 14 struct exp2_fun { 15 /** 16 * Return the base two exponent of the specified argument. 17 * 18 * @tparam T type of argument 19 * @param x argument 20 * @return Base two exponent of the argument. 21 */ 22 template <typename T> funstan::math::exp2_fun23 static inline T fun(const T& x) { 24 using std::exp2; 25 return exp2(x); 26 } 27 }; 28 29 /** 30 * Return the elementwise `exp2()` 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 type of container 35 * @param x container 36 * @return Elementwise exp2 of members of container. 37 */ 38 template < 39 typename T, 40 require_all_not_nonscalar_prim_or_rev_kernel_expression_t<T>* = nullptr, 41 require_not_var_matrix_t<T>* = nullptr> exp2(const T & x)42inline auto exp2(const T& x) { 43 return apply_scalar_unary<exp2_fun, T>::apply(x); 44 } 45 46 } // namespace math 47 } // namespace stan 48 49 #endif 50