Go to the documentation of this file.
3
7 #include <algorithm>
8 #include <vector>
9
10 namespace stan {
11 namespace math {
12
13 /**
14  * A variable implementation taking a sequence of operands and
15  * partial derivatives with respect to the operands.
16  *
17  * Stan users should use function precomputed_gradients()
18  * directly.
19  */
21  protected:
22  const size_t size_;
25
26  public:
27  /**
28  * Construct a precomputed vari with the specified value,
30  *
31  * @param[in] val The value of the variable.
32  * @param[in] size Size of operands and gradients
33  * @param[in] varis Operand implementations.
35  */
36  precomputed_gradients_vari(double val, size_t size, vari** varis,
39
40  /**
41  * Construct a precomputed vari with the specified value,
43  *
44  * @param[in] val The value of the variable.
45  * @param[in] vars Vector of operands.
46  * @param[in] gradients Vector of partial derivatives of value
47  * with respect to operands.
48  * @throws std::invalid_argument if the sizes of the vectors
49  * don't match.
50  */
51  precomputed_gradients_vari(double val, const std::vector<var>& vars,
53  : vari(val),
54  size_(vars.size()),
55  varis_(ChainableStack::instance().memalloc_.alloc_array<vari*>(
56  vars.size())),
58  vars.size())) {
61  for (size_t i = 0; i < vars.size(); ++i)
62  varis_[i] = vars[i].vi_;
64  }
65
66  /**
67  * Implements the chain rule for this variable, using the
68  * prestored operands and gradient.
69  */
70  void chain() {
71  for (size_t i = 0; i < size_; ++i)
73  }
74 };
75
76 /**
77  * This function returns a var for an expression that has the
78  * specified value, vector of operands, and vector of partial
79  * derivatives of value with respect to the operands.
80  *
81  * @param[in] value The value of the resulting dependent variable.
82  * @param[in] operands operands.
83  * @param[in] gradients vector of partial derivatives of result with
84  * respect to operands.
85  * @return An auto-diff variable that uses the precomputed
87  */
88 inline var precomputed_gradients(double value, const std::vector<var>& operands,
91 }
92 } // namespace math
93 } // namespace stan
94 #endif
friend class var
Definition: vari.hpp:32
precomputed_gradients_vari(double val, const std::vector< var > &vars, const std::vector< double > &gradients)
const XML_Char int const XML_Char * value
Definition: expat.h:331
var precomputed_gradients(double value, const std::vector< var > &operands, const std::vector< double > &gradients)
const std::map< std::pair< std::string, std::string >, Variable > vars
int size(const std::vector< T > &x)
Definition: size.hpp:17