forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_export_helpers.cpp
43 lines (34 loc) · 1.16 KB
/
import_export_helpers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <torch/csrc/jit/import_export_helpers.h>
#include <c10/util/Exception.h>
#include <algorithm>
namespace torch {
namespace jit {
namespace ImportExportHelpers {
static const std::string kExportPrefix = "libs/";
static const std::string kExportSuffix = "py";
std::string qualifierToPath(const std::string& qualifier) {
std::string path = qualifier;
std::replace_if(
path.begin(), path.end(), [](char c) { return c == '.'; }, '/');
return kExportPrefix + path + "." + kExportSuffix;
}
std::string pathToQualifier(const std::string& classPath) {
// strip input suffix
const auto end = classPath.rfind(kExportSuffix);
AT_ASSERT(end != std::string::npos);
// strip input suffix
size_t libs_idx = classPath.find(kExportPrefix);
AT_ASSERT(libs_idx == 0);
AT_ASSERT(classPath.size() > kExportPrefix.size());
const auto start = kExportPrefix.size();
std::string class_qualifier = classPath.substr(start, end - start);
std::replace_if(
class_qualifier.begin(),
class_qualifier.end(),
[](char c) { return c == '/'; },
'.');
return class_qualifier;
}
} // namespace ImportExportHelpers
} // namespace jit
} // namespace torch