NEML2 1.4.0
Loading...
Searching...
No Matches
VariableStore Class Reference

#include <VariableStore.h>

Inheritance diagram for VariableStore:

Public Member Functions

 VariableStore (const OptionSet &options, Model *object)
 
LabeledAxisdeclare_axis (const std::string &name)
 
virtual void setup_layout ()
 Setup the layouts of all the registered axes.
 
VariableBaseinput_variable (const VariableName &)
 Get the view of an input variable.
 
VariableBaseoutput_variable (const VariableName &)
 Get the view of an output variable.
 
TensorType input_type (const VariableName &) const
 Get the variable type of an input variable.
 
TensorType output_type (const VariableName &) const
 Get the variable type of an output variable.
 
template<typename T = Tensor>
Variable< T > & get_input_variable (const VariableName &name)
 
template<typename T = Tensor>
const Variable< T > & get_input_variable (const VariableName &name) const
 
template<typename T = Tensor>
const Variable< T > & get_output_variable (const VariableName &name)
 
template<typename T = Tensor>
const Variable< T > & get_output_variable (const VariableName &name) const
 
LabeledAxisinput_axis ()
 
const LabeledAxisinput_axis () const
 
LabeledAxisoutput_axis ()
 
const LabeledAxisoutput_axis () const
 
Storage< VariableName, VariableBase > & input_variables ()
 
const Storage< VariableName, VariableBase > & input_variables () const
 
Storage< VariableName, VariableBase > & output_variables ()
 
const Storage< VariableName, VariableBase > & output_variables () const
 
LabeledVectorinput_storage ()
 
const LabeledVectorinput_storage () const
 
LabeledVectoroutput_storage ()
 
const LabeledVectoroutput_storage () const
 
LabeledMatrixderivative_storage ()
 
const LabeledMatrixderivative_storage () const
 
LabeledTensor3Dsecond_derivative_storage ()
 
const LabeledTensor3Dsecond_derivative_storage () const
 

Protected Member Functions

virtual void cache (TensorShapeRef batch_shape)
 Cache the variable's batch shape.
 
virtual void allocate_variables (TensorShapeRef batch_shape, const torch::TensorOptions &options, bool in, bool out, bool dout_din, bool d2out_din2)
 Allocate variable storages given the batch shape and tensor options.
 
virtual void setup_input_views (VariableStore *host=nullptr)
 Tell each input variable view which tensor storage(s) to view into.
 
virtual void setup_output_views (bool out, bool dout_din, bool d2out_din2)
 Tell each output variable view which tensor storage(s) to view into.
 
virtual void zero (bool dout_din, bool d2out_din2)
 Zero out derivative and second derivative storage.
 
template<typename T , typename... S>
const Variable< T > & declare_input_variable (S &&... name)
 Declare an input variable.
 
template<typename... S>
const Variable< Tensor > & declare_input_variable (Size sz, TensorType t, S &&... name)
 Declare an input variable (with unknown base shape at compile time)
 
template<typename T , typename... S>
const Variable< Tensor > & declare_input_variable_list (Size list_size, S &&... name)
 Declare an input variable that is a list of tensors of fixed size.
 
template<typename T , typename... S>
Variable< T > & declare_output_variable (S &&... name)
 Declare an output variable.
 
template<typename... S>
Variable< Tensor > & declare_output_variable (Size sz, TensorType t, S &&... name)
 Declare an input variable (with unknown base shape at compile time)
 
template<typename T , typename... S>
Variable< Tensor > & declare_output_variable_list (Size list_size, S &&... name)
 Declare an output variable that is a list of tensors of fixed size.
 
template<typename T >
VariableName declare_variable (LabeledAxis &axis, const VariableName &var) const
 Declare an item recursively on an axis.
 
VariableName declare_variable (LabeledAxis &axis, const VariableName &var, Size sz) const
 Declare an item (with known storage size) recursively on an axis.
 
VariableName declare_subaxis (LabeledAxis &axis, const VariableName &subaxis) const
 Declare a subaxis recursively on an axis.
 

Constructor & Destructor Documentation

◆ VariableStore()

VariableStore ( const OptionSet & options,
Model * object )

Member Function Documentation

◆ allocate_variables()

void allocate_variables ( TensorShapeRef batch_shape,
const torch::TensorOptions & options,
bool in,
bool out,
bool dout_din,
bool d2out_din2 )
protectedvirtual

Allocate variable storages given the batch shape and tensor options.

Parameters
batch_shapeBatch shape of the allocated tensors
optionsTensor options of the allocated tensors
inWhether to allocate tensor storage for input
outWhether to allocate tensor storage for output
dout_dinWhether to allocate tensor storage for the first derivatives
d2out_din2Whether to allocate tensor storage for the second derivatives

Reimplemented in Model.

◆ cache()

void cache ( TensorShapeRef batch_shape)
protectedvirtual

Cache the variable's batch shape.

Reimplemented in Model.

◆ declare_axis()

LabeledAxis & declare_axis ( const std::string & name)

◆ declare_input_variable() [1/2]

template<typename T , typename... S>
const Variable< T > & declare_input_variable ( S &&... name)
inlineprotected

