NEML2 2.0.0
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 (NEML2Object *object)
 
 BufferStore (const BufferStore &)=delete
 
 BufferStore (BufferStore &&)=delete
 
BufferStoreoperator= (const BufferStore &)=delete
 
BufferStoreoperator= (BufferStore &&)=delete
 
virtual ~BufferStore ()=default
 
const std::map< std::string, std::unique_ptr< TensorValueBase > > & named_buffers () const
 
std::map< std::string, std::unique_ptr< TensorValueBase > > & named_buffers ()
 
const TensorValueBaseget_buffer (const std::string &name) const
 }@
 
TensorValueBaseget_buffer (const std::string &name)
 Get a writable reference of a buffer.
 
virtual void send_buffers_to (const 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 TensorName< T > &tensorname)
 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.
 
void assign_buffer_stack (jit::Stack &stack)
 Assign stack to buffers.
 
jit::Stack collect_buffer_stack () const
 Collect stack from buffers.
 

Constructor & Destructor Documentation

◆ BufferStore() [1/3]

BufferStore ( NEML2Object * object)

◆ BufferStore() [2/3]

BufferStore ( const BufferStore & )
delete

◆ BufferStore() [3/3]

BufferStore ( BufferStore && )
delete

◆ ~BufferStore()

virtual ~BufferStore ( )
virtualdefault

Member Function Documentation

◆ assign_buffer_stack()

void assign_buffer_stack ( jit::Stack & stack)
protected

Assign stack to buffers.

◆ collect_buffer_stack()

jit::Stack collect_buffer_stack ( ) const
protected

Collect stack from buffers.

◆ declare_buffer() [1/3]

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

Declare a buffer.

Similar to the previous methods, but this method takes care of the high-level logic to directly construct a buffer from the input option.

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/3]

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
T The value of the registered buffer.

◆ declare_buffer() [3/3]

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

Declare a buffer.

Similar to the previous method, but additionally handles the resolution of cross-referenced parameters.

Template Parameters
TBuffer type. See Statically shaped tensors for supported types.
Parameters
nameBuffer name.
tensornameThe cross-ref'ed "string" that defines the value of the buffer.
Returns
T The value of the registered buffer.

◆ get_buffer() [1/2]

TensorValueBase & get_buffer ( const std::string & name)

Get a writable reference of a buffer.

◆ get_buffer() [2/2]

const TensorValueBase & get_buffer ( const std::string & name) const
inline

}@

Get a read-only reference of a buffer

◆ named_buffers() [1/2]

std::map< std::string, std::unique_ptr< TensorValueBase > > & named_buffers ( )

◆ named_buffers() [2/2]

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

◆ operator=() [1/2]

BufferStore & operator= ( BufferStore && )
delete

◆ operator=() [2/2]

BufferStore & operator= ( const BufferStore & )
delete

◆ send_buffers_to()

void send_buffers_to ( const TensorOptions & options)
protectedvirtual

Send all buffers to options.

Parameters
optionsThe target options