Stan Math Library  2.15.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  int min = x[0];
23  for (size_t i = 1; i < x.size(); ++i)
24  if (x[i] < min)
25  min = x[i];
26  return min;
27  }
28 
36  template <typename T>
37  inline T min(const std::vector<T>& x) {
38  if (x.size() == 0)
39  return std::numeric_limits<T>::infinity();
40  T min = x[0];
41  for (size_t i = 1; i < x.size(); ++i)
42  if (x[i] < min)
43  min = x[i];
44  return min;
45  }
46 
53  template <typename T, int R, int C>
54  inline T min(const Eigen::Matrix<T, R, C>& m) {
55  if (m.size() == 0)
56  return std::numeric_limits<double>::infinity();
57  return m.minCoeff();
58  }
59 
60  }
61 }
62 #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–2016, Stan Development Team.