Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
sort.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_SORT_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_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>
60  sort_desc(Eigen::Matrix<T, R, C> xs) {
61  std::sort(xs.data(), xs.data()+xs.size(), std::greater<T>());
62  return xs;
63  }
64 
65  }
66 }
67 #endif
std::vector< fvar< T > > sort_desc(std::vector< fvar< T > > xs)
Definition: sort_desc.hpp:17
std::vector< fvar< T > > sort_asc(std::vector< fvar< T > > xs)
Definition: sort_asc.hpp:17

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