| 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
gevv_vvv_vari.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_CORE_GEVV_VVV_VARI_HPP
2 #define STAN_MATH_REV_CORE_GEVV_VVV_VARI_HPP
3
4 #include <stan/math/rev/core/vari.hpp>
5 #include <stan/math/rev/core/var.hpp>
6 #include <stan/math/rev/core/chainablestack.hpp>
7
8 namespace stan {
9 namespace math {
10
11 class gevv_vvv_vari : public stan::math::vari {
12 protected:
13 stan::math::vari* alpha_;
14 stan::math::vari** v1_;
15 stan::math::vari** v2_;
16 double dotval_;
17 size_t length_;
18 inline static double eval_gevv(const stan::math::var* alpha,
19 const stan::math::var* v1, int stride1,
20 const stan::math::var* v2, int stride2,
21 size_t length, double *dotprod) {
22 double result = 0;
23 for (size_t i = 0; i < length; i++)
24 result += v1[i*stride1].vi_->val_ * v2[i*stride2].vi_->val_;
25 *dotprod = result;
26 return alpha->vi_->val_ * result;
27 }
28
29 public:
30 gevv_vvv_vari(const stan::math::var* alpha,
31 const stan::math::var* v1, int stride1,
32 const stan::math::var* v2, int stride2, size_t length) :
33 vari(eval_gevv(alpha, v1, stride1, v2, stride2, length, &dotval_)),
34 length_(length) {
35 alpha_ = alpha->vi_;
36 v1_ = reinterpret_cast<stan::math::vari**>
37 (stan::math::ChainableStack::memalloc_
38 .alloc(2 * length_ * sizeof(stan::math::vari*)));
39 v2_ = v1_ + length_;
40 for (size_t i = 0; i < length_; i++)
41 v1_[i] = v1[i*stride1].vi_;
42 for (size_t i = 0; i < length_; i++)
43 v2_[i] = v2[i*stride2].vi_;
44 }
45 virtual ~gevv_vvv_vari() {}
46 void chain() {
47 const double adj_alpha = adj_ * alpha_->val_;
48 for (size_t i = 0; i < length_; i++) {
49 v1_[i]->adj_ += adj_alpha * v2_[i]->val_;
50 v2_[i]->adj_ += adj_alpha * v1_[i]->val_;
51 }
52 alpha_->adj_ += adj_ * dotval_;
53 }
54 };
55
56 }
57 }
58
59 #endif
stan::math::gevv_vvv_vari::~gevv_vvv_vari
virtual ~gevv_vvv_vari()
Definition: gevv_vvv_vari.hpp:45
vari.hpp
stan::math::AutodiffStackStorage::memalloc_
static stack_alloc memalloc_
Definition: autodiffstackstorage.hpp:16
stan::math::vari
The variable implementation base class.
Definition: vari.hpp:28
stan::length
size_t length(const std::vector< T > &x)
Definition: length.hpp:10
stan::math::gevv_vvv_vari::eval_gevv
static double eval_gevv(const stan::math::var *alpha, const stan::math::var *v1, int stride1, const stan::math::var *v2, int stride2, size_t length, double *dotprod)
Definition: gevv_vvv_vari.hpp:18
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
stan::math::vari::val_
const double val_
The value of this variable.
Definition: vari.hpp:36
stan::math::gevv_vvv_vari
Definition: gevv_vvv_vari.hpp:11
stan::math::gevv_vvv_vari::alpha_
stan::math::vari * alpha_
Definition: gevv_vvv_vari.hpp:13
stan::math::gevv_vvv_vari::dotval_
double dotval_
Definition: gevv_vvv_vari.hpp:16
stan::math::gevv_vvv_vari::v1_
stan::math::vari ** v1_
Definition: gevv_vvv_vari.hpp:14
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:44
var.hpp
stan::math::gevv_vvv_vari::gevv_vvv_vari
gevv_vvv_vari(const stan::math::var *alpha, const stan::math::var *v1, int stride1, const stan::math::var *v2, int stride2, size_t length)
Definition: gevv_vvv_vari.hpp:30
stan::math::gevv_vvv_vari::v2_
stan::math::vari ** v2_
Definition: gevv_vvv_vari.hpp:15
stan::math::gevv_vvv_vari::length_
size_t length_
Definition: gevv_vvv_vari.hpp:17
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::stack_alloc::alloc
void * alloc(size_t len)
Return a newly allocated block of memory of the appropriate size managed by the stack allocator...
Definition: stack_alloc.hpp:170
stan::math::gevv_vvv_vari::chain
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Definition: gevv_vvv_vari.hpp:46

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