Automatic Differentiation
 
Loading...
Searching...
No Matches
sort_desc.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_SORT_DESC_HPP
2#define STAN_MATH_PRIM_FUN_SORT_DESC_HPP
3
7#include <algorithm>
8#include <functional>
9#include <vector>
10
11namespace stan {
12namespace math {
13
22template <typename T>
23inline std::vector<T> sort_desc(std::vector<T> xs) {
24 check_not_nan("sort_asc", "container argument", xs);
25 std::sort(xs.begin(), xs.end(), std::greater<T>());
26 return xs;
27}
28
38template <typename EigVec, require_eigen_vector_t<EigVec>* = nullptr>
39inline plain_type_t<EigVec> sort_desc(EigVec&& xs) {
40 plain_type_t<EigVec> x = std::forward<EigVec>(xs);
41 check_not_nan("sort_asc", "container argument", x);
42 std::sort(x.data(), x.data() + x.size(),
43 std::greater<value_type_t<EigVec>>());
44 return x;
45}
46
47} // namespace math
48} // namespace stan
49
50#endif
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
auto sort_desc(T &&input)
Sort the (row)vector in ascending order.
Definition sort_desc.hpp:21
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...