Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
stored_gradient_vari.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__MATRIX__STORED_GRADIENT_HPP
2 #define STAN__AGRAD__REV__MATRIX__STORED_GRADIENT_HPP
3 
5 
6 namespace stan {
7 
8  namespace agrad {
9 
18  class stored_gradient_vari : public vari {
19 
20  protected:
21 
22  size_t size_;
24  double* partials_;
25 
26  public:
27 
38  stored_gradient_vari(double value,
39  size_t size,
40  vari** dtrs,
41  double* partials)
42  : vari(value),
43  size_(size),
44  dtrs_(dtrs),
45  partials_(partials) {
46  }
47 
52  void chain() {
53  for (size_t i = 0; i < size_; ++i)
54  dtrs_[i]->adj_ += adj_ * partials_[i];
55  }
56  };
57 
58  }
59 }
60 
61 #endif
void chain()
Propagate derivatives through this vari with partial derivatives given for the daughter vari by the s...
A var implementation that stores the daughter variable implementation pointers and the partial deriva...
The variable implementation base class.
Definition: vari.hpp:28
int size(const std::vector< T > &x)
Definition: size.hpp:11
stored_gradient_vari(double value, size_t size, vari **dtrs, double *partials)
Construct a stored gradient vari with the specified value, size, daughter varis, and partial derivati...
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
Definition: vari.hpp:43

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