| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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>
5 #include <stan/math/rev/scal/fun/is_nan.hpp>
6 #include <stan/math/prim/scal/fun/is_nan.hpp>
7 #include <boost/math/special_functions/fpclassify.hpp>
8 #include <stan/math/prim/scal/fun/constants.hpp>
9 #include <stan/math/prim/scal/meta/likely.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) {
65 using stan::math::NOT_A_NUMBER;
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_,
70 NOT_A_NUMBER, NOT_A_NUMBER));
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) {
97 using stan::math::NOT_A_NUMBER;
98 if (unlikely(is_nan(a))) {
99 if (unlikely(is_nan(b)))
100 return var(new precomp_v_vari(stan::math::NOT_A_NUMBER,
101 a.vi_,
102 stan::math::NOT_A_NUMBER));
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) {
129 using stan::math::NOT_A_NUMBER;
130 if (unlikely(is_nan(b))) {
131 if (unlikely(is_nan(a)))
132 return var(new precomp_v_vari(stan::math::NOT_A_NUMBER,
133 b.vi_,
134 stan::math::NOT_A_NUMBER));
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
core.hpp
stan::math::NOT_A_NUMBER
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:56
is_nan.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::precomp_vv_vari
Definition: precomp_vv_vari.hpp:11
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
unlikely
#define unlikely(x)
Definition: likely.hpp:9
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:43
likely.hpp
constants.hpp
stan::math::precomp_v_vari
Definition: precomp_v_vari.hpp:11
stan::math::is_nan
int is_nan(const fvar< T > &x)
Returns 1 if the input's value is NaN and 0 otherwise.
Definition: is_nan.hpp:22
stan::math::fmax
fvar< T > fmax(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmax.hpp:13
is_nan.hpp

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