Automatic Differentiation
 
Loading...
Searching...
No Matches
max.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_MAX_HPP
2#define STAN_MATH_PRIM_FUN_MAX_HPP
3
8#include <algorithm>
9#include <vector>
10
11namespace stan {
12namespace math {
13
24template <typename T1, typename T2, require_all_arithmetic_t<T1, T2>* = nullptr>
25auto max(T1 x, T2 y) {
26 return std::max(x, y);
27}
28
41template <typename T, require_container_t<T>* = nullptr>
42inline value_type_t<T> max(const T& m) {
43 if (std::is_integral<value_type_t<T>>::value) {
44 check_nonzero_size("max", "int vector", m);
45 } else if (m.size() == 0) {
46 return NEGATIVE_INFTY;
47 }
49 m, [](const auto& x) { return x.maxCoeff(); });
50}
51
52} // namespace math
53} // namespace stan
54
55#endif
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
static constexpr double NEGATIVE_INFTY
Negative infinity.
Definition constants.hpp:51
auto max(T1 x, T2 y)
Returns the maximum value of the two specified scalar arguments.
Definition max.hpp:25
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.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...