Go to the documentation of this file.
3
5
8 #include <vector>
9
10 namespace stan {
11 namespace math {
12
13 /**
14  * Return the specified number of elements as a vector
15  * from the front of the specified vector.
16  *
17  * @tparam T Type of value in vector.
18  * @param v Vector input.
19  * @param n Size of return.
20  * @return The first n elements of v.
21  * @throw std::out_of_range if n is out of range.
22  */
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)
29 }
30
31 /**
32  * Return the specified number of elements as a row vector
33  * from the front of the specified row vector.
34  *
35  * @tparam T Type of value in vector.
36  * @param rv Row vector.
37  * @param n Size of return row vector.
38  * @return The first n elements of rv.
39  * @throw std::out_of_range if n is out of range.
40  */
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)
47 }
48
49 /**
50  * Return the specified number of elements as a standard vector
51  * from the front of the specified standard vector.
52  *
53  * @tparam T Type of value in vector.
54  * @param sv Standard vector.
55  * @param n Size of return.
56  * @return The first n elements of sv.
57  * @throw std::out_of_range if n is out of range.
58  */
59 template <typename T>
60 std::vector<T> head(const std::vector<T>& sv, size_t n) {
61  if (n != 0)
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)