Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
square.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__FUNCTIONS__SQUARE_HPP
2 #define STAN__AGRAD__REV__FUNCTIONS__SQUARE_HPP
3 
4 #include <stan/agrad/rev/var.hpp>
6 
7 namespace stan {
8  namespace agrad {
9 
10  namespace {
11  class square_vari : public op_v_vari {
12  public:
13  square_vari(vari* avi) :
14  op_v_vari(avi->val_ * avi->val_,avi) {
15  }
16  void chain() {
17  avi_->adj_ += adj_ * 2.0 * avi_->val_;
18  }
19  };
20  }
21 
47  inline var square(const var& x) {
48  return var(new square_vari(x.vi_));
49  }
50 
51  }
52 }
53 #endif
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:15
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:40
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:27

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