Automatic Differentiation
 
Loading...
Searching...
No Matches
num_elements.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_NUM_ELEMENTS_HPP
2#define STAN_MATH_PRIM_FUN_NUM_ELEMENTS_HPP
3
6#include <vector>
7
8namespace stan {
9namespace math {
10
18template <typename T, require_stan_scalar_t<T>* = nullptr>
19inline int num_elements(const T& x) {
20 return 1;
21}
22
31template <typename T, require_matrix_t<T>* = nullptr>
32inline int num_elements(const T& m) {
33 return m.size();
34}
35
45template <typename T>
46inline int num_elements(const std::vector<T>& v) {
47 if (v.size() == 0) {
48 return 0;
49 }
50 return v.size() * num_elements(v[0]);
51}
52
53} // namespace math
54} // namespace stan
55
56#endif
size_t num_elements(const T &m)
Returns the number of the elements of a matrix_cl or var_value<matrix_cl<T>>.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9