Automatic Differentiation
 
Loading...
Searching...
No Matches
vec_concat.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_VEC_CONCAT_HPP
2#define STAN_MATH_PRIM_FUN_VEC_CONCAT_HPP
3
5#include <type_traits>
6#include <vector>
7
8namespace stan {
9namespace math {
10namespace internal {
11inline auto sum_vector_sizes() { return 0; }
19template <typename Vec, typename... VecArgs>
20inline auto sum_vector_sizes(const Vec& x, const VecArgs&... args) {
21 return x.size() + sum_vector_sizes(args...);
22}
26template <typename VecInOut>
27inline void append_vectors(VecInOut& x) {}
37template <typename VecInOut, typename VecIn, typename... VecArgs>
38inline void append_vectors(VecInOut& x, const VecIn& y,
39 const VecArgs&... args) {
40 for (auto& yy : y) {
41 x.push_back(yy);
42 }
43 append_vectors(x, args...);
44}
45} // namespace internal
46
56template <typename Vec, typename... Args>
57inline auto vec_concat(const Vec& v1, const Args&... args) {
58 Vec vec;
59 vec.reserve(internal::sum_vector_sizes(v1, args...));
60 internal::append_vectors(vec, v1, args...);
61 return vec;
62}
63
64} // namespace math
65} // namespace stan
66
67#endif
void append_vectors(VecInOut &x)
End of recursion for appending to vector.
auto vec_concat(const Vec &v1, const Args &... args)
Get the event stack from a vector of events and other arguments.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...