Stan Math Library  2.10.0
reverse mode automatic differentiation
fmax.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_FMAX_HPP
2 #define STAN_MATH_REV_SCAL_FUN_FMAX_HPP
3 
4 #include <stan/math/rev/core.hpp>
7 #include <boost/math/special_functions/fpclassify.hpp>
10 
11 namespace stan {
12 
13  namespace math {
14 
63  inline var fmax(const stan::math::var& a,
64  const stan::math::var& b) {
66  if (unlikely(is_nan(a))) {
67  if (unlikely(is_nan(b)))
68  return var(new precomp_vv_vari(NOT_A_NUMBER,
69  a.vi_, b.vi_,
71 
72  return b;
73  }
74 
75  if (unlikely(is_nan(b)))
76  return a;
77 
78  return a > b ? a : b;
79  }
80 
95  inline var fmax(const stan::math::var& a,
96  const double& b) {
98  if (unlikely(is_nan(a))) {
99  if (unlikely(is_nan(b)))
101  a.vi_,
103 
104  return var(b);
105  }
106 
107  if (unlikely(is_nan(b)))
108  return a;
109 
110  return a >= b ? a : var(b);
111  }
112 
127  inline var fmax(const double& a,
128  const stan::math::var& b) {
130  if (unlikely(is_nan(b))) {
131  if (unlikely(is_nan(a)))
133  b.vi_,
135  return var(a);
136  }
137 
138  if (unlikely(is_nan(a)))
139  return b;
140 
141  return a > b ? var(a) : b;
142  }
143 
144  }
145 }
146 #endif
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:56
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
#define unlikely(x)
Definition: likely.hpp:9
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:43
int is_nan(const fvar< T > &x)
Returns 1 if the input's value is NaN and 0 otherwise.
Definition: is_nan.hpp:22
fvar< T > fmax(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmax.hpp:13

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