All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
operator_multiplication.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_REV_CORE_OPERATOR_MULTIPLICATION_HPP
#define STAN_MATH_REV_CORE_OPERATOR_MULTIPLICATION_HPP
#include <stan/math/rev/core/var.hpp>
#include <stan/math/rev/core/vv_vari.hpp>
#include <stan/math/rev/core/vd_vari.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
#include <limits>
namespace stan {
namespace math {
namespace {
class multiply_vv_vari : public op_vv_vari {
public:
multiply_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_ += bvi_->val_ * adj_;
bvi_->adj_ += avi_->val_ * adj_;
}
}
};
class multiply_vd_vari : public op_vd_vari {
public:
multiply_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_ * bd_;
}
};
}
inline var operator*(const var& a, const var& b) {
return var(new multiply_vv_vari(a.vi_, b.vi_));
}
inline var operator*(const var& a, const double b) {
if (b == 1.0)
return a;
return var(new multiply_vd_vari(a.vi_, b));
}
inline var operator*(const double a, const var& b) {
if (a == 1.0)
return b;
return var(new multiply_vd_vari(b.vi_, a)); // by symmetry
}
}
}
#endif
vd_vari.hpp
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
unlikely
#define unlikely(x)
Definition: likely.hpp:9
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:44
var.hpp
vv_vari.hpp
stan::math::operator*
fvar< T > operator*(const fvar< T > &x1, const fvar< T > &x2)
Definition: operator_multiplication.hpp:14

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