| Stan Math Library 2.12.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/arr/err/check_nonzero_size.hpp>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
6 #include <algorithm>
7 #include <limits>
8 #include <stdexcept>
9 #include <vector>
10
11 namespace stan {
12 namespace math {
13
22 inline int max(const std::vector<int>& x) {
23 check_nonzero_size("max", "int vector", x);
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::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
stan::math::max
int max(const std::vector< int > &x)
Returns the maximum coefficient in the specified column vector.
Definition: max.hpp:22
check_nonzero_size.hpp

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