tail.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_FUN_TAIL_HPP
#define STAN_MATH_PRIM_MAT_FUN_TAIL_HPP
#include <stan/math/prim/mat/err/check_column_index.hpp>
#include <stan/math/prim/mat/err/check_row_index.hpp>
#include <stan/math/prim/mat/err/check_std_vector_index.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/meta/index_type.hpp>
#include <stan/math/prim/arr/meta/index_type.hpp>
#include <vector>
namespace stan {
namespace math {
template <typename T>
inline
Eigen::Matrix<T, Eigen::Dynamic, 1>
tail(const Eigen::Matrix<T, Eigen::Dynamic, 1>& v,
size_t n) {
if (n != 0)
check_row_index("tail", "n", v, n);
return v.tail(n);
}
template <typename T>
inline
Eigen::Matrix<T, 1, Eigen::Dynamic>
tail(const Eigen::Matrix<T, 1, Eigen::Dynamic>& rv,
size_t n) {
if (n != 0)
check_column_index("tail", "n", rv, n);
return rv.tail(n);
}
template <typename T>
std::vector<T> tail(const std::vector<T>& sv,
size_t n) {
typedef typename index_type<std::vector<T> >::type idx_t;
if (n != 0)
check_std_vector_index("tail", "n", sv, n);
std::vector<T> s;
for (idx_t i = sv.size() - n; i < sv.size(); ++i)
s.push_back(sv[i]);
return s;
}
}
}
#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
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_column_index
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.
Definition: check_column_index.hpp:35
index_type.hpp
stan::math::check_std_vector_index
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.
Definition: check_std_vector_index.hpp:29
stan::math::check_row_index
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.
Definition: check_row_index.hpp:30
Eigen.hpp

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