All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
multiply_log.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_REV_SCAL_FUN_MULTIPLY_LOG_HPP
#define STAN_MATH_REV_SCAL_FUN_MULTIPLY_LOG_HPP
#include <stan/math/rev/core.hpp>
#include <stan/math/rev/scal/fun/log.hpp>
#include <stan/math/prim/scal/fun/multiply_log.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
#include <limits>
namespace stan {
namespace math {
namespace {
class multiply_log_vv_vari : public op_vv_vari {
public:
multiply_log_vv_vari(vari* avi, vari* bvi) :
op_vv_vari(stan::math::multiply_log(avi->val_, bvi->val_), avi, bvi) {
}
void chain() {
using std::log;
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_ * log(bvi_->val_);
if (bvi_->val_ == 0.0 && avi_->val_ == 0)
bvi_->adj_ += adj_ * std::numeric_limits<double>::infinity();
else
bvi_->adj_ += adj_ * avi_->val_ / bvi_->val_;
}
}
};
class multiply_log_vd_vari : public op_vd_vari {
public:
multiply_log_vd_vari(vari* avi, double b) :
op_vd_vari(stan::math::multiply_log(avi->val_, b), avi, b) {
}
void chain() {
using std::log;
if (unlikely(boost::math::isnan(avi_->val_)
|| boost::math::isnan(bd_)))
avi_->adj_ = std::numeric_limits<double>::quiet_NaN();
else
avi_->adj_ += adj_ * log(bd_);
}
};
class multiply_log_dv_vari : public op_dv_vari {
public:
multiply_log_dv_vari(double a, vari* bvi) :
op_dv_vari(stan::math::multiply_log(a, bvi->val_), a, bvi) {
}
void chain() {
if (bvi_->val_ == 0.0 && ad_ == 0.0)
bvi_->adj_ += adj_ * std::numeric_limits<double>::infinity();
else
bvi_->adj_ += adj_ * ad_ / bvi_->val_;
}
};
}
inline var multiply_log(const var& a, const var& b) {
return var(new multiply_log_vv_vari(a.vi_, b.vi_));
}
inline var multiply_log(const var& a, const double b) {
return var(new multiply_log_vd_vari(a.vi_, b));
}
inline var multiply_log(const double a, const var& b) {
if (a == 1.0)
return log(b);
return var(new multiply_log_dv_vari(a, b.vi_));
}
}
}
#endif
core.hpp
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
boost::math::isnan
bool isnan(const stan::math::var &v)
Checks if the given number is NaN.
Definition: boost_isnan.hpp:22
multiply_log.hpp
unlikely
#define unlikely(x)
Definition: likely.hpp:9
log.hpp
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:44
stan::math::multiply_log
fvar< T > multiply_log(const fvar< T > &x1, const fvar< T > &x2)
Definition: multiply_log.hpp:15

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