All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
fdim.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_REV_SCAL_FUN_FDIM_HPP
#define STAN_MATH_REV_SCAL_FUN_FDIM_HPP
#include <stan/math/rev/core.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
#include <stan/math/prim/scal/meta/likely.hpp>
#include <limits>
namespace stan {
namespace math {
namespace {
class fdim_vv_vari : public op_vv_vari {
public:
fdim_vv_vari(vari* avi, vari* bvi) :
op_vv_vari(avi->val_ - bvi->val_, avi, bvi) {
}
void chain() {
if (unlikely(boost::math::isnan(avi_->val_)
|| boost::math::isnan(bvi_->val_))) {
avi_->adj_ = std::numeric_limits<double>::quiet_NaN();
bvi_->adj_ = std::numeric_limits<double>::quiet_NaN();
} else {
avi_->adj_ += adj_;
bvi_->adj_ -= adj_;
}
}
};
class fdim_vd_vari : public op_vd_vari {
public:
fdim_vd_vari(vari* avi, double b) :
op_vd_vari(avi->val_ - b, avi, b) {
}
void chain() {
if (unlikely(boost::math::isnan(avi_->val_)
|| boost::math::isnan(bd_)))
avi_->adj_ = std::numeric_limits<double>::quiet_NaN();
else
avi_->adj_ += adj_;
}
};
class fdim_dv_vari : public op_dv_vari {
public:
fdim_dv_vari(double a, vari* bvi) :
op_dv_vari(a - bvi->val_, a, bvi) {
}
void chain() {
if (unlikely(boost::math::isnan(bvi_->val_)
|| boost::math::isnan(ad_)))
bvi_->adj_ = std::numeric_limits<double>::quiet_NaN();
else
bvi_->adj_ -= adj_;
}
};
}
inline var fdim(const stan::math::var& a,
const stan::math::var& b) {
if (!(a.vi_->val_ <= b.vi_->val_))
return var(new fdim_vv_vari(a.vi_, b.vi_));
else
return var(new vari(0.0));
}
inline var fdim(const double& a,
const stan::math::var& b) {
return a <= b.vi_->val_
? var(new vari(0.0))
: var(new fdim_dv_vari(a, b.vi_));
}
inline var fdim(const stan::math::var& a,
const double& b) {
return a.vi_->val_ <= b
? var(new vari(0.0))
: var(new fdim_vd_vari(a.vi_, b));
}
}
}
#endif
core.hpp
stan::math::vari
The variable implementation base class.
Definition: vari.hpp:28
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
stan::math::vari::val_
const double val_
The value of this variable.
Definition: vari.hpp:36
boost::math::isnan
bool isnan(const stan::math::var &v)
Checks if the given number is NaN.
Definition: boost_isnan.hpp:22
unlikely
#define unlikely(x)
Definition: likely.hpp:9
stan::math::fdim
fvar< T > fdim(const fvar< T > &x1, const fvar< T > &x2)
Definition: fdim.hpp:11
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:44
likely.hpp

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