NEML2 1.4.0
|
Interface for object which can store parameters. More...
Interface for object which can store parameters.
#include <ParameterStore.h>
Public Member Functions | |
ParameterStore (const OptionSet &options, NEML2Object *object) | |
const Storage< std::string, TensorValueBase > & | named_parameters () const |
Storage< std::string, TensorValueBase > & | named_parameters () |
template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<BatchTensorBase<T>, T>>> | |
T & | get_parameter (const std::string &name) |
}@ | |
bool | has_nl_param () const |
Whether this parameter store has any nonlinear parameter. | |
const std::map< std::string, const VariableBase * > & | nl_params () const |
Get all nonlinear parameters. | |
const VariableBase * | nl_param (const std::string &) const |
Query the existence of a nonlinear parameter. | |
virtual void | send_parameters_to (const torch::TensorOptions &options) |
Send parameters to options. | |
template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<BatchTensorBase<T>, T>>> | |
const T & | declare_parameter (const std::string &name, const T &rawval) |
Declare a parameter. | |
template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<BatchTensorBase<T>, T>>> | |
const T & | declare_parameter (const std::string &name, const std::string &input_option_name) |
Declare a parameter. | |
ParameterStore | ( | const OptionSet & | options, |
NEML2Object * | object ) |
|
protected |
Declare a parameter.
Note that all parameters are stored in the host (the object exposed to users). An object may be used multiple times in the host, and the same parameter may be declared multiple times. That is allowed, but only the first call to declare_parameter constructs the parameter value, and subsequent calls only returns a reference to the existing parameter.
T | Parameter type. See Statically shaped tensors for supported types. |
name | Name of the model parameter. |
input_option_name | Name of the input option that defines the value of the model parameter. |
Declare a parameter.
Note that all parameters are stored in the host (the object exposed to users). An object may be used multiple times in the host, and the same parameter may be declared multiple times. That is allowed, but only the first call to declare_parameter constructs the parameter value, and subsequent calls only returns a reference to the existing parameter.
T | Buffer type. See Statically shaped tensors for supported types. |
name | Buffer name |
rawval | Buffer value |
}@
Get a writable reference of a parameter
|
inline |
Whether this parameter store has any nonlinear parameter.
Storage< std::string, TensorValueBase > & named_parameters | ( | ) |
|
inline |
const VariableBase * nl_param | ( | const std::string & | name | ) | const |
Query the existence of a nonlinear parameter.
|
inline |
Get all nonlinear parameters.