| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

max.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_MAX_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_MAX_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
21 inline int max(const std::vector<int>& x) {
22 if (x.size() == 0)
23 throw std::domain_error("error: cannot take max of empty int vector");
24 int max = x[0];
25 for (size_t i = 1; i < x.size(); ++i)
26 if (x[i] > max)
27 max = x[i];
28 return max;
29 }
30
38 template <typename T>
39 inline T max(const std::vector<T>& x) {
40 if (x.size() == 0)
41 return -std::numeric_limits<T>::infinity();
42 T max = x[0];
43 for (size_t i = 1; i < x.size(); ++i)
44 if (x[i] > max)
45 max = x[i];
46 return max;
47 }
48
55 template <typename T, int R, int C>
56 inline T max(const Eigen::Matrix<T, R, C>& m) {
57 if (m.size() == 0)
58 return -std::numeric_limits<double>::infinity();
59 return m.maxCoeff();
60 }
61
62 }
63 }
64 #endif
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::math::max
int max(const std::vector< int > &x)
Returns the maximum coefficient in the specified column vector.
Definition: max.hpp:21

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