| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/arr/err/check_nonzero_size.hpp>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
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
stan::math::min
int min(const std::vector< int > &x)
Returns the minimum coefficient in the specified column vector.
Definition: min.hpp:20
stan
Definition: log_sum_exp.hpp:8
stan::math::check_nonzero_size
bool check_nonzero_size(const char *function, const char *name, const T_y &y)
Return true if the specified matrix/vector is of non-zero size.
Definition: check_nonzero_size.hpp:29
Eigen.hpp
check_nonzero_size.hpp

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