Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fmin.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__FUNCTIONS__FMIN_HPP
2 #define STAN__AGRAD__REV__FUNCTIONS__FMIN_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 
60  inline var fmin(const stan::agrad::var& a,
61  const stan::agrad::var& b) {
63  if(boost::math::isnan(b.vi_->val_)) {
64  std::vector<stan::agrad::var> vars;
65  std::vector<double> grads;
66  vars.push_back(a);
67  vars.push_back(b);
68  grads.push_back(stan::math::NOT_A_NUMBER);
69  grads.push_back(stan::math::NOT_A_NUMBER);
71  vars, grads));
72  }
73  else
74  return b;
75  } else if (unlikely(boost::math::isnan(b.vi_->val_)))
76  return a;
77  else
78  return a.vi_->val_ < b.vi_->val_ ? a : b;
79  }
80 
95  inline var fmin(const stan::agrad::var& a,
96  const double& b) {
98  if(boost::math::isnan(b))
100  a.vi_,
102  else
103  return var(b);
104  } else if (unlikely(boost::math::isnan(b)))
105  return a;
106  else
107  return a.vi_->val_ <= b ? a : var(b);
108  }
109 
126  inline var fmin(const double& a,
127  const stan::agrad::var& b) {
128  if (unlikely(boost::math::isnan(b.vi_->val_))) {
129  if(boost::math::isnan(a))
131  b.vi_,
133  else
134  return var(a);
135  } else if (unlikely(boost::math::isnan(a)))
136  return b;
137  else
138  return a < b.vi_->val_ ? var(a) : b;
139  }
140 
141  }
142 }
143 #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
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:40
#define unlikely(x)
Definition: likely.hpp:9
fvar< T > fmin(const fvar< T > &x1, const fvar< T > &x2)
Definition: fmin.hpp:17
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:27

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