Stan Math Library  2.20.0
reverse mode automatic differentiation
rank.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_RANK_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_RANK_HPP
3 
6 
7 namespace stan {
8 namespace math {
9 
19 template <typename C>
20 inline int rank(const C& v, int s) {
21  check_range("rank", "v", v.size(), s);
22  --s; // adjust for indexing by one
23  int count = 0;
24  for (typename index_type<C>::type i = 0; i < v.size(); ++i)
25  if (v[i] < v[s])
26  ++count;
27  return count;
28 }
29 
30 } // namespace math
31 } // namespace stan
32 #endif
int rank(const C &v, int s)
Return the number of components of v less than v[s].
Definition: rank.hpp:20
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Check if specified index is within range.
Definition: check_range.hpp:24
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18

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