MCPcopy Create free account
hub / github.com/alibaba/MNN / parseDims

Function parseDims

tools/cpp/MNN2QNNModel.cpp:94–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94static bool parseDims(const std::string& s, std::vector<std::vector<int>>& out) {
95 auto isLegal = [](char c) {
96 return c == 'x' || c == '_' || (c >= '0' && c <= '9');
97 };
98 bool allLegal = std::all_of(s.begin(), s.end(), isLegal);
99 if(!allLegal) {
100 return false;
101 }
102
103 out.clear();
104 std::stringstream ss(s);
105 std::string segment;
106 MNN_PRINT("param dims: %s\n", s.c_str());
107 while (std::getline(ss, segment, '_')) {
108 if (segment.empty()) {
109 MNN_ERROR("%s parse error, format should be like 1x3x512x512_1x256\n", s.c_str());
110 return false;
111 }
112 std::vector<int> dims;
113 std::stringstream inner(segment);
114 std::string token;
115
116 while (std::getline(inner, token, 'x')) {
117 if (token.empty()) {
118 MNN_ERROR("%s parse error, format should be like 1x3x512x512_1x256\n", s.c_str());
119 return false;
120 }
121 int val = std::stoi(token);
122 dims.push_back(val);
123 }
124 if (dims.empty()) {
125 MNN_ERROR("%s parse error, format should be like 1x3x512x512_1x256\n", s.c_str());
126 return false;
127 }
128 out.push_back(dims);
129 }
130 return true;
131}
132
133static bool checkSystem() {
134#ifdef _WIN32

Callers 1

mainFunction · 0.85

Calls 6

beginMethod · 0.45
endMethod · 0.45
clearMethod · 0.45
c_strMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected