27#include "neml2/base/NEML2Object.h"
28#include "neml2/base/OptionSet.h"
29#include "neml2/base/Storage.h"
30#include "neml2/tensors/TensorValue.h"
34#include "neml2/base/CrossRef.h"
35#include "neml2/base/EnumSelection.h"
55 template <
typename T,
typename =
typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>>
79 template <
typename T,
typename =
typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>>
96 template <
typename T,
typename =
typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>>
113template <
typename T,
typename>
117 neml_assert(_object->
host() == _object,
"This method should only be called on the host model.");
119 auto base_ptr = _buffer_values.query_value(name);
126template <
typename T,
typename>
130 if (_object->
host() != _object)
135 if (_buffer_values.has_key(name))
138 auto val = std::make_unique<TensorValue<T>>(
rawval);
139 auto base_ptr = _buffer_values.set_pointer(name, std::move(
val));
141 neml_assert(
ptr,
"Internal error: Failed to cast buffer to a concrete type.");
145template <
typename T,
typename>
155 "Trying to register buffer named " + name +
" from input option named " +
input_option_name +
157 ". Make sure you provided the correct buffer name, option name, and buffer type. Note that "
158 "the buffer type can either be a plain type, a cross-reference, or an interpolator.");
Interface for object which can store buffers.
Definition BufferStore.h:41
virtual void send_buffers_to(const torch::TensorOptions &options)
Send all buffers to options.
Definition BufferStore.cxx:44
const Storage< std::string, TensorValueBase > & named_buffers() const
Definition BufferStore.h:47
const T & declare_buffer(const std::string &name, const T &rawval)
Declare a buffer.
Definition BufferStore.h:128
BufferStore(const OptionSet &options, NEML2Object *object)
Definition BufferStore.cxx:29
TensorValue< T > & get_buffer(const std::string &name)
}@
Definition BufferStore.h:115
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:56
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:100
std::string demangle(const char *name)
Demangle a piece of cxx abi type information.
Definition utils.cxx:33
Definition CrossRef.cxx:30
void neml_assert_dbg(bool assertion, Args &&... args)
Definition error.h:76
std::string & buffer_name_separator()
Default nested buffer name separator.
Definition types.cxx:88
void neml_assert(bool assertion, Args &&... args)
Definition error.h:64