| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/mat/err/check_column_index.hpp>
6 #include <stan/math/prim/mat/err/check_row_index.hpp>
7 #include <stan/math/prim/mat/err/check_std_vector_index.hpp>
8 #include <vector>
9
10 namespace stan {
11 namespace math {
12
23 template <typename T>
24 inline
25 Eigen::Matrix<T, Eigen::Dynamic, 1>
26 head(const Eigen::Matrix<T, Eigen::Dynamic, 1>& v,
27 size_t n) {
28 if (n != 0)
29 check_row_index("head", "n", v, n);
30 return v.head(n);
31 }
32
43 template <typename T>
44 inline
45 Eigen::Matrix<T, 1, Eigen::Dynamic>
46 head(const Eigen::Matrix<T, 1, Eigen::Dynamic>& rv,
47 size_t n) {
48 if (n != 0)
49 check_column_index("head", "n", rv, n);
50 return rv.head(n);
51 }
52
63 template <typename T>
64 std::vector<T> head(const std::vector<T>& sv,
65 size_t n) {
66 if (n != 0)
67 check_std_vector_index("head", "n", sv, n);
68
69 std::vector<T> s;
70 for (size_t i = 0; i < n; ++i)
71 s.push_back(sv[i]);
72 return s;
73 }
74
75 }
76 }
77 #endif
stan
Definition: log_sum_exp.hpp:8
check_column_index.hpp
check_std_vector_index.hpp
stan::math::head
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:26
stan::math::check_row_index
bool check_row_index(const char *function, const char *name, const Eigen::Matrix< T_y, R, C > &y, size_t i)
Return true if the specified index is a valid row of the matrix.
Definition: check_row_index.hpp:32
check_row_index.hpp
stan::math::check_std_vector_index
bool check_std_vector_index(const char *function, const char *name, const std::vector< T > &y, int i)
Return true if the specified index is valid in std vector.
Definition: check_std_vector_index.hpp:30
Eigen.hpp
stan::math::check_column_index
bool check_column_index(const char *function, const char *name, const Eigen::Matrix< T_y, R, C > &y, const size_t i)
Return true if the specified index is a valid column of the matrix.
Definition: check_column_index.hpp:37

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