mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/16472 Differential Revision: D13852553 Pulled By: ZolotukhinM fbshipit-source-id: d5634982c2c42e704d9902774a77660e05fd71eb
45 lines
1.0 KiB
C++
45 lines
1.0 KiB
C++
#include <torch/csrc/jit/scope.h>
|
|
|
|
namespace torch {
|
|
namespace jit {
|
|
|
|
ScopePtr Scope::push(Symbol name) {
|
|
return c10::make_intrusive<Scope>(intrusive_from_this(), name);
|
|
}
|
|
|
|
ScopePtr Scope::getRoot() {
|
|
ScopePtr current = intrusive_from_this();
|
|
while (current->parent_) {
|
|
current = current->parent_;
|
|
}
|
|
return current;
|
|
}
|
|
|
|
size_t Scope::getDepth() {
|
|
size_t d = 1;
|
|
ScopePtr current = intrusive_from_this();
|
|
while (current->parent_) {
|
|
current = current->parent_;
|
|
d += 1;
|
|
}
|
|
return d;
|
|
}
|
|
|
|
std::string Scope::namesFromRoot(const std::string& separator) const {
|
|
// TODO: I think the answer is we shouldn't have used Symbol here
|
|
std::string out = this->name_.toUnqualString();
|
|
if (this->isRoot()) {
|
|
return out;
|
|
}
|
|
ScopePtr parent = this->parent_;
|
|
while (!parent->isRoot()) {
|
|
// NOLINTNEXTLINE(performance-inefficient-string-concatenation)
|
|
out = std::string(parent->name_.toUnqualString()) + separator + out;
|
|
parent = parent->parent_;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
} // namespace jit
|
|
} // namespace torch
|