Class to represent shape of a tensor.
More...
#include <Shape.h>
|
| Shape (uint32_t rank) |
| Construct a new Shape object.
|
|
| Shape (const std::initializer_list< int32_t > &dimensions) |
| Construct a new Shape object.
|
|
| Shape (const Shape &origin)=default |
| Construct a new Shape object.
|
|
void | prepend (int32_t d) |
| Add dimension to the beginning.
|
|
void | append (int32_t d) |
| Add dimension to the back.
|
|
uint32_t | rank (void) const |
| Get the rank of this shape.
|
|
int32_t | dim (uint32_t n) const |
| Get specific dimension.
|
|
int32_t & | dim (uint32_t n) |
| Get the reference of specific dimension.
|
|
const std::deque< int32_t > & | dims () const |
|
uint64_t | num_elements () const |
| Get the number of elements specified by this shape.
|
|
|
static Shape | from (const std::string &s) |
| Get a Shape object after parsing string.
|
|
Class to represent shape of a tensor.
Definition at line 44 of file Shape.h.
◆ Shape() [1/3]
nnfw::misc::tensor::Shape::Shape |
( |
uint32_t |
rank | ) |
|
|
inline |
Construct a new Shape object.
- Parameters
-
Definition at line 51 of file Shape.h.
51{ _dimensions.resize(
rank); }
uint32_t rank(void) const
Get the rank of this shape.
References rank().
◆ Shape() [2/3]
nnfw::misc::tensor::Shape::Shape |
( |
const std::initializer_list< int32_t > & |
dimensions | ) |
|
|
inline |
Construct a new Shape object.
- Parameters
-
[in] | dimensions | initializer_list<int32_t> of dimensions of tensor |
Definition at line 58 of file Shape.h.
58 : _dimensions{dimensions}
59 {
60
61 assert(dimensions.size() <= 0xFFFFFFFF);
62 }
◆ Shape() [3/3]
nnfw::misc::tensor::Shape::Shape |
( |
const Shape & |
origin | ) |
|
|
default |
Construct a new Shape object.
- Parameters
-
[in] | origin | Shape object to copy |
◆ append()
void nnfw::misc::tensor::Shape::append |
( |
int32_t |
d | ) |
|
|
inline |
Add dimension to the back.
- Parameters
-
[in] | d | dimension to add to the back |
- Returns
- N/A
Definition at line 83 of file Shape.h.
83{ _dimensions.emplace_back(d); }
Referenced by from().
◆ dim() [1/2]
int32_t & nnfw::misc::tensor::Shape::dim |
( |
uint32_t |
n | ) |
|
|
inline |
Get the reference of specific dimension.
- Parameters
-
- Returns
- Reference of n'th dimension
Definition at line 107 of file Shape.h.
107{ return _dimensions.at(n); }
◆ dim() [2/2]
int32_t nnfw::misc::tensor::Shape::dim |
( |
uint32_t |
n | ) |
const |
|
inline |
◆ dims()
const std::deque< int32_t > & nnfw::misc::tensor::Shape::dims |
( |
| ) |
const |
|
inline |
Definition at line 109 of file Shape.h.
109{ return _dimensions; }
◆ from()
Shape Shape::from |
( |
const std::string & |
s | ) |
|
|
static |
Get a Shape
object after parsing string.
- Parameters
-
[in] | s | String of dimension list. Accepted format is numbers separated by comma. |
- Returns
Shape
object
Definition at line 48 of file Shape.cpp.
49{
51
52 bool pending = false;
53 int value = 0;
54
55 for (
const char *cur =
str.c_str();
true; ++cur)
56 {
57 if (*cur == ',' || *cur == '\0')
58 {
59 if (pending)
60 {
61 shape.append(value);
62 }
63
64 if (*cur == '\0')
65 {
66 break;
67 }
68
69 pending = false;
70 value = 0;
71 continue;
72 }
73
74 assert(*cur >= '0' && *cur <= '9');
75
76 pending = true;
77 value *= 10;
78 value += *cur - '0';
79 }
80
81 return shape;
82}
std::string str(Args &&...args)
References append(), and nnfw::misc::str().
◆ num_elements()
uint64_t Shape::num_elements |
( |
| ) |
const |
Get the number of elements specified by this shape.
- Returns
- The number of elements
Definition at line 84 of file Shape.cpp.
85{
86 return std::accumulate(_dimensions.cbegin(), _dimensions.cend(), UINT64_C(1),
87 std::multiplies<uint64_t>());
88}
◆ prepend()
void nnfw::misc::tensor::Shape::prepend |
( |
int32_t |
d | ) |
|
|
inline |
Add dimension to the beginning.
- Parameters
-
[in] | d | dimension to add to the beginning |
- Returns
- N/A
Definition at line 76 of file Shape.h.
76{ _dimensions.emplace_front(d); }
◆ rank()
uint32_t nnfw::misc::tensor::Shape::rank |
( |
void |
| ) |
const |
|
inline |
The documentation for this class was generated from the following files:
- runtime/libs/misc/include/misc/tensor/Shape.h
- runtime/libs/misc/src/tensor/Shape.cpp