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

Interface for object which can store buffers. More...

Detailed Description

Interface for object which can store buffers.

#include <BufferStore.h>

Inheritance diagram for BufferStore:

Public Member Functions

 BufferStore (const OptionSet &options, NEML2Object *object)
 
const Storage< std::string, TensorValueBase > & named_buffers () const
 
Storage< std::string, TensorValueBase > & named_buffers ()
 
template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>>
TensorValue< T > & get_buffer (const std::string &name)
 }@
 
virtual void send_buffers_to (const torch::TensorOptions &options)
 Send all buffers to options.
 
template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>>
const T & declare_buffer (const std::string &name, const T &rawval)
 Declare a buffer.
 
template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>>
const T & declare_buffer (const std::string &name, const std::string &input_option_name)
 Declare a buffer.
 

Constructor & Destructor Documentation

◆ BufferStore()

BufferStore ( const OptionSet & options,
NEML2Object * object )

Member Function Documentation

◆ declare_buffer() [1/2]

template<typename T , typename >
const T & declare_buffer ( const std::string & name,
const std::string & input_option_name )
protected

Declare a buffer.

Note that all buffers are stored in the host (the object exposed to users). An object may be used multiple times in the host, and the same buffer may be declared multiple times. That is allowed, but only the first call to declare_buffer constructs the buffer value, and subsequent calls only returns a reference to the existing buffer.

Template Parameters
TBuffer type. See Statically shaped tensors for supported types.
Parameters
nameBuffer name
input_option_nameName of the input option that defines the value of the model buffer.
Returns
T Reference to buffer

◆ declare_buffer() [2/2]

template<typename T , typename >
const T & declare_buffer ( const std::string & name,
const T & rawval )
protected

Declare a buffer.

Note that all buffers are stored in the host (the object exposed to users). An object may be used multiple times in the host, and the same buffer may be declared multiple times. That is allowed, but only the first call to declare_buffer constructs the buffer value, and subsequent calls only returns a reference to the existing buffer.

Template Parameters
TBuffer type. See Statically shaped tensors for supported types.
Parameters
nameBuffer name
rawvalBuffer value
Returns
Reference to buffer

◆ get_buffer()

template<typename T , typename >
TensorValue< T > & get_buffer ( const std::string & name)

}@

Get a writable reference of a buffer

◆ named_buffers() [1/2]

Storage< std::string, TensorValueBase > & named_buffers ( )

◆ named_buffers() [2/2]

const Storage< std::string, TensorValueBase > & named_buffers ( ) const
inline
Returns
the buffer storage

◆ send_buffers_to()

void send_buffers_to ( const torch::TensorOptions & options)
protectedvirtual

Send all buffers to options.

Parameters
optionsThe target options