NEML2 2.0.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 (OptionSet options, NEML2Object *object)
 
 BufferStore (const BufferStore &)=delete
 
 BufferStore (BufferStore &&)=delete
 
BufferStoreoperator= (const BufferStore &)=delete
 
BufferStoreoperator= (BufferStore &&)=delete
 
virtual ~BufferStore ()=default
 
const Storage< std::string, TensorValueBase > & named_buffers () const
 
Storage< std::string, TensorValueBase > & named_buffers ()
 
TensorValueBaseget_buffer (const std::string &name)
 }@
 
const TensorValueBaseget_buffer (const std::string &name) const
 Get a read-only reference of a buffer.
 
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 CrossRef< T > &crossref)
 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() [1/3]

BufferStore ( OptionSet options,
NEML2Object * object )

◆ BufferStore() [2/3]

◆ BufferStore() [3/3]

BufferStore ( BufferStore && )
delete

◆ ~BufferStore()

virtual ~BufferStore ( )
virtualdefault

Member Function Documentation

◆ declare_buffer() [1/3]

template<typename T , typename >
const T & declare_buffer ( const std::string & name,
const CrossRef< T > & crossref )
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.
crossrefThe cross-ref'ed "string" that defines the value of the buffer.
Returns
T The value of the registered buffer.

◆ declare_buffer() [2/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() [3/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.

◆ 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

Get a read-only 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

◆ operator=() [1/2]

BufferStore & operator= ( BufferStore && )
delete

◆ operator=() [2/2]

◆ send_buffers_to()

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

Send all buffers to options.

Parameters
optionsThe target options