| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

fmin.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_FMIN_HPP
2 #define STAN_MATH_REV_SCAL_FUN_FMIN_HPP
3
4 #include <stan/math/rev/core.hpp>
5 #include <stan/math/prim/scal/fun/constants.hpp>
6 #include <stan/math/prim/scal/meta/likely.hpp>
7 #include <stan/math/rev/scal/fun/is_nan.hpp>
8 #include <stan/math/prim/scal/fun/is_nan.hpp>
9
10 namespace stan {
11 namespace math {
12
57 inline var fmin(const var& a,
58 const var& b) {
59 if (unlikely(is_nan(a))) {
60 if (unlikely(is_nan(b)))
61 return var(new precomp_vv_vari(NOT_A_NUMBER,
62 a.vi_, b.vi_,
63 NOT_A_NUMBER, NOT_A_NUMBER));
64 return b;
65 }
66 if (unlikely(is_nan(b)))
67 return a;
68 return a < b ? a : b;
69 }
70
84 inline var fmin(const var& a,
85 double b) {
86 if (unlikely(is_nan(a))) {
87 if (unlikely(is_nan(b)))
88 return var(new precomp_v_vari(NOT_A_NUMBER,
89 a.vi_,
90 NOT_A_NUMBER));
91 return var(b);
92 }
93 if (unlikely(is_nan(b)))
94 return a;
95 return a <= b ? a : var(b);
96 }
97
112 inline var fmin(double a,
113 const var& b) {
114 if (unlikely(is_nan(b))) {
115 if (unlikely(is_nan(a)))
116 return var(new precomp_v_vari(NOT_A_NUMBER,
117 b.vi_,
118 NOT_A_NUMBER));
119 return var(a);
120 }
121 if (unlikely(is_nan(a)))
122 return b;
123 return b <= a ? b : var(a);
124 }
125
126 }
127 }
128 #endif
stan::math::fmin
fvar< T > fmin(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmin.hpp:14
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
is_nan.hpp

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