| Stan Math Library 2.12.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 <stan/math/prim/scal/fun/constants.hpp>
8 #include <stan/math/prim/scal/meta/likely.hpp>
9
10 namespace stan {
11 namespace math {
12
61 inline var fmax(const var& a,
62 const var& b) {
63 if (unlikely(is_nan(a))) {
64 if (unlikely(is_nan(b)))
65 return var(new precomp_vv_vari(NOT_A_NUMBER,
66 a.vi_, b.vi_,
67 NOT_A_NUMBER, NOT_A_NUMBER));
68 return b;
69 }
70 if (unlikely(is_nan(b)))
71 return a;
72 return a > b ? a : b;
73 }
74
89 inline var fmax(const var& a,
90 double b) {
91 if (unlikely(is_nan(a))) {
92 if (unlikely(is_nan(b)))
93 return var(new precomp_v_vari(NOT_A_NUMBER,
94 a.vi_,
95 NOT_A_NUMBER));
96 return var(b);
97 }
98 if (unlikely(is_nan(b)))
99 return a;
100 return a >= b ? a : var(b);
101 }
102
117 inline var fmax(double a,
118 const var& b) {
119 if (unlikely(is_nan(b))) {
120 if (unlikely(is_nan(a)))
121 return var(new precomp_v_vari(NOT_A_NUMBER,
122 b.vi_,
123 NOT_A_NUMBER));
124 return var(a);
125 }
126 if (unlikely(is_nan(a)))
127 return b;
128 return a > b ? var(a) : b;
129 }
130
131 }
132 }
133 #endif
core.hpp
stan::math::NOT_A_NUMBER
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:55
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:30
unlikely
#define unlikely(x)
Definition: likely.hpp:9
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:42
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:21
stan::math::fmax
fvar< T > fmax(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmax.hpp:14
is_nan.hpp

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