Automatic Differentiation
 
Loading...
Searching...
No Matches
stan::math::var_value< T, internal::require_matrix_var_value< T > > Class Template Reference

Detailed Description

template<typename T>
class stan::math::var_value< T, internal::require_matrix_var_value< T > >

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.

Template Parameters
TAn Floating point type.

Definition at line 320 of file var.hpp.

#include <var.hpp>

Public Types

using value_type = T
 
using vari_type = std::conditional_t< is_plain_type< value_type >::value, vari_value< value_type >, vari_view< T > >
 

Public Member Functions

bool is_uninitialized () noexcept
 Return true if this variable has been declared, but not been defined.
 
 var_value ()
 Construct a variable for later assignment.
 
template<typename S , require_assignable_t< value_type, S > * = nullptr>
 var_value (S &&x)
 Construct a variable from the specified floating point argument by constructing a new vari_value<value_type>.
 
template<typename S , require_assignable_t< vari_type, typename var_value< S >::vari_type > * = nullptr, require_all_plain_type_t< T, S > * = nullptr>
 var_value (const var_value< S > &other)
 Copy constructor for var_val when the vari_type from other is directly assignable.
 
template<typename S , require_not_assignable_t< vari_type, typename var_value< S >::vari_type > * = nullptr, require_constructible_t< vari_type, S > * = nullptr, require_all_plain_type_t< T, S > * = nullptr>
 var_value (const var_value< S > &other)
 Construct from a var_value with different inner vari_type
 
template<typename S , typename T_ = T, require_assignable_t< value_type, S > * = nullptr, require_not_plain_type_t< S > * = nullptr, require_plain_type_t< T_ > * = nullptr>
 var_value (const var_value< S > &other)
 Construct a var_value with a plain type from another var_value containing an expression.
 
template<typename S , typename T_ = T, require_assignable_t< value_type, S > * = nullptr, require_arena_matrix_t< S > * = nullptr>
 var_value (const S &val, const S &adj)
 Construct a var_value with premade arena_matrix types.
 
 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 & val_op () noexcept
 
auto & adj () noexcept
 Return a reference to the derivative of the root expression with respect to this expression.
 
auto & adj () const noexcept
 
auto & adj_op () noexcept
 
Eigen::Index rows () const noexcept
 
Eigen::Index cols () const noexcept
 
Eigen::Index size () const noexcept
 
vari_typeoperator* ()
 Return a reference to underlying implementation of this variable.
 
vari_typeoperator-> ()
 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++).
 
template<typename S , require_st_var< S > * = nullptr>
var_value< T > & operator-= (const S &b)
 The compound subtract/assignment operator for variables (C++).
 
template<typename S , require_st_arithmetic< S > * = nullptr>
var_value< T > & operator-= (const S &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++).
 
auto block (Eigen::Index start_row, Eigen::Index start_col, Eigen::Index num_rows, Eigen::Index num_cols) const
 A block view of the underlying Eigen matrices.
 
auto block (Eigen::Index start_row, Eigen::Index start_col, Eigen::Index num_rows, Eigen::Index num_cols)
 
auto transpose () const
 View transpose of eigen matrix.
 
auto transpose ()
 
auto head (Eigen::Index n) const
 View of the head of Eigen vector types.
 
auto head (Eigen::Index n)
 
auto tail (Eigen::Index n) const
 View of the tail of the Eigen vector types.
 
auto tail (Eigen::Index n)
 
auto segment (Eigen::Index i, Eigen::Index n) const
 View block of N elements starting at position i
 
auto segment (Eigen::Index i, Eigen::Index n)
 
auto row (Eigen::Index i) const
 View row of eigen matrices.
 
auto row (Eigen::Index i)
 
auto col (Eigen::Index i) const
 View column of eigen matrices.
 
auto col (Eigen::Index i)
 
auto diagonal () const
 View diagonal of eigen matrices.
 
auto diagonal ()
 
auto as_column_vector_or_scalar () const
 View a matrix_cl as a column vector.
 
auto as_column_vector_or_scalar ()
 
auto coeff (Eigen::Index i) const
 View element of eigen matrices.
 
auto coeff (Eigen::Index i)
 
auto coeff (Eigen::Index i, Eigen::Index j) const
 View element of eigen matrices.
 
auto coeff (Eigen::Index i, Eigen::Index j)
 
auto operator() (Eigen::Index i) const
 View element of eigen matrices.
 
auto operator() (Eigen::Index i)
 
