Stan Math Library  2.20.0
reverse mode automatic differentiation
head.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_HEAD_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_HEAD_HPP
3 
8 #include <vector>
9 
10 namespace stan {
11 namespace math {
12 
23 template <typename T>
24 inline Eigen::Matrix<T, Eigen::Dynamic, 1> head(
25  const Eigen::Matrix<T, Eigen::Dynamic, 1>& v, size_t n) {
26  if (n != 0)
27  check_row_index("head", "n", v, n);
28  return v.head(n);
29 }
30 
41 template <typename T>
42 inline Eigen::Matrix<T, 1, Eigen::Dynamic> head(
43  const Eigen::Matrix<T, 1, Eigen::Dynamic>& rv, size_t n) {
44  if (n != 0)
45  check_column_index("head", "n", rv, n);
46  return rv.head(n);
47 }
48 
59 template <typename T>
60 std::vector<T> head(const std::vector<T>& sv, size_t n) {
61  if (n != 0)
62  check_std_vector_index("head", "n", sv, n);
63 
64  std::vector<T> s;
65  for (size_t i = 0; i < n; ++i)
66  s.push_back(sv[i]);
67  return s;
68 }
69 
70 } // namespace math
71 } // namespace stan
72 #endif
Eigen::Matrix< T, Eigen::Dynamic, 1 > head(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, size_t n)
Return the specified number of elements as a vector from the front of the specified vector...
Definition: head.hpp:24
void check_column_index(const char *function, const char *name, const Eigen::Matrix< T_y, R, C > &y, size_t i)
Check if the specified index is a valid column of the matrix.
void check_std_vector_index(const char *function, const char *name, const std::vector< T > &y, int i)
Check if the specified index is valid in std vector This check is 1-indexed by default.
void check_row_index(const char *function, const char *name, const Eigen::Matrix< T_y, R, C > &y, size_t i)
Check if the specified index is a valid row of the matrix This check is 1-indexed by default...

     [ Stan Home Page ] © 2011–2018, Stan Development Team.