From 7924860b9ff2d6993a71a14ff02a9ad3eb18a240 Mon Sep 17 00:00:00 2001 From: DannyIsFunny <912790387@qq.com> Date: Fri, 20 Mar 2020 02:56:58 +0000 Subject: [PATCH] test=develop --- lite/api/cxx_api.cc | 2 +- lite/core/scope.cc | 13 +++++++++++++ lite/core/scope.h | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lite/api/cxx_api.cc b/lite/api/cxx_api.cc index e8d11370d1..12ddcf3980 100644 --- a/lite/api/cxx_api.cc +++ b/lite/api/cxx_api.cc @@ -152,7 +152,7 @@ std::vector Predictor::GetOutputNames() { return output_names_; } // get param names std::vector Predictor::GetParamNames() { - return exec_scope_->LocalVarNames(); + return exec_scope_->VarNames(); } // append the names of inputs and outputs into input_names_ and output_names_ diff --git a/lite/core/scope.cc b/lite/core/scope.cc index 775652e2a0..1bb3388298 100644 --- a/lite/core/scope.cc +++ b/lite/core/scope.cc @@ -60,6 +60,19 @@ Variable *Scope::FindLocalVar(const std::string &name) const { return nullptr; } +std::vector Scope::VarNames() const { + std::vector resulted_keys; + auto keys = LocalVarNames(); + resulted_keys.insert(resulted_keys.end(), keys.begin(), keys.end()); + const Scope *cur_scope = this; + while (cur_scope->parent()) { + cur_scope = cur_scope->parent(); + keys = cur_scope->LocalVarNames(); + resulted_keys.insert(resulted_keys.end(), keys.begin(), keys.end()); + } + return resulted_keys; +} + std::vector Scope::LocalVarNames() const { std::vector keys; for (const auto &item : vars_) { diff --git a/lite/core/scope.h b/lite/core/scope.h index 2593c36522..f424307073 100644 --- a/lite/core/scope.h +++ b/lite/core/scope.h @@ -45,6 +45,8 @@ class Scope final { const Scope* parent() const { return parent_; } + // Get all params in each scope. + std::vector VarNames() const; // Following the legacy scope interface. std::vector LocalVarNames() const; -- GitLab