27#include "neml2/base/NEML2Object.h"
28#include "neml2/base/OptionSet.h"
29#include "neml2/base/Storage.h"
30#include "neml2/tensors/TensorValue.h"
53 typename =
typename std::enable_if_t<std::is_base_of_v<BatchTensorBase<T>, T>>>
60 const std::map<std::string, const VariableBase *> &
nl_params()
const {
return _nl_params; }
92 typename =
typename std::enable_if_t<std::is_base_of_v<BatchTensorBase<T>, T>>>
109 template <
typename T,
110 typename =
typename std::enable_if_t<std::is_base_of_v<BatchTensorBase<T>, T>>>
127 std::map<std::string, const VariableBase *> _nl_params;
130template <
typename T,
typename>
134 neml_assert(_object->
host() == _object,
"This method should only be called on the host model.");
136 auto base_ptr = _param_values.query_value(name);
143template <
typename T,
typename>
147 if (_object->
host() != _object)
151 if (_param_values.has_key(name))
154 auto val = std::make_unique<TensorValue<T>>(
rawval);
155 auto base_ptr = _param_values.set_pointer(name, std::move(
val));
157 neml_assert(
ptr,
"Internal error: Failed to cast parameter to a concrete type.");
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
The base class of all "manufacturable" objects in the NEML2 library.
Definition NEML2Object.h:38
const std::string & name() const
A readonly reference to the object's name.
Definition NEML2Object.h:65
const T * host() const
Get a readonly pointer to the host.
Definition NEML2Object.h:90
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
Interface for object which can store parameters.
Definition ParameterStore.h:38
virtual void send_parameters_to(const torch::TensorOptions &options)
Send parameters to options.
Definition ParameterStore.cxx:47
ParameterStore(const OptionSet &options, NEML2Object *object)
Definition ParameterStore.cxx:32
const std::map< std::string, const VariableBase * > & nl_params() const
Get all nonlinear parameters.
Definition ParameterStore.h:60
bool has_nl_param() const
Whether this parameter store has any nonlinear parameter.
Definition ParameterStore.h:57
const Storage< std::string, TensorValueBase > & named_parameters() const
Definition ParameterStore.h:44
const T & declare_parameter(const std::string &name, const T &rawval)
Declare a parameter.
Definition ParameterStore.h:145
T & get_parameter(const std::string &name)
}@
Definition ParameterStore.h:132
const VariableBase * nl_param(const std::string &) const
Query the existence of a nonlinear parameter.
Definition ParameterStore.cxx:56
Definition CrossRef.cxx:32
void neml_assert_dbg(bool assertion, Args &&... args)
Definition error.h:85
void neml_assert(bool assertion, Args &&... args)
Definition error.h:73