Stan Math Library  2.20.0
reverse mode automatic differentiation
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 
6 #include <algorithm>
7 #include <limits>
8 #include <vector>
9 
10 namespace stan {
11 namespace math {
12 
21 inline int max(const std::vector<int>& x) {
22  check_nonzero_size("max", "int vector", x);
23  Eigen::Map<const Eigen::Matrix<int, Eigen::Dynamic, 1>> m(&x[0], x.size());
24  return m.maxCoeff();
25 }
26 
34 template <typename T>
35 inline T max(const std::vector<T>& x) {
36  if (x.size() == 0)
37  return -std::numeric_limits<T>::infinity();
38  Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&x[0], x.size());
39  return m.maxCoeff();
40 }
41 
48 template <typename T, int R, int C>
49 inline T max(const Eigen::Matrix<T, R, C>& m) {
50  if (m.size() == 0)
51  return -std::numeric_limits<double>::infinity();
52  return m.maxCoeff();
53 }
54 
55 } // namespace math
56 } // namespace stan
57 #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 max(const std::vector< int > &x)
Returns the maximum coefficient in the specified column vector.
Definition: max.hpp:21

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