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 <cstdint>
7#include <vector>
8
9namespace stan {
10namespace math {
11
19template <typename T, require_stan_scalar_t<T>* = nullptr>
20inline int64_t num_elements(const T& x) {
21 return 1;
22}
23
32template <typename T, require_matrix_t<T>* = nullptr>
33inline int64_t num_elements(const T& m) {
34 return m.size();
35}
36
46template <typename T>
47inline int64_t num_elements(const std::vector<T>& v) {
48 if (v.size() == 0) {
49 return 0;
50 }
51 return v.size() * num_elements(v[0]);
52}
53
54} // namespace math
55} // namespace stan
56
57#endif
int64_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 ...