Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sort.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__MATRIX__SORT_HPP
2 #define STAN__MATH__MATRIX__SORT_HPP
3 
5 #include <vector>
6 #include <algorithm> // std::sort
7 #include <functional> // std::greater
8 
9 namespace stan {
10  namespace math {
11 
19  template <typename T>
20  inline typename std::vector<T> sort_asc(std::vector<T> xs) {
21  std::sort(xs.begin(), xs.end());
22  return xs;
23  }
24 
32  template <typename T>
33  inline typename std::vector<T> sort_desc(std::vector<T> xs) {
34  std::sort(xs.begin(), xs.end(), std::greater<T>());
35  return xs;
36  }
37 
45  template <typename T, int R, int C>
46  inline typename Eigen::Matrix<T,R,C> sort_asc(Eigen::Matrix<T,R,C> xs) {
47  std::sort(xs.data(), xs.data()+xs.size());
48  return xs;
49  }
50 
58  template <typename T, int R, int C>
59  inline typename Eigen::Matrix<T,R,C> sort_desc(Eigen::Matrix<T,R,C> xs) {
60  std::sort(xs.data(), xs.data()+xs.size(), std::greater<T>());
61  return xs;
62  }
63 
64  }
65 }
66 #endif
std::vector< T > sort_desc(std::vector< T > xs)
Return the specified standard vector in descending order.
Definition: sort.hpp:33
std::vector< T > sort_asc(std::vector< T > xs)
Return the specified standard vector in ascending order.
Definition: sort.hpp:20

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