ONE - On-device Neural Engine
Loading...
Searching...
No Matches
circle_resizer Namespace Reference

Data Structures

class  CircleModel
 
class  Dim
 
class  ModelEditor
 
class  Shape
 

Functions

std::ostream & operator<< (std::ostream &os, const Shape &shape)
 Print the shape in format [1, 2, 3].
 
std::vector< Shapeparse_shapes (const std::string &shapes)
 Parse shapes from string representation to Shapes object.
 

Function Documentation

◆ operator<<()

std::ostream & circle_resizer::operator<< ( std::ostream &  os,
const Shape shape 
)

Print the shape in format [1, 2, 3].

Definition at line 86 of file Shape.cpp.

87{
88 if (shape.is_scalar())
89 {
90 os << "[]";
91 return os;
92 }
93 os << "[";
94 for (int i = 0; i < shape.rank() - 1; ++i)
95 {
96 os << shape[i].value() << ", ";
97 }
98 os << shape[shape.rank() - 1].value() << "]";
99 return os;
100}
bool is_scalar() const
Returns true if the shape is a scalar. Otherwise, return false.
Definition Shape.cpp:58
size_t rank() const
Returns number of dimensions in the shape.

References circle_resizer::Shape::is_scalar(), and circle_resizer::Shape::rank().

◆ parse_shapes()

std::vector< Shape > circle_resizer::parse_shapes ( const std::string &  shapes)

Parse shapes from string representation to Shapes object.

The single shape is represented by comma-separated integers inside squared brackets. If there is more than one shape, they are separated by commas. An example for single shape: [1,2,3], an example for many shapes: [1,2,3],[4,5].

Exceptions: std::invalid_argument if the parsing failed.

Definition at line 65 of file ShapeParser.cpp.

66{
67 std::vector<Shape> result_shapes;
68 auto shapes_tmp = shapes;
69 std::string token;
70 size_t begin_pos = 0, end_pos = 0;
71 while ((begin_pos = shapes_tmp.find_first_of("[")) != std::string::npos &&
72 (end_pos = shapes_tmp.find_first_of("]")) != std::string::npos)
73 {
74 if (begin_pos > end_pos)
75 {
76 throw std::invalid_argument("Invalid shape format: " + shapes);
77 }
78 const size_t token_size = end_pos - begin_pos - 1;
79 token = shapes_tmp.substr(begin_pos + 1, token_size);
80 result_shapes.push_back(parse_single_shape(token));
81 shapes_tmp.erase(0, end_pos + 1);
82 }
83
84 if (result_shapes.empty())
85 {
86 throw std::invalid_argument("No shapes found in the input string: " + shapes);
87 }
88
89 // the rest of the input not handled by loop above cannot be processed properly
90 if (shapes_tmp.size() > 0 && !is_blank(shapes_tmp))
91 {
92 throw std::invalid_argument("The part of input shapes: " + shapes_tmp + " cannot be processed");
93 }
94
95 return result_shapes;
96}

Referenced by entry().