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

Array, container representing a contiguous sequence of ObjectRefs. More...

#include <array.h>

Inheritance diagram for tvm::runtime::Array< T, typename >:
Collaboration diagram for tvm::runtime::Array< T, typename >:

Classes

struct  ValueConverter
 

Public Types

using value_type = T
 
using iterator = IterAdapter< ValueConverter, const ObjectRef * >
 
using reverse_iterator = ReverseIterAdapter< ValueConverter, const ObjectRef * >
 
using ContainerType = ArrayNode
 specify container node More...
 
- Public Types inherited from tvm::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 (ObjectPtr< Object > n)
 constructor from pointer More...
 
template<typename IterType >
 Array (IterType first, IterType last)
 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 (const 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...
 
iterator begin () const
 
iterator end () const
 
reverse_iterator rbegin () const
 
reverse_iterator rend () const
 
const T operator[] (int64_t i) const
 Immutably read i-th element from array. More...
 
size_t size () const
 
size_t capacity () const
 
bool empty () const
 
const T front () const
 
const T back () const
 
void push_back (const T &item)
 push a new item to the back of the list More...
 
void insert (iterator position, const T &val)
 Insert an element into the given position. More...
 
template<typename IterType >
void insert (iterator position, IterType first, IterType last)
 Insert a range of elements into the given position. More...
 
void pop_back ()
 Remove the last item of the list. More...
 
void erase (iterator position)
 Erase an element on the given position. More...
 
void erase (iterator first, iterator last)
 Erase a given range of elements. More...
 
void resize (int64_t n)
 Resize the array. More...
 
void reserve (int64_t n)
 Make sure the list has the capacity of at least n. More...
 
void clear ()
 Release reference to all the elements. More...
 
void Set (int64_t i, T value)
 set i-th element of the array. More...
 
ArrayNodeGetArrayNode () const
 
template<typename F , typename U = std::invoke_result_t<F, T>>
Array< U > Map (F fmap) const
 Helper function to apply a map function onto the array. More...
 
template<typename F , typename = std::enable_if_t<std::is_same_v<T, std::invoke_result_t<F, T>>>>
void MutateByApply (F fmutate)
 Helper function to apply fmutate to mutate an array. More...
 
template<typename IterType >
void Assign (IterType first, IterType last)
 reset the array to content from iterator. More...
 
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...
 
- Public Member Functions inherited from tvm::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
 
int use_count () const
 
template<typename ObjectType , typename = std::enable_if_t<std::is_base_of_v<Object, ObjectType>>>
const ObjectType * as () const
 Try to downcast the internal Object to a raw pointer of a corresponding type. More...
 
template<typename ObjectRefType , typename = std::enable_if_t<std::is_base_of_v<ObjectRef, ObjectRefType>>>
Optional< ObjectRefType > as () const
 Try to downcast the ObjectRef to a Optional<T> of the requested type. More...
 

Static Public Member Functions

template<typename... Args>
static size_t CalcCapacityImpl ()
 
template<typename... Args>
static size_t CalcCapacityImpl (Array< T > value, Args... args)
 
template<typename... Args>
static size_t CalcCapacityImpl (T value, Args... args)
 
template<typename... Args>
static void AgregateImpl (Array< T > &dest)
 
template<typename... Args>
static void AgregateImpl (Array< T > &dest, Array< T > value, Args... args)
 
template<typename... Args>
static void AgregateImpl (Array< T > &dest, T value, Args... args)
 
template<typename... Args>
static Array< T > Agregate (Args... args)
 Agregate arguments into a single Array<T> More...
 

Additional Inherited Members

- Static Public Attributes inherited from tvm::runtime::ObjectRef
static constexpr bool _type_is_nullable = true
 
- Protected Member Functions inherited from tvm::runtime::ObjectRef
Objectget_mutable () const
 
- Static Protected Member Functions inherited from tvm::runtime::ObjectRef
template<typename T >
static T DowncastNoCheck (ObjectRef ref)
 Internal helper function downcast a ref without check. More...
 
static void FFIClearAfterMove (ObjectRef *ref)
 Clear the object ref data field without DecRef after we successfully moved the field. 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 tvm::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 tvm::runtime::Array< T, typename >

Array, container representing a contiguous sequence of ObjectRefs.

Array implements in-place copy-on-write semantics.

As in typical copy-on-write, a method which would typically mutate the array instead opaquely copies the underlying container, and then acts on its copy.

If the array has reference count equal to one, we directly update the container in place without copying. This is optimization is sound because when the reference count is equal to one this reference is guranteed to be the sole pointer to the container.

operator[] only provides const access, use Set to mutate the content.

Template Parameters
TThe content ObjectRef type.

Member Typedef Documentation

◆ ContainerType

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
using tvm::runtime::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 tvm::runtime::Array< T, typename >::iterator = IterAdapter<ValueConverter, const ObjectRef*>

◆ reverse_iterator

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
using tvm::runtime::Array< T, typename >::reverse_iterator = ReverseIterAdapter<ValueConverter, const ObjectRef*>

◆ value_type

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
using tvm::runtime::Array< T, typename >::value_type = T

Constructor & Destructor Documentation

◆ Array() [1/8]

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
tvm::runtime::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>
tvm::runtime::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>
tvm::runtime::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>
tvm::runtime::Array< T, typename >::Array ( 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 >
tvm::runtime::Array< T, typename >::Array ( IterType  first,
IterType  last 
)
inline

Constructor from iterator.

Parameters
firstbegin of iterator
lastend 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>
tvm::runtime::Array< T, typename >::Array ( std::initializer_list< T >  init)
inline

constructor from initializer list

Parameters
initThe initializer list

◆ Array() [7/8]

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
tvm::runtime::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>
tvm::runtime::Array< T, typename >::Array ( const 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

◆ Agregate()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename... Args>
static Array<T> tvm::runtime::Array< T, typename >::Agregate ( Args...  args)
inlinestatic

Agregate arguments into a single Array<T>

Parameters
argssequence of T or Array<T> elements
Returns
Agregated Array<T>

◆ AgregateImpl() [1/3]

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename... Args>
static void tvm::runtime::Array< T, typename >::AgregateImpl ( Array< T > &  dest)
inlinestatic

◆ AgregateImpl() [2/3]

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename... Args>
static void tvm::runtime::Array< T, typename >::AgregateImpl ( Array< T > &  dest,
Array< T >  value,
Args...  args 
)
inlinestatic

◆ AgregateImpl() [3/3]

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename... Args>
static void tvm::runtime::Array< T, typename >::AgregateImpl ( Array< T > &  dest,
value,
Args...  args 
)
inlinestatic

◆ Assign()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename IterType >
void tvm::runtime::Array< T, typename >::Assign ( IterType  first,
IterType  last 
)
inline

reset the array to content from iterator.

Parameters
firstbegin of iterator
lastend of iterator
Template Parameters
IterTypeThe type of iterator

◆ back()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
const T tvm::runtime::Array< T, typename >::back ( ) const
inline
Returns
The last element of the array

◆ begin()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
iterator tvm::runtime::Array< T, typename >::begin ( ) const
inline
Returns
begin iterator

◆ CalcCapacityImpl() [1/3]

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename... Args>
static size_t tvm::runtime::Array< T, typename >::CalcCapacityImpl ( )
inlinestatic

◆ CalcCapacityImpl() [2/3]

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename... Args>
static size_t tvm::runtime::Array< T, typename >::CalcCapacityImpl ( Array< T >  value,
Args...  args 
)
inlinestatic

◆ CalcCapacityImpl() [3/3]

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename... Args>
static size_t tvm::runtime::Array< T, typename >::CalcCapacityImpl ( value,
Args...  args 
)
inlinestatic

◆ capacity()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
size_t tvm::runtime::Array< T, typename >::capacity ( ) const
inline
Returns
The capacity of the array

◆ clear()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
void tvm::runtime::Array< T, typename >::clear ( )
inline

Release reference to all the elements.

◆ CopyOnWrite()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
ArrayNode* tvm::runtime::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 tvm::runtime::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 tvm::runtime::Array< T, typename >::end ( ) const
inline
Returns
end iterator

◆ erase() [1/2]

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
void tvm::runtime::Array< T, typename >::erase ( iterator  first,
iterator  last 
)
inline

Erase a given range of elements.

Parameters
firstThe begin iterator of the range
lastThe end iterator of the range

◆ erase() [2/2]

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
void tvm::runtime::Array< T, typename >::erase ( iterator  position)
inline

Erase an element on the given position.

Parameters
positionAn iterator pointing to the element to be erased

◆ front()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
const T tvm::runtime::Array< T, typename >::front ( ) const
inline
Returns
The first element of the array

◆ GetArrayNode()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
ArrayNode* tvm::runtime::Array< T, typename >::GetArrayNode ( ) const
inline
Returns
The underlying ArrayNode

◆ insert() [1/2]

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
void tvm::runtime::Array< T, typename >::insert ( iterator  position,
const T &  val 
)
inline

Insert an element into the given position.

Parameters
positionAn iterator pointing to the insertion point
valThe element to insert

◆ insert() [2/2]

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename IterType >
void tvm::runtime::Array< T, typename >::insert ( iterator  position,
IterType  first,
IterType  last 
)
inline

Insert a range of elements into the given position.

Parameters
positionAn iterator pointing to the insertion point
firstThe begin iterator of the range
lastThe end iterator of the range

◆ Map()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename F , typename U = std::invoke_result_t<F, T>>
Array<U> tvm::runtime::Array< T, typename >::Map ( fmap) const
inline

Helper function to apply a map function onto the array.

Parameters
fmapThe transformation function T -> U.
Template Parameters
FThe type of the mutation function.
UThe type of the returned array, inferred from the return type of F. If overridden by the user, must be something that is convertible from the return type of F.
Note
This function performs copy on write optimization. If fmap returns an object of type T, and all elements of the array are mapped to themselves, then the returned array will be the same as the original, and reference counts of the elements in the array will not be incremented.
Returns
The transformed array.

◆ MutateByApply()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
template<typename F , typename = std::enable_if_t<std::is_same_v<T, std::invoke_result_t<F, T>>>>
void tvm::runtime::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>& tvm::runtime::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>& tvm::runtime::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 tvm::runtime::Array< T, typename >::operator[] ( int64_t  i) const
inline

Immutably read i-th element from array.

Parameters
iThe index
Returns
the i-th element.

◆ pop_back()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
void tvm::runtime::Array< T, typename >::pop_back ( )
inline

Remove the last item of the list.

◆ push_back()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
void tvm::runtime::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 tvm::runtime::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 tvm::runtime::Array< T, typename >::rend ( ) const
inline
Returns
rend iterator

◆ reserve()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
void tvm::runtime::Array< T, typename >::reserve ( int64_t  n)
inline

Make sure the list has the capacity of at least n.

Parameters
nlower bound of the capacity

◆ resize()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
void tvm::runtime::Array< T, typename >::resize ( int64_t  n)
inline

Resize the array.

Parameters
nThe new size.

◆ Set()

template<typename T , typename = typename std::enable_if<std::is_base_of<ObjectRef, T>::value>::type>
void tvm::runtime::Array< T, typename >::Set ( int64_t  i,
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 tvm::runtime::Array< T, typename >::size ( ) const
inline
Returns
The size of the array

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