24 #ifndef TVM_RUNTIME_CONTAINER_SHAPE_TUPLE_H_
25 #define TVM_RUNTIME_CONTAINER_SHAPE_TUPLE_H_
50 static constexpr
const char*
_type_key =
"runtime.ShapeTuple";
73 explicit FromStd(std::vector<index_type> other) : data_container{other} {}
77 std::vector<index_type> data_container;
101 template <
typename IterType>
140 ICHECK(idx < this->
size()) <<
"IndexError: indexing " << idx <<
" on an array of size "
142 return this->
data()[idx];
171 auto ptr = make_object<ShapeTupleObj::FromStd>(std::move(
shape));
172 ptr->size = ptr->data_container.size();
173 ptr->data = ptr->data_container.data();
174 data_ = std::move(ptr);
179 for (
int i = 0, n = this->
size; i < n; ++i) {
180 numel *= this->
data[i];
187 for (
size_t i = 0; i <
shape->size; ++i) {
191 os <<
shape->data[i];
Base class of all object reference.
Definition: object.h:519
const Object * get() const
Definition: object.h:554
ObjectPtr< Object > data_
Internal pointer that backs the reference.
Definition: object.h:605
base class of all object containers.
Definition: object.h:171
An object representing shape tuple moved from std::vector.
Definition: shape_tuple.h:61
FromStd(std::vector< index_type > other)
Construct a new FromStd object.
Definition: shape_tuple.h:73
ShapeTupleObj::index_type index_type
The type of shape index element.
Definition: shape_tuple.h:64
An object representing a shape tuple.
Definition: shape_tuple.h:37
index_type * data
The pointer to shape tuple data.
Definition: shape_tuple.h:42
int64_t index_type
The type of shape index element.
Definition: shape_tuple.h:40
TVM_DECLARE_FINAL_OBJECT_INFO(ShapeTupleObj, Object)
uint64_t size
The size of the shape tuple object.
Definition: shape_tuple.h:44
static constexpr const uint32_t _type_index
Definition: shape_tuple.h:49
index_type Product() const
Get "numel", meaning the number of elements of an array if the array has this shape.
Definition: shape_tuple.h:177
static constexpr const char * _type_key
Definition: shape_tuple.h:50
Reference to shape tuple objects.
Definition: shape_tuple.h:85
index_type at(size_t idx) const
Immutably read i-th element from the shape tuple.
Definition: shape_tuple.h:150
const index_type * data() const
Return the data pointer.
Definition: shape_tuple.h:125
index_type back() const
Definition: shape_tuple.h:159
index_type operator[](size_t idx) const
Immutably read i-th element from the shape tuple.
Definition: shape_tuple.h:139
size_t size() const
Return the size of the shape tuple.
Definition: shape_tuple.h:132
ShapeTuple(IterType begin, IterType end)
Constructor from iterator.
Definition: shape_tuple.h:102
ShapeTuple(std::initializer_list< index_type > shape)
constructor from initializer list
Definition: shape_tuple.h:108
bool empty() const
Definition: shape_tuple.h:153
const index_type * begin() const
Definition: shape_tuple.h:162
ShapeTuple()
Construct an empty shape tuple.
Definition: shape_tuple.h:93
const index_type * end() const
Definition: shape_tuple.h:165
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ShapeTuple, ObjectRef, ShapeTupleObj)
ShapeTupleObj::index_type index_type
The type of shape index element.
Definition: shape_tuple.h:88
index_type front() const
Definition: shape_tuple.h:156
ShapeTuple IntTuple
Definition: shape_tuple.h:197
ShapeTupleObj IntTupleObj
Definition: shape_tuple.h:198
std::ostream & operator<<(std::ostream &os, const ObjectRef &n)
Definition: repr_printer.h:97
Tensor shape(const Tensor &src, DataType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:1913
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
@ kRuntimeShapeTuple
runtime::ShapeTuple.
Definition: object.h:72