Automatic Differentiation
 
Loading...
Searching...
No Matches
make_zeroed_arena.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_CORE_MAKE_ZEROED_ARENA_HPP
2#define STAN_MATH_REV_CORE_MAKE_ZEROED_ARENA_HPP
3
7
8namespace stan::math::internal {
17template <typename Input>
18inline constexpr auto make_zeroed_arena(Input&& input) {
19 if constexpr (is_tuple_v<Input>) {
20 return stan::math::filter_map<is_any_var_scalar>(
21 [](auto&& output_i) { return make_zeroed_arena(output_i); }, input);
22 } else if constexpr (is_std_vector_v<Input>) {
23 if constexpr (!is_var_v<value_type_t<Input>>) {
24 const auto output_size = input.size();
25 arena_t<std::vector<decltype(make_zeroed_arena(input[0]))>> ret;
26 ret.reserve(output_size);
27 for (Eigen::Index i = 0; i < output_size; ++i) {
28 ret.push_back(make_zeroed_arena(input[i]));
29 }
30 return ret;
31 } else {
32 return arena_t<std::vector<double>>(input.size(), 0.0);
33 }
34 } else if constexpr (is_eigen_v<Input>) {
37 input.cols()));
38 } else if constexpr (is_var<Input>::value) {
39 return static_cast<double>(0.0);
40 }
41}
42
43} // namespace stan::math::internal
44
45#endif
constexpr auto make_zeroed_arena(Input &&input)
Creates an arena type that is the same type as the input and initialized with zeros.
A comparator that works for any container type that has the brackets operator.
typename plain_type< std::decay_t< T > >::type plain_type_t
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.
Defines a static member named value which is defined to be false as the primitive scalar types cannot...
Definition is_var.hpp:14