Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
head.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__MATRIX__HEAD_HPP
2 #define STAN__MATH__MATRIX__HEAD_HPP
3 
5 #include <vector>
9 
10 namespace stan {
11  namespace math {
12 
21  template <typename T>
22  inline
23  Eigen::Matrix<T,Eigen::Dynamic,1>
24  head(const Eigen::Matrix<T,Eigen::Dynamic,1>& v,
25  size_t n) {
26  if (n != 0)
27  stan::math::check_row_index("head(%1%)",n,v,"n",(double*)0);
28  return v.head(n);
29  }
30 
39  template <typename T>
40  inline
41  Eigen::Matrix<T,1,Eigen::Dynamic>
42  head(const Eigen::Matrix<T,1,Eigen::Dynamic>& rv,
43  size_t n) {
44  if (n != 0)
45  stan::math::check_column_index("head(%1%)",n,rv,"n",(double*)0);
46  return rv.head(n);
47  }
48 
57  template <typename T>
58  std::vector<T> head(const std::vector<T>& sv,
59  size_t n) {
60  if (n != 0)
61  stan::math::check_std_vector_index("head(%1%)",n,sv,"n",(double*)0);
62 
63  std::vector<T> s;
64  for (size_t i = 0; i < n; ++i)
65  s.push_back(sv[i]);
66  return s;
67  }
68 
69 
70  }
71 }
72 
73 #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.
Eigen::Matrix< T, Eigen::Dynamic, 1 > head(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, size_t n)
Return the specified number of elements as a vector from the front of the specified vector...
Definition: head.hpp:24
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.