tvm
|
Array, container representing a contiguous sequence of ObjectRefs. More...
#include <array.h>
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... | |
ArrayNode * | GetArrayNode () 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... | |
ArrayNode * | CopyOnWrite () |
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 Object * | get () const |
const Object * | operator-> () 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 | |
Object * | get_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< Object > | data_ |
Internal pointer that backs the reference. More... | |
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.
T | The content ObjectRef type. |
using tvm::runtime::Array< T, typename >::ContainerType = ArrayNode |
specify container node
using tvm::runtime::Array< T, typename >::iterator = IterAdapter<ValueConverter, const ObjectRef*> |
using tvm::runtime::Array< T, typename >::reverse_iterator = ReverseIterAdapter<ValueConverter, const ObjectRef*> |
using tvm::runtime::Array< T, typename >::value_type = T |
|
inline |
default constructor
|
inline |
move constructor
other | source |
|
inline |
copy constructor
other | source |
|
inlineexplicit |
constructor from pointer
n | the container pointer |
|
inline |
Constructor from iterator.
first | begin of iterator |
last | end of iterator |
IterType | The type of iterator |
|
inline |
constructor from initializer list
init | The initializer list |
|
inline |
constructor from vector
init | The vector |
|
inlineexplicit |
Constructs a container with n elements. Each element is a copy of val.
n | The size of the container |
val | The init value |
|
inlinestatic |
Agregate arguments into a single Array<T>
args | sequence of T or Array<T> elements |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inline |
reset the array to content from iterator.
first | begin of iterator |
last | end of iterator |
IterType | The type of iterator |
|
inline |
|
inline |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inline |
|
inline |
Release reference to all the elements.
|
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.
|
inline |
|
inline |
|
inline |
Erase a given range of elements.
first | The begin iterator of the range |
last | The end iterator of the range |
|
inline |
Erase an element on the given position.
position | An iterator pointing to the element to be erased |
|
inline |
|
inline |
|
inline |
Insert an element into the given position.
position | An iterator pointing to the insertion point |
val | The element to insert |
|
inline |
Insert a range of elements into the given position.
position | An iterator pointing to the insertion point |
first | The begin iterator of the range |
last | The end iterator of the range |
|
inline |
Helper function to apply a map function onto the array.
fmap | The transformation function T -> U. |
F | The type of the mutation function. |
U | The 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. |
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.
|
inline |
Helper function to apply fmutate to mutate an array.
fmutate | The transformation function T -> T. |
F | the type of the mutation function. |
|
inline |
move assign operator
other | The source of assignment |
|
inline |
copy assign operator
other | The source of assignment |
|
inline |
Immutably read i-th element from array.
i | The index |
|
inline |
Remove the last item of the list.
|
inline |
push a new item to the back of the list
item | The item to be pushed. |
|
inline |
|
inline |
|
inline |
Make sure the list has the capacity of at least n.
n | lower bound of the capacity |
|
inline |
Resize the array.
n | The new size. |
|
inline |
set i-th element of the array.
i | The index |
value | The value to be setted. |
|
inline |