Stan Math Library  2.20.0
reverse mode automatic differentiation
min.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_MIN_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_MIN_HPP
3 
6 #include <algorithm>
7 #include <limits>
8 #include <vector>
9 
10 namespace stan {
11 namespace math {
12 
20 inline int min(const std::vector<int>& x) {
21  check_nonzero_size("min", "int vector", x);
22  Eigen::Map<const Eigen::Matrix<int, Eigen::Dynamic, 1>> m(&x[0], x.size());
23  return m.minCoeff();
24 }
25 
33 template <typename T>
34 inline T min(const std::vector<T>& x) {
35  if (x.size() == 0)
36  return std::numeric_limits<T>::infinity();
37  Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&x[0], x.size());
38  return m.minCoeff();
39 }
40 
47 template <typename T, int R, int C>
48 inline T min(const Eigen::Matrix<T, R, C>& m) {
49  if (m.size() == 0)
50  return std::numeric_limits<double>::infinity();
51  return m.minCoeff();
52 }
53 
54 } // namespace math
55 } // namespace stan
56 #endif
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
int min(const std::vector< int > &x)
Returns the minimum coefficient in the specified column vector.
Definition: min.hpp:20

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