mxnet
Public Member Functions | Protected Member Functions | Friends | List of all members
mxnet::runtime::InplaceArrayBase< ArrayType, ElemType > Class Template Reference

Base template for classes with array like memory layout. More...

#include <container.h>

Collaboration diagram for mxnet::runtime::InplaceArrayBase< ArrayType, ElemType >:
Collaboration graph

Public Member Functions

const ElemType & operator[] (size_t idx) const
 Access element at index. More...
 
ElemType & operator[] (size_t idx)
 Access element at index. More...
 
 ~InplaceArrayBase ()
 Destroy the Inplace Array Base object. More...
 

Protected Member Functions

template<typename... Args>
void EmplaceInit (size_t idx, Args &&...args)
 Construct a value in place with the arguments. More...
 

Friends

class ADTBuilder
 

Detailed Description

template<typename ArrayType, typename ElemType>
class mxnet::runtime::InplaceArrayBase< ArrayType, ElemType >

Base template for classes with array like memory layout.

It provides general methods to access the memory. The memory layout is ArrayType + [ElemType]. The alignment of ArrayType and ElemType is handled by the memory allocator.

Template Parameters
ArrayTypeThe array header type, contains object specific metadata.
ElemTypeThe type of objects stored in the array right after ArrayType.
// Example usage of the template to define a simple array wrapper
class ArrayObj : public InplaceArrayBase<ArrayObj, Elem> {
public:
// Wrap EmplaceInit to initialize the elements
template <typename Iterator>
void Init(Iterator begin, Iterator end) {
size_t num_elems = std::distance(begin, end);
auto it = begin;
this->size = 0;
for (size_t i = 0; i < num_elems; ++i) {
this->size++;
}
}
}
void test_function() {
vector<Elem> fields;
auto ptr = make_inplace_array_object<ArrayObj, Elem>(fields.size());
ptr->Init(fields.begin(), fields.end());
// Access the 0th element in the array.
assert(ptr->operator[](0) == fields[0]);
}

Constructor & Destructor Documentation

template<typename ArrayType, typename ElemType>
mxnet::runtime::InplaceArrayBase< ArrayType, ElemType >::~InplaceArrayBase ( )
inline

Destroy the Inplace Array Base object.

Member Function Documentation

template<typename ArrayType, typename ElemType>
template<typename... Args>
void mxnet::runtime::InplaceArrayBase< ArrayType, ElemType >::EmplaceInit ( size_t  idx,
Args &&...  args 
)
inlineprotected

Construct a value in place with the arguments.

Template Parameters
ArgsType parameters of the arguments.
Parameters
idxIndex of the element.
argsArguments to construct the new value.
Note
Please make sure ArrayType::GetSize returns 0 before first call of EmplaceInit, and increment GetSize by 1 each time EmplaceInit succeeds.
template<typename ArrayType, typename ElemType>
const ElemType& mxnet::runtime::InplaceArrayBase< ArrayType, ElemType >::operator[] ( size_t  idx) const
inline

Access element at index.

Parameters
idxThe index of the element.
Returns
Const reference to ElemType at the index.
template<typename ArrayType, typename ElemType>
ElemType& mxnet::runtime::InplaceArrayBase< ArrayType, ElemType >::operator[] ( size_t  idx)
inline

Access element at index.

Parameters
idxThe index of the element.
Returns
Reference to ElemType at the index.

Friends And Related Function Documentation

template<typename ArrayType, typename ElemType>
friend class ADTBuilder
friend

The documentation for this class was generated from the following file: