Stan Math Library  2.15.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 
10 #include <vector>
11 
12 namespace stan {
13  namespace math {
14 
25  template <typename T>
26  inline
27  Eigen::Matrix<T, Eigen::Dynamic, 1>
28  tail(const Eigen::Matrix<T, Eigen::Dynamic, 1>& v,
29  size_t n) {
30  if (n != 0)
31  check_row_index("tail", "n", v, n);
32  return v.tail(n);
33  }
34 
45  template <typename T>
46  inline
47  Eigen::Matrix<T, 1, Eigen::Dynamic>
48  tail(const Eigen::Matrix<T, 1, Eigen::Dynamic>& rv,
49  size_t n) {
50  if (n != 0)
51  check_column_index("tail", "n", rv, n);
52  return rv.tail(n);
53  }
54 
65  template <typename T>
66  std::vector<T> tail(const std::vector<T>& sv,
67  size_t n) {
68  typedef typename index_type<std::vector<T> >::type idx_t;
69  if (n != 0)
70  check_std_vector_index("tail", "n", sv, n);
71  std::vector<T> s;
72  for (idx_t i = sv.size() - n; i < sv.size(); ++i)
73  s.push_back(sv[i]);
74  return s;
75  }
76 
77  }
78 }
79 #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:28
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.
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.

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