1#ifndef STAN_MATH_PRIM_FUNCTOR_APPLY_VECTOR_UNARY_HPP
2#define STAN_MATH_PRIM_FUNCTOR_APPLY_VECTOR_UNARY_HPP
16template <
typename T,
typename Enable =
void>
43 template <
typename F,
typename T2 = T,
45 static inline auto apply(T2&& x, F&& f) {
48 [](
auto&& xx) {
return std::forward<decltype(xx)>(xx).matrix(); },
49 make_holder(std::forward<F>(f), std::forward<T2>(x)));
51 return make_holder(std::forward<F>(f), std::forward<T2>(x));
55 template <
typename F,
typename T2 = T,
57 static inline auto apply(T2&& x, F&& f) {
59 return make_holder(std::forward<F>(f), std::forward<T2>(x));
62 [](
auto&& xx) {
return std::forward<decltype(xx)>(xx).array(); },
63 make_holder(std::forward<F>(f), std::forward<T2>(x)));
79 template <
typename F,
typename T2 = T,
82 return std::forward<F>(f)(std::forward<T2>(x));
85 template <
typename F,
typename T2 = T,
88 return std::forward<F>(f)(std::forward<T2>(x));
102 template <
typename T2,
typename F>
103 static inline auto reduce(T2&& x, F&& f) {
104 return make_holder(std::forward<F>(f), std::forward<T2>(x));
120 using T_map =
typename Eigen::Map<
const Eigen::Matrix<
T_vt, -1, 1>>;
132 template <
typename T2,
typename F>
133 static inline auto apply(T2&& x, F&& f) {
136 std::vector<T_return> result(x.size());
137 Eigen::Map<Eigen::Matrix<T_return, -1, 1>>(result.data(), result.size())
154 template <
typename T2,
typename F>
156 return apply(std::forward<T2>(x), std::forward<F>(f));
169 template <
typename T2,
typename F>
170 static inline auto reduce(T2&& x, F&& f) {
202 template <
typename F>
203 static inline auto apply(
const T& x,
const F& f) {
206 std::vector<T_return> result(x.size());
207 std::transform(x.begin(), x.end(), result.begin(), [&f](
auto&& xx) {
208 return apply_vector_unary<T_vt>::apply(xx, f);
224 template <
typename F>
239 template <
typename F>
240 static inline auto reduce(
const T& x,
const F& f) {
241 size_t x_size = x.size();
243 std::vector<T_return> result(x_size);
244 for (
size_t i = 0; i < x_size; ++i)
require_t< is_eigen< std::decay_t< T > > > require_eigen_t
Require type satisfies is_eigen.
auto as_column_vector_or_scalar(T &&a)
as_column_vector_or_scalar of a kernel generator expression.
require_t< container_type_check_base< is_std_vector, value_type_t, TypeCheck, Check... > > require_std_vector_vt
Require type satisfies is_std_vector.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
auto make_holder(F &&func, Args &&... args)
Calls given function with given arguments.
constexpr decltype(auto) apply(F &&f, Tuple &&t, PreArgs &&... pre_args)
bool_constant< math::disjunction< is_container< Container >, is_var_matrix< Container > >::value > is_container_or_var_matrix
Deduces whether type is eigen matrix, standard vector, or var<Matrix>.
typename plain_type< std::decay_t< T > >::type plain_type_t
std::enable_if_t< Check::value > require_t
If condition is true, template is enabled.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Check if a type is derived from Eigen::ArrayBase
Checks if decayed type is a var, fvar, or arithmetic.
static auto apply(T2 &&x, F &&f)
Member function for applying a functor to a vector and subsequently returning a vector.
static auto apply_no_holder(T2 &&x, F &&f)
static auto reduce(T2 &&x, F &&f)
Member function for applying a functor to a vector and subsequently returning a scalar.
static auto apply_no_holder(T2 &x, F &&f)
Member function for applying a functor to a vector and subsequently returning a vector.
static auto reduce(const T &x, const F &f)
Member function for applying a functor to each container in an std::vector and subsequently returning...
static auto apply(const T &x, const F &f)
Member function for applying a functor to each container in an std::vector and subsequently returning...
static auto apply_no_holder(const T &x, const F &f)
Member function for applying a functor to each container in an std::vector and subsequently returning...
static auto reduce(T2 &&x, F &&f)
Member function for applying a functor to a vector and subsequently returning a scalar.
typename Eigen::Map< const Eigen::Matrix< T_vt, -1, 1 > > T_map
static auto apply(T2 &&x, F &&f)
Member function for applying a functor to a vector and subsequently returning a vector.
static auto apply_no_holder(T2 &&x, F &&f)
Member function for applying a functor to each container in an std::vector and subsequently returning...