NEML2 1.4.0
|
Concrete definition of a variable. More...
Concrete definition of a variable.
#include <Variable.h>
Public Member Functions | |
template<typename T2 = T, typename = typename std::enable_if_t<!std::is_same_v<Tensor, T2>>> | |
Variable (const VariableName &name_in, const Model *owner, TensorType type=TensorTypeEnum< T2 >::value) | |
template<typename T2 = T, typename = typename std::enable_if_t<std::is_same_v<Tensor, T2>>> | |
Variable (const VariableName &name_in, const Model *owner, TensorShapeRef base_shape, TensorType type=TensorType::kTensor) | |
virtual void | setup_views (const LabeledVector *value, const LabeledMatrix *deriv=nullptr, const LabeledTensor3D *secderiv=nullptr) override |
Setup the variable's views into blocks of the storage. | |
virtual void | setup_views (const VariableBase *other) override |
Setup the variable's views following another variable. | |
virtual void | requires_grad_ (bool req=true) override |
Set requires_grad for the underlying storage. | |
virtual TensorShapeRef | base_sizes () const override |
Base shape. | |
virtual TensorShapeRef | sizes () const override |
Total shape. | |
Variable (const Variable< T > &) | |
Suppressed constructor to prevent accidental dereferencing. | |
void | operator= (const Variable< T > &) |
Suppressed assignment operator to prevent accidental dereferencing. | |
void | operator= (const Tensor &val) |
Set the raw value to store val . | |
const T & | value () const |
Variable value of the logical shape. | |
virtual const Tensor | tensor () const override |
Variable value of the logical shape. | |
virtual TensorType | type () const override |
Variable type. | |
T | operator- () const |
Negation. | |
operator T () const | |
virtual void | cache (TensorShapeRef batch_shape) override |
Set the batch shape and base shape according to val . | |
template<typename T2 = T, typename = typename std::enable_if_t<!std::is_same_v<T2, Tensor>>> | |
operator Tensor () const | |
Public Member Functions inherited from VariableBase | |
VariableBase (const VariableName &name_in, const Model *owner) | |
virtual | ~VariableBase ()=default |
Derivative | d (const VariableBase &x) |
Create a wrapper representing the derivative dy/dx. | |
Derivative | d (const VariableBase &x1, const VariableBase &x2) |
Create a wrapper representing the second derivative d2y/dx2. | |
const Tensor & | raw_value () const |
Raw flattened variable value. | |
const VariableName & | name () const |
Name of this variable. | |
const Model & | owner () const |
The owner of this variable. | |
const VariableBase * | src () const |
The source variable. | |
TensorShapeRef | batch_sizes () const |
Batch shape. | |
Size | batch_dim () const |
Batch dimension. | |
Size | base_dim () const |
Base dimension. | |
Size | base_storage () const |
Base storage. | |
bool | is_dependent () const |
Check if the derivative with respect to this variable should be evaluated. | |
bool | is_state () const |
bool | is_old_state () const |
bool | is_force () const |
bool | is_old_force () const |
bool | is_residual () const |
bool | is_parameter () const |
bool | is_other () const |
bool | is_solve_dependent () const |
Protected Attributes | |
const TensorType | _type |
Variable tensor type. | |
const TensorShape | _base_sizes |
Base shape of this variable. | |
TensorShape | _sizes |
Shape of this variable. | |
T | _value |
Variable value of the logical shape. | |
Protected Attributes inherited from VariableBase | |
const VariableName | _name |
Name of the variable. | |
const Model * | _owner |
The model which declared this variable. | |
TensorShape | _batch_sizes |
Batch shape of this variable. | |
Tensor | _raw_value |
The raw (flattened) variable value. | |
std::map< VariableName, Tensor > | _dvalue_d |
The derivative of this variable w.r.t. arguments. | |
std::map< VariableName, std::map< VariableName, Tensor > > | _d2value_d |
The second derivative of this variable w.r.t. arguments. | |
const VariableBase * | _src |
The source variable this variable follows. | |
const bool | _is_state |
const bool | _is_old_state |
const bool | _is_force |
const bool | _is_old_force |
const bool | _is_residual |
const bool | _is_parameter |
const bool | _is_other |
const bool | _is_solve_dependent |
|
inline |
|
inline |
Suppressed constructor to prevent accidental dereferencing.
|
inlineoverridevirtual |
Base shape.
Implements VariableBase.
|
inlineoverridevirtual |
Set the batch shape and base shape according to val
.
Reimplemented from VariableBase.
Set the raw value to store val
.
Note that this is an in-place operation, and so we must reshape (flatten base dimensions of) val
and modify raw_value.
Suppressed assignment operator to prevent accidental dereferencing.
Set requires_grad for the underlying storage.
Implements VariableBase.
|
inlineoverridevirtual |
Setup the variable's views into blocks of the storage.
Reimplemented from VariableBase.
|
inlineoverridevirtual |
Setup the variable's views following another variable.
Reimplemented from VariableBase.
|
inlineoverridevirtual |
Total shape.
Implements VariableBase.
Variable value of the logical shape.
Implements VariableBase.
|
inlineoverridevirtual |
Variable type.
Implements VariableBase.
|
protected |
Base shape of this variable.
|
protected |
Shape of this variable.
|
protected |
Variable tensor type.