1 #ifndef STAN_MATH_PRIM_FUN_GET_HPP 2 #define STAN_MATH_PRIM_FUN_GET_HPP 3 4 #include <stan/math/prim/meta.hpp> 5 #include <stan/math/prim/fun/Eigen.hpp> 6 #include <cmath> 7 #include <cstddef> 8 #include <cstdlib> 9 #include <vector> 10 11 namespace stan { 12 13 /** \ingroup type_trait 14 * Returns the provided element. Scalar type overload 15 * for the function to retrieve n-th element of a vector, 16 * \c Eigen \c Matrix or expression 17 * 18 * @param x input scalar 19 * @param n index of the element to return 20 * @return input scalar 21 */ 22 template <typename T, typename = require_stan_scalar_t<T>> get(const T & x,size_t n)23inline T get(const T& x, size_t n) { 24 return x; 25 } 26 27 /** \ingroup type_trait 28 * Returns the n-th element of the provided std::vector. 29 * 30 * @param x input vector 31 * @param n index of the element to return 32 * @return n-th element of the input vector 33 */ 34 template <typename T> get(const std::vector<T> & x,size_t n)35inline T get(const std::vector<T>& x, size_t n) { 36 return x[n]; 37 } 38 39 /** \ingroup type_trait 40 * Returns the n-th element of the provided Eigen matrix. 41 * 42 * @param m input \c Eigen \c Matrix or expression 43 * @param n index of the element to return 44 * @return n-th element of the \c Eigen \c Matrix or expression 45 */ 46 template <typename T, typename = require_eigen_t<T>> get(const T & m,size_t n)47inline scalar_type_t<T> get(const T& m, size_t n) { 48 return m(static_cast<int>(n)); 49 } 50 51 } // namespace stan 52 #endif 53