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__AGRAD__REV__SORT_HPP
2 #define STAN__AGRAD__REV__SORT_HPP
3 
4 #include <valarray>
5 #include <stan/agrad/rev/var.hpp>
9 #include <vector>
11 #include <algorithm> // std::sort
12 #include <functional> // std::greater
13 
14 namespace stan {
15  namespace agrad {
16 
24  inline std::vector<var> sort_asc(std::vector<var> xs) {
25  std::sort(xs.begin(), xs.end());
26  return xs;
27  }
28 
36  inline std::vector<var> sort_desc(std::vector<var> xs) {
37  std::sort(xs.begin(), xs.end(), std::greater<var>());
38  return xs;
39  }
40 
48  template <int R, int C>
49  inline typename Eigen::Matrix<var,R,C> sort_asc(Eigen::Matrix<var,R,C> xs) {
50  std::sort(xs.data(), xs.data()+xs.size());
51  return xs;
52  }
53 
61  template <int R, int C>
62  inline typename Eigen::Matrix<var,R,C> sort_desc(Eigen::Matrix<var,R,C> xs) {
63  std::sort(xs.data(), xs.data()+xs.size(), std::greater<var>());
64  return xs;
65  }
66 
67  }
68 }
69 #endif
std::vector< fvar< T > > sort_asc(std::vector< fvar< T > > xs)
Definition: sort.hpp:18
std::vector< fvar< T > > sort_desc(std::vector< fvar< T > > xs)
Definition: sort.hpp:26

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