27#include "neml2/base/NEML2Object.h"
28#include "neml2/base/OptionSet.h"
29#include "neml2/base/Storage.h"
30#include "neml2/tensors/TensorValue.h"
51 typename =
typename std::enable_if_t<std::is_base_of_v<BatchTensorBase<T>, T>>>
76 typename =
typename std::enable_if_t<std::is_base_of_v<BatchTensorBase<T>, T>>>
94 typename =
typename std::enable_if_t<std::is_base_of_v<BatchTensorBase<T>, T>>>
111template <
typename T,
typename>
115 neml_assert(_object->
host() == _object,
"This method should only be called on the host model.");
117 auto base_ptr = _buffer_values.query_value(name);
124template <
typename T,
typename>
128 if (_object->
host() != _object)
132 if (_buffer_values.has_key(name))
135 auto val = std::make_unique<TensorValue<T>>(
rawval);
136 auto base_ptr = _buffer_values.set_pointer(name, std::move(
val));
138 neml_assert(
ptr,
"Internal error: Failed to cast buffer to a concrete type.");
142template <
typename T,
typename>
152 "Trying to register buffer named " + name +
" from input option named " +
input_option_name +
154 ". Make sure you provided the correct buffer name, option name, and buffer type. Note that "
155 "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:36
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:42
const T & declare_buffer(const std::string &name, const T &rawval)
Declare a buffer.
Definition BufferStore.h:126
T & get_buffer(const std::string &name)
}@
Definition BufferStore.h:113
BufferStore(const OptionSet &options, NEML2Object *object)
Definition BufferStore.cxx:29
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
std::string demangle(const char *name)
Definition parser_utils.cxx:46
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