Stan Math Library: stan/math/prim/mat/fun/tail.hpp Source File

| Stan Math Library 2.10.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
14 namespace math {
15
20 template <typename T>
21 inline
22 Eigen::Matrix<T, Eigen::Dynamic, 1>
23 tail(const Eigen::Matrix<T, Eigen::Dynamic, 1>& v,
24 size_t n) {
25 if (n != 0)
26 stan::math::check_row_index("tail", "n", v, n);
27 return v.tail(n);
28 }
29
30
35 template <typename T>
36 inline
37 Eigen::Matrix<T, 1, Eigen::Dynamic>
38 tail(const Eigen::Matrix<T, 1, Eigen::Dynamic>& rv,
39 size_t n) {
40 if (n != 0)
41 stan::math::check_column_index("tail", "n", rv, n);
42 return rv.tail(n);
43 }
44
45 template <typename T>
46 std::vector<T> tail(const std::vector<T>& sv,
47 size_t n) {
48 typedef typename index_type<std::vector<T> >::type idx_t;
49 if (n != 0)
50 stan::math::check_std_vector_index("tail", "n", sv, n);
51 std::vector<T> s;
52 for (idx_t i = sv.size() - n; i < sv.size(); ++i)
53 s.push_back(sv[i]);
54 return s;
55 }
56
57
58 }
59 }
60
61 #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:23
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:19
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.