| 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
vari.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_CORE_VARI_HPP
2 #define STAN_MATH_REV_CORE_VARI_HPP
3
4 #include <stan/math/rev/core/chainable.hpp>
5 #include <stan/math/rev/core/chainable_alloc.hpp>
6 #include <stan/math/rev/core/chainablestack.hpp>
7 #include <ostream>
8
9 namespace stan {
10 namespace math {
11
12 // forward declaration of var
13 class var;
14
28 class vari : public chainable {
29 private:
30 friend class var;
31
32 public:
36 const double val_;
37
42 double adj_;
43
56 explicit vari(const double x):
57 val_(x),
58 adj_(0.0) {
59 ChainableStack::var_stack_.push_back(this);
60 }
61
62 vari(const double x, bool stacked):
63 val_(x),
64 adj_(0.0) {
65 if (stacked)
66 ChainableStack::var_stack_.push_back(this);
67 else
68 ChainableStack::var_nochain_stack_.push_back(this);
69 }
70
78 virtual ~vari() {
79 // throw std::logic_error("vari destruction handled automatically");
80 }
81
87 virtual void init_dependent() {
88 adj_ = 1.0; // droot/droot = 1
89 }
90
94 virtual void set_zero_adjoint() {
95 adj_ = 0.0;
96 }
97
107 friend std::ostream& operator<<(std::ostream& os, const vari* v) {
108 return os << v->val_ << ":" << v->adj_;
109 }
110 };
111
112 }
113 }
114 #endif
stan::math::vari::vari
vari(const double x)
Construct a variable implementation from a value.
Definition: vari.hpp:56
stan::math::vari::operator<<
friend std::ostream & operator<<(std::ostream &os, const vari *v)
Insertion operator for vari.
Definition: vari.hpp:107
stan::math::chainable
Abstract base class for variable implementations that handles memory management and applying the chai...
Definition: chainable.hpp:14
stan::math::vari
The variable implementation base class.
Definition: vari.hpp:28
chainable.hpp
stan::math::vari::init_dependent
virtual void init_dependent()
Initialize the adjoint for this (dependent) variable to 1.
Definition: vari.hpp:87
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
stan::math::vari::~vari
virtual ~vari()
Throw an illegal argument exception.
Definition: vari.hpp:78
stan::math::vari::val_
const double val_
The value of this variable.
Definition: vari.hpp:36
stan::math::vari::vari
vari(const double x, bool stacked)
Definition: vari.hpp:62
stan::math::AutodiffStackStorage::var_nochain_stack_
static std::vector< ChainableT * > var_nochain_stack_
Definition: autodiffstackstorage.hpp:14
chainable_alloc.hpp
stan::math::vari::set_zero_adjoint
virtual void set_zero_adjoint()
Set the adjoint value of this variable to 0.
Definition: vari.hpp:94
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
chainablestack.hpp
stan::math::AutodiffStackStorage::var_stack_
static std::vector< ChainableT * > var_stack_
Definition: autodiffstackstorage.hpp:13

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