ONE - On-device Neural Engine
Loading...
Searching...
No Matches
circle_resizer::Shape Class Reference

#include <Shape.h>

Public Member Functions

 Shape (const std::initializer_list< Dim > &dims)
 Initialize shape with initializer list of dims.
 
 Shape (const std::vector< Dim > &shape_vec)
 Initialize shape with vector of dims.
 
 Shape (const std::initializer_list< uint32_t > &shape_vec)
 Initialize static shape with initializer list of of uint32_t values.
 
size_t rank () const
 Returns number of dimensions in the shape.
 
Dim operator[] (const size_t &axis) const
 Returns dimension of the position determined by axis.
 
bool is_scalar () const
 Returns true if the shape is a scalar. Otherwise, return false.
 
bool is_dynamic () const
 Returns true if all dimensions in the shape are static or the shape is a scalar. Otherwise, return false.
 
bool operator== (const Shape &rhs) const
 Returns true of the current shape and the provided rhs are equal.
 

Static Public Member Functions

static Shape scalar ()
 Create scalar shape. Note, that the same can be achieved with Shape{}.
 

Detailed Description

The representation of a single shape.

Definition at line 31 of file Shape.h.

Constructor & Destructor Documentation

◆ Shape() [1/3]

Shape::Shape ( const std::initializer_list< Dim > &  dims)

Initialize shape with initializer list of dims.

Definition at line 24 of file Shape.cpp.

24: _dims{dims} {}
std::vector< int > dims(const std::string &src)
Definition Utils.h:35

◆ Shape() [2/3]

Shape::Shape ( const std::vector< Dim > &  shape_vec)

Initialize shape with vector of dims.

Definition at line 26 of file Shape.cpp.

26: _dims{shape_vec} {}

◆ Shape() [3/3]

Shape::Shape ( const std::initializer_list< uint32_t > &  shape_vec)

Initialize static shape with initializer list of of uint32_t values.

Exceptions:

  • std::out_of_range if some elements in shape_vec exceed int32_t range.

Definition at line 28 of file Shape.cpp.

29{
30 for (const auto &dim : shape_vec)
31 {
32 if (dim >= std::numeric_limits<int32_t>::max())
33 {
34 std::out_of_range("Provided dimension: " + std::to_string(dim) + " is out of range");
35 }
36 _dims.emplace_back(Dim{static_cast<int32_t>(dim)});
37 }
38}

Member Function Documentation

◆ is_dynamic()

bool Shape::is_dynamic ( ) const

Returns true if all dimensions in the shape are static or the shape is a scalar. Otherwise, return false.

Definition at line 60 of file Shape.cpp.

61{
62 if (is_scalar())
63 {
64 return false;
65 }
66 return std::any_of(std::begin(_dims), std::end(_dims),
67 [](const Dim &dim) { return dim.is_dynamic(); });
68}
bool is_dynamic() const
Returns true if the dimension is dynamic. Otherwise, return false.
Definition Dim.cpp:33
bool is_scalar() const
Returns true if the shape is a scalar. Otherwise, return false.
Definition Shape.cpp:58

References circle_resizer::Dim::is_dynamic(), and is_scalar().

◆ is_scalar()

bool Shape::is_scalar ( ) const

Returns true if the shape is a scalar. Otherwise, return false.

Definition at line 58 of file Shape.cpp.

58{ return _dims.empty(); }

Referenced by is_dynamic(), circle_resizer::operator<<(), and operator[]().

◆ operator==()

bool circle_resizer::Shape::operator== ( const Shape rhs) const

Returns true of the current shape and the provided rhs are equal.

◆ operator[]()

Dim Shape::operator[] ( const size_t &  axis) const

Returns dimension of the position determined by axis.

Exceptions:

  • std::invalid_argument if the method is called on a scalar shape.
  • std::out_of_range if the provided axis is greater than rank.

Definition at line 44 of file Shape.cpp.

45{
46 if (is_scalar())
47 {
48 throw std::invalid_argument("You cannot gather dimension from a scalar");
49 }
50 if (axis > rank() - 1)
51 {
52 throw std::out_of_range("Axis=" + std::to_string(axis) +
53 " is out of range of shape's rank: " + std::to_string(rank()));
54 }
55 return _dims[axis];
56}
size_t rank() const
Returns number of dimensions in the shape.

References is_scalar(), and rank().

◆ rank()

size_t circle_resizer::Shape::rank ( ) const

Returns number of dimensions in the shape.

Referenced by circle_resizer::operator<<(), and operator[]().

◆ scalar()

Shape Shape::scalar ( )
static

Create scalar shape. Note, that the same can be achieved with Shape{}.

Definition at line 40 of file Shape.cpp.

40{ return Shape{std::initializer_list<Dim>{}}; }
Definition Shape.h:28

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