Stan Math Library
2.20.0
reverse mode automatic differentiation
stan
math
prim
mat
fun
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/meta.hpp
>
5
#include <
stan/math/prim/mat/err/check_range.hpp
>
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
stan::math::rank
int rank(const C &v, int s)
Return the number of components of v less than v[s].
Definition:
rank.hpp:20
stan::math::check_range
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
stan
Definition:
log_sum_exp.hpp:8
meta.hpp
stan::math::index_type
Primary template class for the metaprogram to compute the index type of a container.
Definition:
index_type.hpp:18
check_range.hpp
[
Stan Home Page
]
© 2011–2018, Stan Development Team.