1 #ifndef STAN_MATH_REV_CORE_VAR_HPP
2 #define STAN_MATH_REV_CORE_VAR_HPP
7 #include <boost/math/tools/config.hpp>
15 static void grad(vari* vi);
54 return (vi_ == static_cast<vari*>(0U));
80 var(
float x) : vi_(new
vari(static_cast<double>(x))) { }
107 var(
bool x) : vi_(new
vari(static_cast<double>(x))) { }
116 var(
char x) : vi_(new
vari(static_cast<double>(x))) { }
125 var(
short x) : vi_(new
vari(static_cast<double>(x))) { }
134 var(
int x) : vi_(new
vari(static_cast<double>(x))) { }
143 var(
long x) : vi_(new
vari(static_cast<double>(x))) { }
152 var(
unsigned char x) : vi_(new
vari(static_cast<double>(x))) { }
162 var(
unsigned short x) : vi_(new
vari(static_cast<double>(x))) { }
171 var(
unsigned int x) : vi_(new
vari(static_cast<double>(x))) { }
181 var(
unsigned long x) : vi_(new
vari(static_cast<double>(x))) { }
196 var(
size_t x) : vi_(new
vari(static_cast<double>(x))) { }
205 var(ptrdiff_t x) : vi_(new vari(static_cast<double>(x))) { }
208 #ifdef BOOST_MATH_USE_FLOAT128
220 var(__float128 x) : vi_(new vari(static_cast<double>(x))) { }
229 inline double val()
const {
241 inline double adj()
const {
258 std::vector<double>& g) {
261 for (
size_t i = 0; i < x.size(); ++i)
262 g[i] = x[i].vi_->
adj_;
420 return os <<
"uninitialized";
421 return os << v.
val();
var & operator+=(const var &b)
The compound add/assignment operator for variables (C++).
var & operator*=(const var &b)
The compound multiply/assignment operator for variables (C++).
var(unsigned char x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
var(long x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
var & operator/=(const var &b)
The compound divide/assignment operator for variables (C++).
var(unsigned long x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
The variable implementation base class.
var(vari *vi)
Construct a variable from a pointer to a variable implementation.
Independent (input) and dependent (output) variables for gradients.
vari & operator*()
Return a reference to underlying implementation of this variable.
static void grad(vari *vi)
Compute the gradient for all variables starting from the specified root variable implementation.
var & operator-=(const var &b)
The compound subtract/assignment operator for variables (C++).
const double val_
The value of this variable.
var(double x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
var(bool x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
var(char x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
bool is_uninitialized()
Return true if this variable has been declared, but not been defined.
var(unsigned int x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
var()
Construct a variable for later assignment.
vari * vi_
Pointer to the implementation of this variable.
var(float x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
void grad(std::vector< var > &x, std::vector< double > &g)
Compute the gradient of this (dependent) variable with respect to the specified vector of (independen...
vari * operator->()
Return a pointer to the underlying implementation of this variable.
void grad()
Compute the gradient of this (dependent) variable with respect to all (independent) variables...
var(long double x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
var(int x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
double val() const
Return the value of this variable.
friend std::ostream & operator<<(std::ostream &os, const var &v)
Write the value of this auto-dif variable and its adjoint to the specified output stream...
double adj() const
Return the derivative of the root expression with respect to this expression.
var(unsigned short x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
var(short x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...