Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
max.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__MATRIX__MAX_HPP
2 #define STAN__MATH__MATRIX__MAX_HPP
3 
4 #include <stdexcept>
5 #include <vector>
7 
8 namespace stan {
9  namespace math {
10 
19  inline int max(const std::vector<int>& x) {
20  if (x.size() == 0)
21  throw std::domain_error("error: cannot take max of empty int vector");
22  int max = x[0];
23  for (size_t i = 1; i < x.size(); ++i)
24  if (x[i] > max)
25  max = x[i];
26  return max;
27  }
28 
36  template <typename T>
37  inline T max(const std::vector<T>& x) {
38  if (x.size() == 0)
39  return -std::numeric_limits<T>::infinity();
40  T max = x[0];
41  for (size_t i = 1; i < x.size(); ++i)
42  if (x[i] > max)
43  max = x[i];
44  return max;
45  }
46 
53  template <typename T, int R, int C>
54  inline T max(const Eigen::Matrix<T,R,C>& m) {
55  if (m.size() == 0)
56  return -std::numeric_limits<double>::infinity();
57  return m.maxCoeff();
58  }
59 
60  }
61 }
62 #endif
double max(const double a, const double b)
Definition: max.hpp:7

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