Loading [MathJax]/extensions/TeX/AMSmath.js
Automatic Differentiation
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
iter_tuple_nested.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUNCTOR_ITER_TUPLE_N_HPP
2#define STAN_MATH_PRIM_FUNCTOR_ITER_TUPLE_N_HPP
3
8#include <utility>
9namespace stan::math {
22template <typename F, typename... Types>
23inline void iter_tuple_nested(F&& f, Types&&... args) {
24 constexpr bool is_vec_container
25 = (is_std_vector_v<Types> && ...)
26 && (!is_stan_scalar<value_type_t<Types>>::value && ...);
27 if constexpr ((is_tuple_v<Types> && ...)) {
29 [&f](auto&&... args_i) {
30 iter_tuple_nested(f, std::forward<decltype(args_i)>(args_i)...);
31 },
32 std::forward<Types>(args)...);
33 } else if constexpr (is_vec_container) {
34 const auto vec_size = max_size(args...);
35 for (Eigen::Index i = 0; i < vec_size; ++i) {
36 iter_tuple_nested(f, args[i]...);
37 }
38 } else {
39 f(std::forward<Types>(args)...);
40 }
41}
42
43} // namespace stan::math
44#endif
void iter_tuple_nested(F &&f, Types &&... args)
Iterate and nest into a tuple or std::vector to apply f to each matrix or scalar type.
constexpr void for_each(F &&f, const std::tuple<> &)
Apply a function to each element of a tuple.
Definition for_each.hpp:80
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
Definition max_size.hpp:20
Matrices and templated mathematical functions.
Checks if decayed type is a var, fvar, or arithmetic.