Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tail.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__MATRIX__TAIL_HPP
2 #define STAN__MATH__MATRIX__TAIL_HPP
3 
4 #include <vector>
10 
11 namespace stan {
12 
13  namespace math {
14 
19  template <typename T>
20  inline
21  Eigen::Matrix<T,Eigen::Dynamic,1>
22  tail(const Eigen::Matrix<T,Eigen::Dynamic,1>& v,
23  size_t n) {
24  if (n != 0)
25  stan::math::check_row_index("tail(%1%)",n,v,"n",(double*)0);
26  return v.tail(n);
27  }
28 
29 
34  template <typename T>
35  inline
36  Eigen::Matrix<T,1,Eigen::Dynamic>
37  tail(const Eigen::Matrix<T,1,Eigen::Dynamic>& rv,
38  size_t n) {
39  if (n != 0)
40  stan::math::check_column_index("tail(%1%)",n,rv,"n",(double*)0);
41  return rv.tail(n);
42  }
43 
44  template <typename T>
45  std::vector<T> tail(const std::vector<T>& sv,
46  size_t n) {
47  typedef typename index_type<std::vector<T> >::type idx_t;
48  if (n != 0)
49  stan::math::check_std_vector_index("tail(%1%)",n,sv,"n",(double*)0);
50  std::vector<T> s;
51  for (idx_t i = sv.size() - n; i < sv.size(); ++i)
52  s.push_back(sv[i]);
53  return s;
54  }
55 
56 
57  }
58 }
59 
60 #endif
bool check_std_vector_index(const char *function, size_t i, const std::vector< T_y > &y, const char *name, T_result *result)
Return true if the specified index is valid in std vector.
bool check_column_index(const char *function, size_t i, const Eigen::Matrix< T_y, R, C > &y, const char *name, T_result *result)
Return true if the specified index is a valid column of the matrix.
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:21
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:22
bool check_row_index(const char *function, size_t i, const Eigen::Matrix< T_y, R, C > &y, const char *name, T_result *result)
Return true if the specified index is a valid row of the matrix.

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