| Stan Math Library 2.11.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/mat/fun/Eigen.hpp>
5 #include <algorithm>
6 #include <limits>
7 #include <stdexcept>
8 #include <vector>
9
10 namespace stan {
11 namespace math {
12
20 inline int min(const std::vector<int>& x) {
21 if (x.size() == 0)
22 throw std::domain_error("error: cannot take min of empty int vector");
23 int min = x[0];
24 for (size_t i = 1; i < x.size(); ++i)
25 if (x[i] < min)
26 min = x[i];
27 return min;
28 }
29
37 template <typename T>
38 inline T min(const std::vector<T>& x) {
39 if (x.size() == 0)
40 return std::numeric_limits<T>::infinity();
41 T min = x[0];
42 for (size_t i = 1; i < x.size(); ++i)
43 if (x[i] < min)
44 min = x[i];
45 return min;
46 }
47
54 template <typename T, int R, int C>
55 inline T min(const Eigen::Matrix<T, R, C>& m) {
56 if (m.size() == 0)
57 return std::numeric_limits<double>::infinity();
58 return m.minCoeff();
59 }
60
61 }
62 }
63 #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::domain_error
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
Definition: domain_error.hpp:32
Eigen.hpp

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