| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/mat/err/check_column_index.hpp>
5 #include <stan/math/prim/mat/err/check_row_index.hpp>
6 #include <stan/math/prim/mat/err/check_std_vector_index.hpp>
7 #include <stan/math/prim/mat/fun/Eigen.hpp>
8 #include <stan/math/prim/mat/meta/index_type.hpp>
9 #include <stan/math/prim/arr/meta/index_type.hpp>
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
stan
Definition: log_sum_exp.hpp:8
index_type.hpp
check_column_index.hpp
stan::math::tail
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
check_std_vector_index.hpp
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::index_type
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
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
index_type.hpp
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.