Declare an input variable.

◆ declare_input_variable() [2/2]

template<typename... S>
const Variable< Tensor > & declare_input_variable ( Size sz,
TensorType t,
S &&... name )
inlineprotected

Declare an input variable (with unknown base shape at compile time)

◆ declare_input_variable_list()

template<typename T , typename... S>
const Variable< Tensor > & declare_input_variable_list ( Size list_size,
S &&... name )
inlineprotected

Declare an input variable that is a list of tensors of fixed size.

◆ declare_output_variable() [1/2]

template<typename T , typename... S>
Variable< T > & declare_output_variable ( S &&... name)
inlineprotected

Declare an output variable.

◆ declare_output_variable() [2/2]

template<typename... S>
Variable< Tensor > & declare_output_variable ( Size sz,
TensorType t,
S &&... name )
inlineprotected

Declare an input variable (with unknown base shape at compile time)

◆ declare_output_variable_list()

template<typename T , typename... S>
Variable< Tensor > & declare_output_variable_list ( Size list_size,
S &&... name )
inlineprotected

Declare an output variable that is a list of tensors of fixed size.

◆ declare_subaxis()

VariableName declare_subaxis ( LabeledAxis & axis,
const VariableName & subaxis ) const
inlineprotected

Declare a subaxis recursively on an axis.

◆ declare_variable() [1/2]

template<typename T >
VariableName declare_variable ( LabeledAxis & axis,
const VariableName & var ) const
inlineprotected

Declare an item recursively on an axis.

◆ declare_variable() [2/2]

VariableName declare_variable ( LabeledAxis & axis,
const VariableName & var,
Size sz ) const
inlineprotected

Declare an item (with known storage size) recursively on an axis.

◆ derivative_storage() [1/2]

LabeledMatrix & derivative_storage ( )
inline

Derivative storage

◆ derivative_storage() [2/2]

const LabeledMatrix & derivative_storage ( ) const
inline

◆ get_input_variable() [1/2]

template<typename T = Tensor>
Variable< T > & get_input_variable ( const VariableName & name)
inline

Get an input variable

◆ get_input_variable() [2/2]

template<typename T = Tensor>
const Variable< T > & get_input_variable ( const VariableName & name) const
inline

◆ get_output_variable() [1/2]

template<typename T = Tensor>
const Variable< T > & get_output_variable ( const VariableName & name)
inline

Get an output variable

◆ get_output_variable() [2/2]

template<typename T = Tensor>
const Variable< T > & get_output_variable ( const VariableName & name) const
inline

◆ input_axis() [1/2]

LabeledAxis & input_axis ( )
inline

Definition of the input variables

◆ input_axis() [2/2]

const LabeledAxis & input_axis ( ) const
inline

◆ input_storage() [1/2]

LabeledVector & input_storage ( )
inline

Input storage

◆ input_storage() [2/2]

const LabeledVector & input_storage ( ) const
inline

◆ input_type()

TensorType input_type ( const VariableName & name) const

Get the variable type of an input variable.

◆ input_variable()

VariableBase * input_variable ( const VariableName & name)

Get the view of an input variable.

◆ input_variables() [1/2]

Storage< VariableName, VariableBase > & input_variables ( )
inline

Input variable views

◆ input_variables() [2/2]

const Storage< VariableName, VariableBase > & input_variables ( ) const
inline

◆ output_axis() [1/2]

LabeledAxis & output_axis ( )
inline

Which variables this object defines as output

◆ output_axis() [2/2]

const LabeledAxis & output_axis ( ) const
inline

◆ output_storage() [1/2]

LabeledVector & output_storage ( )
inline

Output storage

◆ output_storage() [2/2]

const LabeledVector & output_storage ( ) const
inline

◆ output_type()

TensorType output_type ( const VariableName & name) const

Get the variable type of an output variable.

◆ output_variable()

VariableBase * output_variable ( const VariableName & name)

Get the view of an output variable.

◆ output_variables() [1/2]

Storage< VariableName, VariableBase > & output_variables ( )
inline

Output variable views

◆ output_variables() [2/2]

const Storage< VariableName, VariableBase > & output_variables ( ) const
inline

◆ second_derivative_storage() [1/2]

LabeledTensor3D & second_derivative_storage ( )
inline

Second derivative storage

◆ second_derivative_storage() [2/2]

const LabeledTensor3D & second_derivative_storage ( ) const
inline

◆ setup_input_views()

void setup_input_views ( VariableStore * host = nullptr)
protectedvirtual

Tell each input variable view which tensor storage(s) to view into.

Reimplemented in Model.

◆ setup_layout()

void setup_layout ( )
virtual

Setup the layouts of all the registered axes.

◆ setup_output_views()

void setup_output_views ( bool out,
bool dout_din,
bool d2out_din2 )
protectedvirtual

Tell each output variable view which tensor storage(s) to view into.

Reimplemented in Model.

◆ zero()

void zero ( bool dout_din,
bool d2out_din2 )
protectedvirtual

Zero out derivative and second derivative storage.

Reimplemented in Model.