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 Types inherited from mxnet::runtime::ObjectRef
using ContainerType = Object
 type indicate the container type. More...
 

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
 
- Public Member Functions inherited from mxnet::runtime::ObjectRef
 ObjectRef ()=default
 default constructor More...
 
 ObjectRef (ObjectPtr< Object > data)
 Constructor from existing object ptr. More...
 
bool same_as (const ObjectRef &other) const
 Comparator. More...
 
bool operator== (const ObjectRef &other) const
 Comparator. More...
 
bool operator!= (const ObjectRef &other) const
 Comparator. More...
 
bool operator< (const ObjectRef &other) const
 Comparator. More...
 
bool defined () const
 
const Objectget () const
 
const Objectoperator-> () const
 
bool unique () const
 
template<typename ObjectType >
const ObjectType * as () const
 Try to downcast the internal Object to a raw pointer of a corresponding type. More...
 

Additional Inherited Members

- Protected Member Functions inherited from mxnet::runtime::ObjectRef
Objectget_mutable () const
 
- Static Protected Member Functions inherited from mxnet::runtime::ObjectRef
template<typename T >
static T DowncastNoCheck (ObjectRef ref)
 Internal helper function downcast a ref without check. More...
 
template<typename ObjectType >
static ObjectPtr< ObjectType > GetDataPtr (const ObjectRef &ref)
 Internal helper function get data_ as ObjectPtr of ObjectType. More...
 
- Protected Attributes inherited from mxnet::runtime::ObjectRef
ObjectPtr< Objectdata_
 Internal pointer that backs the reference. More...
 

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

◆ ContainerType

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

◆ iterator

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>

◆ reverse_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

◆ Array() [1/8]

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

default constructor

◆ Array() [2/8]

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

◆ Array() [3/8]

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

◆ Array() [4/8]

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

◆ Array() [5/8]

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

◆ Array() [6/8]

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

◆ Array() [7/8]

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

◆ Array() [8/8]

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

◆ assign()

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

◆ begin()

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

◆ CopyOnWrite()

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)

◆ empty()

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

◆ end()

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

◆ MutateByApply()

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.

◆ operator=() [1/2]

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.

◆ operator=() [2/2]

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.

◆ operator[]()

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.

◆ push_back()

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.

◆ rbegin()

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

◆ rend()

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

◆ resize()

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.

◆ Set()

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.

◆ size()

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: