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

Method feed

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

! * \brief feed different data to diffferent parser * \param path data file path or data string */

Source from the content-addressed store, hash-verified

10 * \param path data file path or data string
11 */
12void DataParser::feed(const std::string& path) {
13 std::string blob_name = "data", blob_string = path;
14 size_t sep = path.find(":");
15 if (sep != std::string::npos) {
16 blob_name = path.substr(0, sep);
17 blob_string = path.substr(sep + 1);
18 }
19
20 auto endWith = [blob_string](std::string suffix) -> bool {
21 const auto index = blob_string.rfind(suffix);
22 if (index != std::string::npos and
23 index == blob_string.length() - suffix.length()) {
24 return true;
25 }
26 return false;
27 };
28
29 if (endWith(".ppm") || endWith(".pgm")) {
30 parse_image(blob_name, blob_string);
31 } else if (endWith(".json")) {
32 parse_json(blob_string);
33 } else if (endWith(".npy")) {
34 parse_npy(blob_name, blob_string);
35 } else {
36 parse_string(blob_name, blob_string);
37 }
38}
39
40void DataParser::parse_json(const std::string& path) {
41 mgb::JsonLoader json;

Callers 3

command_hashFunction · 0.45

Calls 1

findMethod · 0.45

Tested by

no test coverage detected