23#ifndef __NNFW_MISC_TENSOR_SHAPE_H__
24#define __NNFW_MISC_TENSOR_SHAPE_H__
29#include <initializer_list>
58 Shape(
const std::initializer_list<int32_t> &dimensions) : _dimensions{dimensions}
61 assert(dimensions.size() <= 0xFFFFFFFF);
76 void prepend(int32_t d) { _dimensions.emplace_front(d); }
83 void append(int32_t d) { _dimensions.emplace_back(d); }
92 uint32_t
rank(
void)
const {
return static_cast<uint32_t
>(_dimensions.size()); }
100 int32_t
dim(uint32_t n)
const {
return _dimensions.at(n); }
107 int32_t &
dim(uint32_t n) {
return _dimensions.at(n); }
109 const std::deque<int32_t> &
dims()
const {
return _dimensions; }
119 std::deque<int32_t> _dimensions;
Class to represent shape of a tensor.
const std::deque< int32_t > & dims() const
int32_t dim(uint32_t n) const
Get specific dimension.
void append(int32_t d)
Add dimension to the back.
static Shape from(const std::string &s)
Get a Shape object after parsing string.
void prepend(int32_t d)
Add dimension to the beginning.
Shape(const Shape &origin)=default
Construct a new Shape object.
uint32_t rank(void) const
Get the rank of this shape.
Shape(uint32_t rank)
Construct a new Shape object.
uint64_t num_elements() const
Get the number of elements specified by this shape.
Shape(const std::initializer_list< int32_t > &dimensions)
Construct a new Shape object.
int32_t & dim(uint32_t n)
Get the reference of specific dimension.
bool operator==(const Shape &, const Shape &)
Check equality of two Shape.
std::ostream & operator<<(std::ostream &os, const IndexFormatter &fmt)
Send IndexFormatter object to output stream.