mxnet
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
mxnet::Tuple< ValueType > Class Template Reference

A dynamic sized array data structure that is optimized for storing small number of elements with same type. More...

#include <tuple.h>

Collaboration diagram for mxnet::Tuple< ValueType >:
Collaboration graph

Public Member Functions

 Tuple ()=default
 default constructor More...
 
 ~Tuple ()
 destructor More...
 
 Tuple (const Tuple< ValueType > &s)
 copy constructor from another tuple More...
 
 Tuple (std::initializer_list< ValueType > init)
 constructor from initializer list More...
 
 Tuple (std::vector< ValueType > init)
 constructor from vector More...
 
 Tuple (Tuple< ValueType > &&src)
 move constructor from Tuple More...
 
template<typename RandomAccessIterator >
 Tuple (RandomAccessIterator begin, RandomAccessIterator end)
 construct the Tuple from content of iterator More...
 
template<typename RandomAccessIterator >
void assign (RandomAccessIterator begin, RandomAccessIterator end)
 Assign content to tuple from iterator. More...
 
void swap (Tuple< ValueType > &other)
 Swap current object with other. More...
 
Tuple< ValueType > & operator= (const Tuple< ValueType > &src)
 assignment from another tuple. More...
 
Tuple< ValueType > & operator= (Tuple< ValueType > &&src)
 assignment from rvalue of another tuple. More...
 
Tuple< ValueType > & operator= (std::initializer_list< ValueType > init)
 assignment from initializer list More...
 
bool operator== (const Tuple< ValueType > &s) const
 
bool operator!= (const Tuple< ValueType > &s) const
 
const ValueType * begin () const
 
ValueType * begin ()
 
const ValueType * end () const
 
ValueType * end ()
 
int ndim () const
 
ValueType & operator[] (int i)
 get corresponding index More...
 
const ValueType & operator[] (int i) const
 get corresponding index More...
 
void Save (dmlc::JSONWriter *writer) const
 Save Tuple to JSON. More...
 
void Load (dmlc::JSONReader *reader)
 Load Tuple from JSON. More...
 
template<typename DType = ValueType, typename TStream >
void Save (TStream *strm) const
 save the content into binary stream More...
 
template<typename DType = ValueType, typename TStream >
bool Load (TStream *strm)
 load the content from binary stream More...
 

Protected Member Functions

void SetDim (int ndim)
 

Protected Attributes

int ndim_ {0}
 number of dimension of the tuple More...
 
int num_heap_allocated_ {0}
 number of cells allocated in data_heap_ More...
 
ValueType data_stack_ [kStackCache]
 in stack space used to store shape when it is small More...
 
ValueType * data_heap_ {nullptr}
 space to store shape when dimension is big More...
 

Static Protected Attributes

static const int kStackCache = 4
 

Friends

std::ostream & operator<< (std::ostream &os, const Tuple< ValueType > &t)
 allow output string of tuple to ostream More...
 
std::istream & operator>> (std::istream &is, Tuple< ValueType > &t)
 read tuple from the istream More...
 

Detailed Description

template<typename ValueType>
class mxnet::Tuple< ValueType >

A dynamic sized array data structure that is optimized for storing small number of elements with same type.

Data will be stored in stack when number of elements is small. It is suitable to hold shape of Tensor.

The ndim of a valid tuple is an integer in range [0, inf). ndim = 0 means the tuple is empty.

Template Parameters
ValueTypeThe type of data stored inside tuple.
See also
TShape

Constructor & Destructor Documentation

template<typename ValueType>
mxnet::Tuple< ValueType >::Tuple ( )
default

default constructor

template<typename ValueType>
mxnet::Tuple< ValueType >::~Tuple ( )
inline

destructor

template<typename ValueType>
mxnet::Tuple< ValueType >::Tuple ( const Tuple< ValueType > &  s)
inline

copy constructor from another tuple

Parameters
sthe source tuple
template<typename ValueType>
mxnet::Tuple< ValueType >::Tuple ( std::initializer_list< ValueType >  init)
inline

constructor from initializer list

Parameters
initthe initializer_list
template<typename ValueType>
mxnet::Tuple< ValueType >::Tuple ( std::vector< ValueType >  init)
inline

constructor from vector

Parameters
initthe vector
template<typename ValueType>
mxnet::Tuple< ValueType >::Tuple ( Tuple< ValueType > &&  src)
inline

move constructor from Tuple

Parameters
srcthe source shape
template<typename ValueType>
template<typename RandomAccessIterator >
mxnet::Tuple< ValueType >::Tuple ( RandomAccessIterator  begin,
RandomAccessIterator  end 
)
inline

construct the Tuple from content of iterator

Parameters
beginthe beginning of iterator
endend the end of the iterator
Template Parameters
RandomAccessIteratoriterator type

Member Function Documentation

template<typename ValueType>
template<typename RandomAccessIterator >
void mxnet::Tuple< ValueType >::assign ( RandomAccessIterator  begin,
RandomAccessIterator  end 
)
inline

Assign content to tuple from iterator.

Parameters
beginthe beginning of iterator
endend the end of the iterator
Template Parameters
RandomAccessIteratoriterator type
template<typename ValueType>
const ValueType* mxnet::Tuple< ValueType >::begin ( ) const
inline
Returns
the begin data pointer to content of the tuple
template<typename ValueType>
ValueType* mxnet::Tuple< ValueType >::begin ( )
inline
Returns
the begin data pointer to content of the tuple
template<typename ValueType>
const ValueType* mxnet::Tuple< ValueType >::end ( ) const
inline
Returns
the data pointer to end of the tuple
template<typename ValueType>
ValueType* mxnet::Tuple< ValueType >::end ( )
inline
Returns
the data pointer to end the tuple
template<typename ValueType>
void mxnet::Tuple< ValueType >::Load ( dmlc::JSONReader *  reader)
inline

Load Tuple from JSON.

Parameters
readerJSONReader
template<typename ValueType >
template<typename DType , typename TStream >
bool mxnet::Tuple< ValueType >::Load ( TStream *  strm)
inline

load the content from binary stream

Parameters
strmthe output stream
Template Parameters
DTypedata type that load from
TStreamany stream type that have write
Returns
whether the load is successful
Template Parameters
ValueTypeThe type of data stored inside tuple.
template<typename ValueType>
int mxnet::Tuple< ValueType >::ndim ( void  ) const
inline
Returns
number of dimension of the tuple
template<typename ValueType>
bool mxnet::Tuple< ValueType >::operator!= ( const Tuple< ValueType > &  s) const
inline
Returns
whether two tuple not equal
Parameters
sthe tuple to compare against
template<typename ValueType>
Tuple<ValueType>& mxnet::Tuple< ValueType >::operator= ( const Tuple< ValueType > &  src)
inline

assignment from another tuple.

Parameters
srcsource tuple
Returns
reference of self
template<typename ValueType>
Tuple<ValueType>& mxnet::Tuple< ValueType >::operator= ( Tuple< ValueType > &&  src)
inline

assignment from rvalue of another tuple.

Parameters
srcsource tuple
Returns
reference of self
template<typename ValueType>
Tuple<ValueType>& mxnet::Tuple< ValueType >::operator= ( std::initializer_list< ValueType >  init)
inline

assignment from initializer list

Parameters
initthe source initializer list
Returns
reference of self
template<typename ValueType>
bool mxnet::Tuple< ValueType >::operator== ( const Tuple< ValueType > &  s) const
inline
Returns
whether two tuple equals
Parameters
sthe tuple to compare against
template<typename ValueType>
ValueType& mxnet::Tuple< ValueType >::operator[] ( int  i)
inline

get corresponding index

Parameters
idimension index
Returns
the corresponding dimension size
template<typename ValueType>
const ValueType& mxnet::Tuple< ValueType >::operator[] ( int  i) const
inline

get corresponding index

Parameters
idimension index
Returns
the corresponding dimension size
template<typename ValueType>
void mxnet::Tuple< ValueType >::Save ( dmlc::JSONWriter *  writer) const
inline

Save Tuple to JSON.

Parameters
writerJSONWriter
template<typename ValueType >
template<typename DType , typename TStream >
void mxnet::Tuple< ValueType >::Save ( TStream *  strm) const
inline

save the content into binary stream

Parameters
strmthe output stream
Template Parameters
DTypedata type that save to
TStreamany stream type that have write
ValueTypeThe type of data stored inside tuple.
template<typename ValueType>
void mxnet::Tuple< ValueType >::SetDim ( int  ndim)
inlineprotected
template<typename ValueType>
void mxnet::Tuple< ValueType >::swap ( Tuple< ValueType > &  other)
inline

Swap current object with other.

Parameters
otheranother object to be swapped.

Friends And Related Function Documentation

template<typename ValueType>
std::ostream& operator<< ( std::ostream &  os,
const Tuple< ValueType > &  t 
)
friend

allow output string of tuple to ostream

Parameters
osthe output stream
tthe tuple
Returns
the ostream
template<typename ValueType>
std::istream& operator>> ( std::istream &  is,
Tuple< ValueType > &  t 
)
friend

read tuple from the istream

Parameters
isthe input stream
tThe tuple
Returns
the istream

Member Data Documentation

template<typename ValueType>
ValueType* mxnet::Tuple< ValueType >::data_heap_ {nullptr}
protected

space to store shape when dimension is big

template<typename ValueType>
ValueType mxnet::Tuple< ValueType >::data_stack_[kStackCache]
protected

in stack space used to store shape when it is small

template<typename ValueType>
const int mxnet::Tuple< ValueType >::kStackCache = 4
staticprotected
template<typename ValueType>
int mxnet::Tuple< ValueType >::ndim_ {0}
protected

number of dimension of the tuple

template<typename ValueType>
int mxnet::Tuple< ValueType >::num_heap_allocated_ {0}
protected

number of cells allocated in data_heap_


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