Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rank.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__MATRIX__RANK_HPP
2 #define STAN__MATH__MATRIX__RANK_HPP
3 
4 #include <vector>
7 
8 namespace stan {
9  namespace math {
10 
17  template <typename T>
18  inline size_t rank(const std::vector<T> & v, int s) {
19  size_t size = v.size();
20  check_range(size,s,"in the function rank(v,s)",s);
21  s--;
22  size_t count(0U);
23  T compare(v[s]);
24  for (size_t i = 0U; i < size; ++i)
25  if (v[i]<compare) count++;
26  return count;
27  }
28 
35  template <typename T, int R, int C>
36  inline size_t rank(const Eigen::Matrix<T,R,C> & v, int s) {
37  size_t size = v.size();
38  check_range(size,s,"in the function rank(v,s)",s);
39  s--;
40  const T * vv = v.data();
41  size_t count(0U);
42  T compare(vv[s]);
43  for (size_t i = 0U; i < size; ++i)
44  if (vv[i]<compare) count++;
45  return count;
46  }
47 
48  }
49 }
50 #endif
int size(const std::vector< T > &x)
Definition: size.hpp:11
void check_range(size_t max, size_t i, const char *msg, size_t idx)
Definition: check_range.hpp:30
size_t rank(const std::vector< T > &v, int s)
Return the number of components of v less than v[s].
Definition: rank.hpp:18

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