1#ifndef STAN_MATH_REV_FUN_TO_ARENA_HPP
2#define STAN_MATH_REV_FUN_TO_ARENA_HPP
26template <
typename T, require_not_same_t<T, arena_t<T>>* =
nullptr,
27 require_not_container_t<T>* =
nullptr,
28 require_not_matrix_cl_t<T>* =
nullptr>
30 return std::forward<T>(a);
47template <
typename T, require_same_t<T, arena_t<T>>* =
nullptr,
48 require_not_matrix_cl_t<T>* =
nullptr,
49 require_not_std_vector_t<T>* =
nullptr,
50 require_not_tuple_t<T>* =
nullptr>
51inline std::remove_reference_t<T>
to_arena(T&& a) {
54 return std::forward<T>(a);
67template <
typename T, require_eigen_t<T>* =
nullptr,
68 require_not_same_t<T, arena_t<T>>* =
nullptr>
84inline std::vector<T, arena_allocator<T>>
to_arena(
90 std::vector<T, arena_allocator<T>> res;
91 std::memcpy(
static_cast<void*
>(&res),
static_cast<const void*
>(&a),
110template <
typename T, require_same_t<T, arena_t<T>>* =
nullptr>
112 return {a.begin(), a.end()};
128template <
typename T, require_not_same_t<T, arena_t<T>>* =
nullptr>
131 res.reserve(a.size());
132 for (
const T& i : a) {
144template <
typename Tuple, require_tuple_t<Tuple>* =
nullptr>
148 return std::make_tuple(
to_arena(std::forward<
decltype(args)>(args))...);
150 std::forward<Tuple>(tup));
161template <
bool Condition,
typename T, std::enable_if_t<!Condition>* =
nullptr>
163 return std::forward<T>(a);
166template <
bool Condition,
typename T, std::enable_if_t<Condition>* =
nullptr>
arena_t< T > to_arena(const T &a)
Converts given argument into a type that either has any dynamic allocation on AD stack or schedules i...
T to_arena_if(T &&a)
If the condition is true, converts given argument into a type that has any dynamic allocation on AD s...
constexpr decltype(auto) apply(F &&f, Tuple &&t, PreArgs &&... pre_args)
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
std library compatible allocator that uses AD stack.