auto operator() (Eigen::Index i, Eigen::Index j) const
 View element of eigen matrices.
 
auto operator() (Eigen::Index i, Eigen::Index j)
 
auto coeffRef (Eigen::Index i) const
 View element of eigen matrices.
 
auto coeffRef (Eigen::Index i)
 
auto coeffRef (Eigen::Index i, Eigen::Index j) const
 View element of eigen matrices.
 
auto coeffRef (Eigen::Index i, Eigen::Index j)
 
auto rowwise_reverse () const
 Return an expression that operates on the rows of the matrix vari
 
auto rowwise_reverse ()
 
auto colwise_reverse () const
 Return an expression that operates on the columns of the matrix vari
 
auto colwise_reverse ()
 
auto reverse () const
 Return an expression an expression to reverse the order of the coefficients inside of a vari matrix.
 
auto reverse ()
 
auto topRows (Eigen::Index n) const
 Return a block consisting of the top rows.
 
auto topRows (Eigen::Index n)
 
auto bottomRows (Eigen::Index n) const
 Return a block consisting of the bottom rows.
 
auto bottomRows (Eigen::Index n)
 
auto middleRows (Eigen::Index start_row, Eigen::Index n) const
 Return a block consisting of rows in the middle.
 
auto middleRows (Eigen::Index start_row, Eigen::Index n)
 
auto leftCols (Eigen::Index n) const
 Return a block consisting of the left-most columns.
 
auto leftCols (Eigen::Index n)
 
auto rightCols (Eigen::Index n) const
 Return a block consisting of the right-most columns.
 
auto rightCols (Eigen::Index n)
 
auto middleCols (Eigen::Index start_col, Eigen::Index n) const
 Return a block consisting of columns in the middle.
 
auto middleCols (Eigen::Index start_col, Eigen::Index n)
 
auto array () const
 Return an Array.
 
auto array ()
 
auto matrix () const
 Return an Matrix.
 
auto matrix ()
 
template<typename U = T, require_any_t< is_eigen< U >, is_matrix_cl< U > > * = nullptr>
auto rows () const noexcept
 Returns number of rows.
 
template<typename U = T, require_any_t< is_eigen< U >, is_matrix_cl< U > > * = nullptr>
auto cols () const noexcept
 Returns number of columns.
 
template<typename S , require_assignable_t< value_type, S > * = nullptr, require_all_plain_type_t< T, S > * = nullptr, require_same_t< plain_type_t< T >, plain_type_t< S > > * = nullptr>
var_value< T > & operator= (const var_value< S > &other)
 Assignment of another plain var value, when this also contains a plain type.
 
template<typename S , typename T_ = T, require_assignable_t< value_type, S > * = nullptr, require_all_plain_type_t< T_, S > * = nullptr, require_not_same_t< plain_type_t< T_ >, plain_type_t< S > > * = nullptr>
var_value< T > & operator= (const var_value< S > &other)
 Assignment of one plain type to another when one sides compile time columns differ from the other.
 
template<typename S , typename T_ = T, require_assignable_t< value_type, S > * = nullptr, require_not_plain_type_t< S > * = nullptr, require_plain_type_t< T_ > * = nullptr>
var_value< T > & operator= (const var_value< S > &other)
 Assignment of another var value, when the this does not contain a plain type.
 
template<typename S , typename T_ = T, require_assignable_t< value_type, S > * = nullptr, require_not_plain_type_t< T_ > * = nullptr>
var_value< T > & operator= (const var_value< S > &other)
 Assignment of another var value, when either both this or other does not contain a plain type.
 
template<typename T_ = T, require_plain_type_t< T_ > * = nullptr>
auto & eval () noexcept
 No-op to match with Eigen methods which call eval.
 
template<typename T_ = T, require_plain_type_t< T_ > * = nullptr>
const auto & eval () const noexcept
 
template<typename T_ = T, require_not_plain_type_t< T_ > * = nullptr>
auto eval ()
 For non-plain types evaluate to the plain type.
 
template<typename T_ = T, require_not_plain_type_t< T_ > * = nullptr>
auto eval () const
 
var_value< T > & operator= (const var_value< T > &other)
 Copy assignment operator delegates to general assignment operator.
 

Public Attributes

vari_typevi_
 Pointer to the implementation of this variable.
 

Static Public Attributes

static constexpr int RowsAtCompileTime {vari_type::RowsAtCompileTime}
 
static constexpr int ColsAtCompileTime {vari_type::ColsAtCompileTime}
 

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.
 

The documentation for this class was generated from the following files: