| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/mat/err/check_range.hpp>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
6 #include <vector>
7
8 namespace stan {
9 namespace math {
10
19 template <typename T>
20 inline int rank(const std::vector<T> & v, int s) {
21 using stan::math::check_range;
22 int size = static_cast<int>(v.size());
23 check_range("rank", "v", size, s);
24 --s;
25 int count(0);
26 T compare(v[s]);
27 for (int i = 0; i < size; ++i)
28 if (v[i] < compare)
29 ++count;
30 return count;
31 }
32
41 template <typename T, int R, int C>
42 inline int rank(const Eigen::Matrix<T, R, C> & v, int s) {
43 using stan::math::check_range;
44 int size = v.size();
45 check_range("rank", "v", size, s);
46 --s;
47 const T * vv = v.data();
48 int count(0);
49 T compare(vv[s]);
50 for (int i = 0; i < size; ++i)
51 if (vv[i] < compare)
52 ++count;
53 return count;
54 }
55
56 }
57 }
58 #endif
stan
Definition: log_sum_exp.hpp:8
stan::math::check_range
bool check_range(const char *function, const char *name, const int max, const int index, const int nested_level, const char *error_msg)
Return true if specified index is within range.
Definition: check_range.hpp:29
stan::math::rank
int rank(const std::vector< T > &v, int s)
Return the number of components of v less than v[s].
Definition: rank.hpp:20
Eigen.hpp
stan::math::size
int size(const std::vector< T > &x)
Return the size of the specified standard vector.
Definition: size.hpp:17
check_range.hpp

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