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__FWD__SORT_HPP
2 #define STAN__AGRAD__FWD__SORT_HPP
3 
5 #include <stan/meta/traits.hpp>
6 #include <vector>
8 #include <algorithm> // std::sort
9 #include <functional> // std::greater
10 
11 namespace stan {
12 
13  namespace agrad {
14 
15  template <typename T>
16  inline
17  std::vector< fvar<T> >
18  sort_asc(std::vector< fvar<T> > xs) {
19  std::sort(xs.begin(), xs.end());
20  return xs;
21  }
22 
23  template <typename T>
24  inline
25  std::vector< fvar<T> >
26  sort_desc(std::vector< fvar<T> > xs) {
27  std::sort(xs.begin(), xs.end(), std::greater< fvar<T> >());
28  return xs;
29  }
30 
31  template <typename T, int R, int C>
32  inline
33  typename Eigen::Matrix<fvar<T>,R,C>
34  sort_asc(Eigen::Matrix<fvar<T>,R,C> xs) {
35  std::sort(xs.data(), xs.data()+xs.size());
36  return xs;
37  }
38 
39  template <typename T, int R, int C>
40  inline
41  typename Eigen::Matrix<fvar<T>,R,C>
42  sort_desc(Eigen::Matrix<fvar<T>,R,C> xs) {
43  std::sort(xs.data(), xs.data()+xs.size(), std::greater< fvar<T> >());
44  return xs;
45  }
46 
47  }
48 }
49 #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.