Stan Math Library  2.20.0
reverse mode automatic differentiation
tail.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_TAIL_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_TAIL_HPP
3 
9 #include <vector>
10 
11 namespace stan {
12 namespace math {
13 
24 template <typename T>
25 inline Eigen::Matrix<T, Eigen::Dynamic, 1> tail(
26  const Eigen::Matrix<T, Eigen::Dynamic, 1>& v, size_t n) {
27  if (n != 0)
28  check_row_index("tail", "n", v, n);
29  return v.tail(n);
30 }
31 
42 template <typename T>
43 inline Eigen::Matrix<T, 1, Eigen::Dynamic> tail(
44  const Eigen::Matrix<T, 1, Eigen::Dynamic>& rv, size_t n) {
45  if (n != 0)
46  check_column_index("tail", "n", rv, n);
47  return rv.tail(n);
48 }
49 
60 template <typename T>
61 std::vector<T> tail(const std::vector<T>& sv, size_t n) {
62  typedef typename index_type<std::vector<T> >::type idx_t;
63  if (n != 0)
64  check_std_vector_index("tail", "n", sv, n);
65  std::vector<T> s;
66  for (idx_t i = sv.size() - n; i < sv.size(); ++i)
67  s.push_back(sv[i]);
68  return s;
69 }
70 
71 } // namespace math
72 } // namespace stan
73 #endif
Eigen::Matrix< T, Eigen::Dynamic, 1 > tail(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, size_t n)
Return the specified number of elements as a vector from the back of the specified vector...
Definition: tail.hpp:25
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
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.