Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fmax.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__FUNCTIONS__FMAX_HPP
2 #define STAN__AGRAD__REV__FUNCTIONS__FMAX_HPP
3 
4 #include <stan/agrad/rev/var.hpp>
5 #include <boost/math/special_functions/fpclassify.hpp>
9 #include <stan/meta/likely.hpp>
10 
11 namespace stan {
12  namespace agrad {
13 
64  inline var fmax(const stan::agrad::var& a,
65  const stan::agrad::var& b) {
67  if(boost::math::isnan(b.vi_->val_)) {
68  std::vector<stan::agrad::var> vars;
69  std::vector<double> grads;
70  vars.push_back(a);
71  vars.push_back(b);
72  grads.push_back(stan::math::NOT_A_NUMBER);
73  grads.push_back(stan::math::NOT_A_NUMBER);
75  vars, grads));
76  }
77  else
78  return b;
79  } else if (unlikely(boost::math::isnan(b.vi_->val_)))
80  return a;
81  else
82  return a.vi_->val_ > b.vi_->val_ ? a : b;
83  }
84 
101  inline var fmax(const stan::agrad::var& a,
102  const double& b) {
103  if (unlikely(boost::math::isnan(a.vi_->val_))) {
104  if(boost::math::isnan(b))
106  a.vi_,
108  else
109  return var(b);
110  } else if (unlikely(boost::math::isnan(b)))
111  return a;
112  else
113  return a.vi_->val_ >= b ? a : var(b);
114  }
115 
132  inline var fmax(const double& a,
133  const stan::agrad::var& b) {
134  if (unlikely(boost::math::isnan(b.vi_->val_))) {
135  if(boost::math::isnan(a))
137  b.vi_,
139  else
140  return var(a);
141  } else if (unlikely(boost::math::isnan(a)))
142  return b;
143  else
144  return a > b.vi_->val_ ? var(a) : b;
145  }
146 
147  }
148 }
149 #endif
bool isnan(const stan::agrad::var &v)
Checks if the given number is NaN.
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition: constants.hpp:53
var precomputed_gradients(const double value, const std::vector< var > &vars, const std::vector< double > &gradients)
This function is provided for Stan users that want to compute gradients without using Stan's auto-dif...
const double val_
The value of this variable.
Definition: vari.hpp:37
fvar< T > fmax(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmax.hpp:17
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:40
#define unlikely(x)
Definition: likely.hpp:9
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:27

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