Automatic Differentiation
 
Loading...
Searching...
No Matches
count_vars.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_CORE_COUNT_VARS_HPP
2#define STAN_MATH_REV_CORE_COUNT_VARS_HPP
3
7
8#include <utility>
9#include <vector>
10
11namespace stan {
12namespace math {
13
14namespace internal {
15template <typename VecVar, require_std_vector_vt<is_var, VecVar>* = nullptr,
16 typename... Pargs>
17inline size_t count_vars_impl(size_t count, VecVar&& x, Pargs&&... args);
18
19template <typename VecContainer,
20 require_std_vector_st<is_var, VecContainer>* = nullptr,
21 require_std_vector_vt<is_container, VecContainer>* = nullptr,
22 typename... Pargs>
23inline size_t count_vars_impl(size_t count, VecContainer&& x, Pargs&&... args);
24
25template <typename EigT, require_eigen_vt<is_var, EigT>* = nullptr,
26 typename... Pargs>
27inline size_t count_vars_impl(size_t count, EigT&& x, Pargs&&... args);
28
29template <typename... Pargs>
30inline size_t count_vars_impl(size_t count, const var& x, Pargs&&... args);
31
32template <typename Arith, require_arithmetic_t<scalar_type_t<Arith>>* = nullptr,
33 typename... Pargs>
34inline size_t count_vars_impl(size_t count, Arith& x, Pargs&&... args);
35
36inline size_t count_vars_impl(size_t count);
37
51template <typename VecVar, require_std_vector_vt<is_var, VecVar>*,
52 typename... Pargs>
53inline size_t count_vars_impl(size_t count, VecVar&& x, Pargs&&... args) {
54 return count_vars_impl(count + x.size(), std::forward<Pargs>(args)...);
55}
56
70template <typename VecContainer, require_std_vector_st<is_var, VecContainer>*,
71 require_std_vector_vt<is_container, VecContainer>*, typename... Pargs>
72inline size_t count_vars_impl(size_t count, VecContainer&& x, Pargs&&... args) {
73 for (auto&& x_iter : x) {
74 count = count_vars_impl(count, x_iter);
75 }
76 return count_vars_impl(count, std::forward<Pargs>(args)...);
77}
78
92template <typename EigT, require_eigen_vt<is_var, EigT>*, typename... Pargs>
93inline size_t count_vars_impl(size_t count, EigT&& x, Pargs&&... args) {
94 return count_vars_impl(count + x.size(), std::forward<Pargs>(args)...);
95}
96
108template <typename... Pargs>
109inline size_t count_vars_impl(size_t count, const var& x, Pargs&&... args) {
110 return count_vars_impl(count + 1, std::forward<Pargs>(args)...);
111}
112
127template <typename Arith, require_arithmetic_t<scalar_type_t<Arith>>*,
128 typename... Pargs>
129inline size_t count_vars_impl(size_t count, Arith& x, Pargs&&... args) {
130 return count_vars_impl(count, std::forward<Pargs>(args)...);
131}
132
136inline size_t count_vars_impl(size_t count) { return count; }
137} // namespace internal
138
145template <typename... Pargs>
146inline size_t count_vars(Pargs&&... args) {
147 return internal::count_vars_impl(0, std::forward<Pargs>(args)...);
148}
149
150} // namespace math
151} // namespace stan
152
153#endif
size_t count_vars_impl(size_t count, VecVar &&x, Pargs &&... args)
Count the number of vars in x (a std::vector of vars), add it to the running total,...
size_t count_vars(Pargs &&... args)
Count the number of vars in the input argument list.
var_value< double > var
Definition var.hpp:1187
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...