MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / parse_shape

Method parse_shape

lite/load_and_run/src/helpers/data_parser.cpp:267–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265}
266
267void DataParser::parse_shape(const std::string& name, const std::string& str) {
268 //! {d0,d1,..,dn}
269 mgb_assert(
270 "{" == str.substr(0, 1),
271 "invalid value: %s for parse_shape, valid format: {d0,d1,..,dn}\n",
272 str.c_str());
273 megdnn::SmallVector<size_t> shape;
274 std::string shape_size = "";
275 for (size_t i = 0; i < str.size(); ++i) {
276 char c = str[i];
277 if ('{' == c || ' ' == c) {
278 continue;
279 } else if (',' == c || '}' == c) {
280 shape.push_back(std::stoul(shape_size));
281 shape_size = "";
282 if ('}' == c) {
283 break;
284 }
285 } else {
286 shape_size += c;
287 }
288 }
289 mgb::HostTensorND hv(mgb::CompNode::default_cpu(), shape);
290 mgb::HostTensorStorage storage(mgb::CompNode::default_cpu());
291 hv.only_reset_raw_storage(storage);
292 inputs.insert(std::make_pair(name, std::move(hv)));
293}

Callers

nothing calls this directly

Calls 4

sizeMethod · 0.45
push_backMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected