All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
rank.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_FUN_RANK_HPP
#define STAN_MATH_PRIM_MAT_FUN_RANK_HPP
#include <stan/math/prim/mat/err/check_range.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <vector>
namespace stan {
namespace math {
template <typename T>
inline int rank(const std::vector<T> & v, int s) {
using stan::math::check_range;
int size = static_cast<int>(v.size());
check_range("rank", "v", size, s);
--s;
int count(0);
T compare(v[s]);
for (int i = 0; i < size; ++i)
if (v[i] < compare)
++count;
return count;
}
template <typename T, int R, int C>
inline int rank(const Eigen::Matrix<T, R, C> & v, int s) {
using stan::math::check_range;
int size = v.size();
check_range("rank", "v", size, s);
--s;
const T * vv = v.data();
int count(0);
T compare(vv[s]);
for (int i = 0; i < size; ++i)
if (vv[i] < compare)
++count;
return count;
}
}
}
#endif
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–2015, Stan Development Team.