Caffe2 - C++ API
A deep learning, cross platform ML framework
scope.cpp
1 #include <torch/csrc/jit/scope.h>
2 
3 namespace torch {
4 namespace jit {
5 
6 ScopePtr Scope::push(Symbol name) {
7  return c10::make_intrusive<Scope>(intrusive_from_this(), name);
8 }
9 
10 ScopePtr Scope::getRoot() {
11  ScopePtr current = intrusive_from_this();
12  while (current->parent_) {
13  current = current->parent_;
14  }
15  return current;
16 }
17 
18 size_t Scope::getDepth() {
19  size_t d = 1;
20  ScopePtr current = intrusive_from_this();
21  while (current->parent_) {
22  current = current->parent_;
23  d += 1;
24  }
25  return d;
26 }
27 
28 std::string Scope::namesFromRoot(const std::string& separator) const {
29  // TODO: I think the answer is we shouldn't have used Symbol here
30  std::string out = this->name_.toUnqualString();
31  if (this->isRoot()) {
32  return out;
33  }
34  ScopePtr parent = this->parent_;
35  while (!parent->isRoot()) {
36  // NOLINTNEXTLINE(performance-inefficient-string-concatenation)
37  out = std::string(parent->name_.toUnqualString()) + separator + out;
38  parent = parent->parent_;
39  }
40  return out;
41 }
42 
43 } // namespace jit
44 } // namespace torch
Definition: jit_type.h:17