| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
var.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_CORE_VAR_HPP
2 #define STAN_MATH_REV_CORE_VAR_HPP
3
4 #include <stan/math/rev/core/vari.hpp>
5 #include <stan/math/rev/core/grad.hpp>
6 #include <stan/math/rev/core/chainable.hpp>
7 #include <stan/math/rev/core/chainable_alloc.hpp>
8 #include <boost/math/tools/config.hpp>
9 #include <ostream>
10 #include <vector>
11
12 namespace stan {
13
14 namespace math {
15
16 // forward declare
17 static void grad(chainable* vi);
18
32 class var {
33 public:
34 // FIXME: doc what this is for
35 typedef double Scalar;
36
44 vari * vi_;
45
55 bool is_uninitialized() {
56 return (vi_ == static_cast<vari*>(0U));
57 }
58
66 var() : vi_(static_cast<vari*>(0U)) { }
67
68
74 var(vari* vi) : vi_(vi) { } // NOLINT
75
83 var(float x) : vi_(new vari(static_cast<double>(x))) { } // NOLINT
84
92 var(double x) : vi_(new vari(x)) { } // NOLINT
93
101 var(long double x) : vi_(new vari(x)) { } // NOLINT
102
110 var(bool x) : vi_(new vari(static_cast<double>(x))) { } // NOLINT
111
119 var(char x) : vi_(new vari(static_cast<double>(x))) { } // NOLINT
120
128 var(short x) : vi_(new vari(static_cast<double>(x))) { } // NOLINT
129
137 var(int x) : vi_(new vari(static_cast<double>(x))) { } // NOLINT
138
146 var(long x) : vi_(new vari(static_cast<double>(x))) { } // NOLINT
147
155 var(unsigned char x) : vi_(new vari(static_cast<double>(x))) { } // NOLINT
156
164 // NOLINTNEXTLINE
165 var(unsigned short x) : vi_(new vari(static_cast<double>(x))) { }
166
174 var(unsigned int x) : vi_(new vari(static_cast<double>(x))) { } // NOLINT
175
183 // NOLINTNEXTLINE
184 var(unsigned long x) : vi_(new vari(static_cast<double>(x))) { } // NOLINT
185
186 #ifdef _WIN64
187
188 // these two ctors are for Win64 to enable 64-bit signed
189 // and unsigned integers, because long and unsigned long
190 // are still 32-bit
191
199 var(size_t x) : vi_(new vari(static_cast<double>(x))) { } // NOLINT
200
201
209 var(ptrdiff_t x) : vi_(new vari(static_cast<double>(x))) { } // NOLINT
210 #endif
211
212
213 #ifdef BOOST_MATH_USE_FLOAT128
214
215 // this ctor is for later GCCs that have the __float128
216 // type enabled, because it gets enabled by boost
217
225 var(__float128 x) : vi_(new vari(static_cast<double>(x))) { } // NOLINT
226
227 #endif
228
234 inline double val() const {
235 return vi_->val_;
236 }
237
246 inline double adj() const {
247 return vi_->adj_;
248 }
249
262 void grad(std::vector<var>& x,
263 std::vector<double>& g) {
264 stan::math::grad(vi_); // defined in chainable.hpp
265 g.resize(x.size());
266 for (size_t i = 0; i < x.size(); ++i)
267 g[i] = x[i].vi_->adj_;
268 }
269
276 void grad() {
277 stan::math::grad(vi_); // defined in chainable.hpp
278 }
279
280 // POINTER OVERRIDES
281
294 inline vari& operator*() {
295 return *vi_;
296 }
297
308 inline vari* operator->() {
309 return vi_;
310 }
311
312 // COMPOUND ASSIGNMENT OPERATORS
313
324 inline var& operator+=(const var& b);
325
336 inline var& operator+=(const double b);
337
349 inline var& operator-=(const var& b);
350
362 inline var& operator-=(const double b);
363
375 inline var& operator*=(const var& b);
376
388 inline var& operator*=(const double b);
389
400 inline var& operator/=(const var& b);
401
413 inline var& operator/=(const double b);
414
423 friend std::ostream& operator<<(std::ostream& os, const var& v) {
424 if (v.vi_ == 0)
425 return os << "uninitialized";
426 return os << v.val();
427 }
428 };
429
430 }
431 }
432 #endif
stan::math::var::operator+=
var & operator+=(const var &b)
The compound add/assignment operator for variables (C++).
Definition: operator_plus_equal.hpp:10
stan::math::var::operator*=
var & operator*=(const var &b)
The compound multiply/assignment operator for variables (C++).
Definition: operator_multiply_equal.hpp:10
stan::math::var::var
var(unsigned char x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
Definition: var.hpp:155
vari.hpp
stan::math::var::var
var(long x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
Definition: var.hpp:146
stan::math::var::operator/=
var & operator/=(const var &b)
The compound divide/assignment operator for variables (C++).
Definition: operator_divide_equal.hpp:10
stan::math::var::var
var(unsigned long x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
Definition: var.hpp:184
stan::math::vari
The variable implementation base class.
Definition: vari.hpp:28
chainable.hpp
stan::math::grad
static void grad(chainable *vi)
Compute the gradient for all variables starting from the specified root variable implementation.
Definition: grad.hpp:30
grad.hpp
stan::math::var::var
var(vari *vi)
Construct a variable from a pointer to a variable implementation.
Definition: var.hpp:74
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
stan::math::var::operator*
vari & operator*()
Return a reference to underlying implementation of this variable.
Definition: var.hpp:294
stan::math::var::operator-=
var & operator-=(const var &b)
The compound subtract/assignment operator for variables (C++).
Definition: operator_minus_equal.hpp:10
stan::math::vari::val_
const double val_
The value of this variable.
Definition: vari.hpp:36
stan::math::var::var
var(double x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
Definition: var.hpp:92
stan::math::var::var
var(bool x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
Definition: var.hpp:110
stan::math::var::var
var(char x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
Definition: var.hpp:119
stan::math::var::is_uninitialized
bool is_uninitialized()
Return true if this variable has been declared, but not been defined.
Definition: var.hpp:55
stan::math::var::var
var(unsigned int x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
Definition: var.hpp:174
stan::math::var::var
var()
Construct a variable for later assignment.
Definition: var.hpp:66
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:44
chainable_alloc.hpp
stan::math::var::var
var(float x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
Definition: var.hpp:83
stan::math::var::grad
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...
Definition: var.hpp:262
stan::math::var::operator->
vari * operator->()
Return a pointer to the underlying implementation of this variable.
Definition: var.hpp:308
stan::math::var::grad
void grad()
Compute the gradient of this (dependent) variable with respect to all (independent) variables...
Definition: var.hpp:276
stan::math::var::var
var(long double x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
Definition: var.hpp:101
stan::math::var::var
var(int x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
Definition: var.hpp:137
stan::math::var::Scalar
double Scalar
Definition: var.hpp:35
stan::math::vari::adj_
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
Definition: vari.hpp:42
stan::math::var::val
double val() const
Return the value of this variable.
Definition: var.hpp:234
stan::math::var::operator<<
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...
Definition: var.hpp:423
stan::math::var::adj
double adj() const
Return the derivative of the root expression with respect to this expression.
Definition: var.hpp:246
stan::math::var::var
var(unsigned short x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
Definition: var.hpp:165
stan::math::var::var
var(short x)
Construct a variable from the specified arithmetic argument by constructing a new vari with the argum...
Definition: var.hpp:128

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