Automatic Differentiation
 
Loading...
Searching...
No Matches
rank.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_PRIM_RANK_HPP
2#define STAN_MATH_OPENCL_PRIM_RANK_HPP
3#ifdef STAN_OPENCL
4
9
10namespace stan {
11namespace math {
12
22template <typename T,
23 require_all_kernel_expressions_and_none_scalar_t<T>* = nullptr>
24int rank(const T& v, int s) {
25 check_vector("rank (OpenCL)", "v", v);
26 check_range("rank (OpenCL)", "v", v.size(), s);
27 auto v_col = as_column_vector_or_scalar(v);
28 return sum((v_col < indexing(v_col, s - 1, col_index())) + 0);
29}
30
31} // namespace math
32} // namespace stan
33
34#endif
35#endif
Represents operation that determines column index.
Definition index.hpp:80
auto as_column_vector_or_scalar(T &&a)
as_column_vector_or_scalar of a kernel generator expression.
auto indexing(T_mat &&mat, T_row_index &&row_index, T_col_index &&col_index)
Index a kernel generator expression using two expressions for indices.
Definition indexing.hpp:304
int rank(const T &v, int s)
Return the number of components of v less than v[s].
Definition rank.hpp:24
void check_vector(const char *function, const char *name, const Mat &x)
Check the input is either a row vector or column vector or a matrix with a single row or column.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:23
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.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...