Stan Math Library
4.8.1
Automatic Differentiation
|
Independent (input) and dependent (output) variables for gradients.
This class acts as a smart pointer, with resources managed by an arena-based memory manager scoped to a single gradient calculation.
A var is constructed with a type T
and used like any other scalar. Arithmetical functions like negation, addition, and subtraction, as well as a range of mathematical functions like exponentiation and powers are overridden to operate on var values objects.
T | An Floating point type. |
#include <var.hpp>
Public Types | |
using | value_type = std::decay_t< T > |
using | vari_type = vari_value< value_type > |
Public Member Functions | |
bool | is_uninitialized () |
Return true if this variable has been declared, but not been defined. | |
var_value () | |
Construct a variable for later assignment. | |
template<typename S , require_convertible_t< S &, value_type > * = nullptr> | |
var_value (S x) | |
Construct a variable from the specified floating point argument by constructing a new vari_value<value_type> . | |
var_value (vari_type *vi) | |
Construct a variable from a pointer to a variable implementation. | |
const auto & | val () const noexcept |
Return a constant reference to the value of this variable. | |
auto & | adj () const noexcept |
Return a reference of the derivative of the root expression with respect to this expression. | |
auto & | adj () noexcept |
Return a reference to the derivative of the root expression with respect to this expression. | |
void | grad (std::vector< var_value< T > > &x, std::vector< value_type > &g) |
Compute the gradient of this (dependent) variable with respect to the specified vector of (independent) variables, assigning the specified vector to the gradient. | |
void | grad () |
Compute the gradient of this (dependent) variable with respect to all (independent) variables. | |
vari_type & | operator* () |
Return a reference to underlying implementation of this variable. | |
vari_type * | operator-> () |
Return a pointer to the underlying implementation of this variable. | |
var_value< T > & | operator+= (const var_value< T > &b) |
The compound add/assignment operator for variables (C++). | |
var_value< T > & | operator+= (T b) |
The compound add/assignment operator for scalars (C++). | |
var_value< T > & | operator-= (const var_value< T > &b) |
The compound subtract/assignment operator for variables (C++). | |
var_value< T > & | operator-= (T b) |
The compound subtract/assignment operator for scalars (C++). | |
var_value< T > & | operator*= (const var_value< T > &b) |
The compound multiply/assignment operator for variables (C++). | |
var_value< T > & | operator*= (T b) |
The compound multiply/assignment operator for scalars (C++). | |
var_value< T > & | operator/= (const var_value< T > &b) |
The compound divide/assignment operator for variables (C++). | |
var_value< T > & | operator/= (T b) |
The compound divide/assignment operator for scalars (C++). | |
Public Attributes | |
vari_type * | vi_ |
Pointer to the implementation of this variable. | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const var_value< T > &v) |
Write the value of this autodiff variable and its adjoint to the specified output stream. | |