Integrate liwchang/StagePreorderTraverse4 into master
This commit is contained in:
Коммит
9e549e7258
|
@ -3389,6 +3389,16 @@ namespace CNTK
|
|||
});
|
||||
}
|
||||
|
||||
///
|
||||
/// Recursively traverses the Function graph underlying 'this' Function invoking the provided functor for all visited nodes in the graph.
|
||||
/// A wrapper for PreorderTraverseFunctions.
|
||||
///
|
||||
template <typename FunctionType>
|
||||
void PreorderTraverse(const FunctionType& functor, bool traverseInsideBlockFunction = false)
|
||||
{
|
||||
PreorderTraverseFunctions(RootFunction(), functor, traverseInsideBlockFunction);
|
||||
}
|
||||
|
||||
///
|
||||
/// Find a function with the given name in the Function graph underlying 'this' Function.
|
||||
/// If more than one function with the same name, an exception is thrown.
|
||||
|
@ -3557,16 +3567,21 @@ namespace CNTK
|
|||
visitedFunctions.insert(rootFunction);
|
||||
functor(rootFunction);
|
||||
|
||||
if (traverseInsideBlockFunction && rootFunction->IsBlock())
|
||||
PreorderTraverseFunctions(rootFunction->BlockRoot(), visitedFunctions, functor, traverseInsideBlockFunction);
|
||||
|
||||
std::vector<Variable> rootFunctionInputs = rootFunction->Inputs();
|
||||
for (const auto& rootInput : rootFunctionInputs)
|
||||
if (rootFunction->IsComposite())
|
||||
PreorderTraverseFunctions(rootFunction->RootFunction(), visitedFunctions, functor, traverseInsideBlockFunction);
|
||||
else
|
||||
{
|
||||
if (rootInput.IsOutput() && visitedFunctions.find(rootInput.Owner()) == visitedFunctions.end())
|
||||
if (traverseInsideBlockFunction && rootFunction->IsBlock())
|
||||
PreorderTraverseFunctions(rootFunction->BlockRoot(), visitedFunctions, functor, traverseInsideBlockFunction);
|
||||
|
||||
std::vector<Variable> rootFunctionInputs = rootFunction->Inputs();
|
||||
for (const auto& rootInput : rootFunctionInputs)
|
||||
{
|
||||
const auto& function = rootInput.Owner();
|
||||
PreorderTraverseFunctions(function, visitedFunctions, functor, traverseInsideBlockFunction);
|
||||
if (rootInput.IsOutput() && visitedFunctions.find(rootInput.Owner()) == visitedFunctions.end())
|
||||
{
|
||||
const auto& function = rootInput.Owner();
|
||||
PreorderTraverseFunctions(function, visitedFunctions, functor, traverseInsideBlockFunction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче