mxnet
Classes | Public Types | Public Member Functions | List of all members
mxnet::Array< T, typename > Class Template Reference

Array container of NodeRef in DSL graph. Array implements copy on write semantics, which means array is mutable but copy will happen when array is referenced in more than two places. More...

#include <container.h>

Inheritance diagram for mxnet::Array< T, typename >:
Inheritance graph
Collaboration diagram for mxnet::Array< T, typename >:
Collaboration graph

Classes

struct  ValueConverter
 

Public Types

using ContainerType = ArrayNode
 specify container node More...
 
using iterator = IterAdapter< ValueConverter, std::vector< ObjectRef >::const_iterator >
 
using reverse_iterator = IterAdapter< ValueConverter, std::vector< ObjectRef >::const_reverse_iterator >
 

Public Member Functions

 Array ()
 default constructor More...
 
 Array (Array< T > &&other)
 move constructor More...
 
 Array (const Array< T > &other)
 copy constructor More...
 
 Array (runtime::ObjectPtr< Object > n)
 constructor from pointer More...
 
template<typename IterType >
 Array (IterType begin, IterType end)
 constructor from iterator More...
 
 Array (std::initializer_list< T > init)
 constructor from initializer list More...
 
 Array (const std::vector< T > &init)
 constructor from vector More...
 
 Array (size_t n, const T &val)
 Constructs a container with n elements. Each element is a copy of val. More...
 
Array< T > & operator= (Array< T > &&other)
 move assign operator More...
 
Array< T > & operator= (const Array< T > &other)
 copy assign operator More...
 
template<typename IterType >
void assign (IterType begin, IterType end)
 reset the array to content from iterator. More...
 
const T operator[] (size_t i) const
 Read i-th element from array. More...
 
size_t size () const
 
ArrayNodeCopyOnWrite ()
 copy on write semantics Do nothing if current handle is the unique copy of the array. Otherwise make a new copy of the array to ensure the current handle hold a unique copy. More...
 
void push_back (const T &item)
 push a new item to the back of the list More...
 
void resize (size_t size)
 Resize the array. More...
 
void Set (size_t i, const T &value)
 set i-th element of the array. More...
 
bool empty () const
 
template<typename F >
void MutateByApply (F fmutate)
 Helper function to apply fmutate to mutate an array. More...
 
iterator begin () const
 
iterator end () const
 
reverse_iterator rbegin () const
 
reverse_iterator rend () const
 

Detailed Description

template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
class mxnet::Array< T, typename >

Array container of NodeRef in DSL graph. Array implements copy on write semantics, which means array is mutable but copy will happen when array is referenced in more than two places.

operator[] only provide const acces, use Set to mutate the content.

Template Parameters
TThe content NodeRef type.

Member Typedef Documentation

template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
using mxnet::Array< T, typename >::ContainerType = ArrayNode

specify container node

template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
using mxnet::Array< T, typename >::iterator = IterAdapter<ValueConverter, std::vector<ObjectRef>::const_iterator>
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
using mxnet::Array< T, typename >::reverse_iterator = IterAdapter< ValueConverter, std::vector<ObjectRef>::const_reverse_iterator>

Constructor & Destructor Documentation

template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
mxnet::Array< T, typename >::Array ( )
inline

default constructor

template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
mxnet::Array< T, typename >::Array ( Array< T > &&  other)
inline

move constructor

Parameters
othersource
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
mxnet::Array< T, typename >::Array ( const Array< T > &  other)
inline

copy constructor

Parameters
othersource
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
mxnet::Array< T, typename >::Array ( runtime::ObjectPtr< Object >  n)
inlineexplicit

constructor from pointer

Parameters
nthe container pointer
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename IterType >
mxnet::Array< T, typename >::Array ( IterType  begin,
IterType  end 
)
inline

constructor from iterator

Parameters
beginbegin of iterator
endend of iterator
Template Parameters
IterTypeThe type of iterator
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
mxnet::Array< T, typename >::Array ( std::initializer_list< T >  init)
inline

constructor from initializer list

Parameters
initThe initalizer list
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
mxnet::Array< T, typename >::Array ( const std::vector< T > &  init)
inline

constructor from vector

Parameters
initThe vector
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
mxnet::Array< T, typename >::Array ( size_t  n,
const T &  val 
)
inlineexplicit

Constructs a container with n elements. Each element is a copy of val.

Parameters
nThe size of the container
valThe init value

Member Function Documentation

template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename IterType >
void mxnet::Array< T, typename >::assign ( IterType  begin,
IterType  end 
)
inline

reset the array to content from iterator.

Parameters
beginbegin of iterator
endend of iterator
Template Parameters
IterTypeThe type of iterator
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
iterator mxnet::Array< T, typename >::begin ( ) const
inline
Returns
begin iterator
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
ArrayNode* mxnet::Array< T, typename >::CopyOnWrite ( )
inline

copy on write semantics Do nothing if current handle is the unique copy of the array. Otherwise make a new copy of the array to ensure the current handle hold a unique copy.

Returns
Handle to the internal node container(which ganrantees to be unique)
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
bool mxnet::Array< T, typename >::empty ( ) const
inline
Returns
whether array is empty
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
iterator mxnet::Array< T, typename >::end ( ) const
inline
Returns
end iterator
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename F >
void mxnet::Array< T, typename >::MutateByApply ( fmutate)
inline

Helper function to apply fmutate to mutate an array.

Parameters
fmutateThe transformation function T -> T.
Template Parameters
Fthe type of the mutation function.
Note
This function performs copy on write optimization.
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
Array<T>& mxnet::Array< T, typename >::operator= ( Array< T > &&  other)
inline

move assign operator

Parameters
otherThe source of assignment
Returns
reference to self.
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
Array<T>& mxnet::Array< T, typename >::operator= ( const Array< T > &  other)
inline

copy assign operator

Parameters
otherThe source of assignment
Returns
reference to self.
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
const T mxnet::Array< T, typename >::operator[] ( size_t  i) const
inline

Read i-th element from array.

Parameters
iThe index
Returns
the i-th element.
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
void mxnet::Array< T, typename >::push_back ( const T &  item)
inline

push a new item to the back of the list

Parameters
itemThe item to be pushed.
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
reverse_iterator mxnet::Array< T, typename >::rbegin ( ) const
inline
Returns
rbegin iterator
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
reverse_iterator mxnet::Array< T, typename >::rend ( ) const
inline
Returns
rend iterator
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
void mxnet::Array< T, typename >::resize ( size_t  size)
inline

Resize the array.

Parameters
sizeThe new size.
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
void mxnet::Array< T, typename >::Set ( size_t  i,
const T &  value 
)
inline

set i-th element of the array.

Parameters
iThe index
valueThe value to be setted.
template<typename T, typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
size_t mxnet::Array< T, typename >::size ( ) const
inline
Returns
The size of the array

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