Automatic Differentiation
 
Loading...
Searching...
No Matches
head.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_HEAD_HPP
2#define STAN_MATH_PRIM_FUN_HEAD_HPP
3
6#include <vector>
7
8namespace stan {
9namespace math {
10
21template <typename T, require_vector_t<T>* = nullptr>
22inline auto head(const T& v, size_t n) {
23 if (n != 0) {
24 check_vector_index("head", "n", v, n);
25 }
26 return v.head(n);
27}
28
39template <typename T>
40std::vector<T> head(const std::vector<T>& sv, size_t n) {
41 if (n != 0) {
42 check_std_vector_index("head", "n", sv, n);
43 }
44
45 std::vector<T> s(sv.begin(), sv.begin() + n);
46 return s;
47}
48
49} // namespace math
50} // namespace stan
51
52#endif
void check_vector_index(const char *function, const char *name, const T &y, size_t i)
Check if the specified index is a valid element of the row or column vector This check is 1-indexed b...
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 This check is 1-indexed by default.
auto head(T_x &&x, size_t n)
Return the specified number of elements as a vector or row vector (same as input) from the front of t...
Definition head.hpp:24
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9