|
|
|
@ -37,12 +37,14 @@ NodesDFSIterator::NodesDFSIterator(const NodesDFSIterator &other)
|
|
|
|
|
: stack_(other.stack_), visited_(other.visited_) {}
|
|
|
|
|
|
|
|
|
|
Node &NodesDFSIterator::operator*() {
|
|
|
|
|
PADDLE_ENFORCE(!stack_.empty());
|
|
|
|
|
PADDLE_ENFORCE_EQ(stack_.empty(), false, platform::errors::OutOfRange(
|
|
|
|
|
"The iterator exceeds range."));
|
|
|
|
|
return *stack_.top();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NodesDFSIterator &NodesDFSIterator::operator++() {
|
|
|
|
|
PADDLE_ENFORCE(!stack_.empty(), "the iterator exceeds range");
|
|
|
|
|
PADDLE_ENFORCE_EQ(stack_.empty(), false, platform::errors::OutOfRange(
|
|
|
|
|
"The iterator exceeds range."));
|
|
|
|
|
visited_.insert(stack_.top());
|
|
|
|
|
auto *cur = stack_.top();
|
|
|
|
|
stack_.pop();
|
|
|
|
@ -73,11 +75,18 @@ inline bool CheckNodeIndegreeEquals(const Node &node, size_t n) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NodesTSIterator::NodesTSIterator(const std::vector<Node *> &source) {
|
|
|
|
|
PADDLE_ENFORCE(!source.empty(),
|
|
|
|
|
"Start points of topological sorting should not be empty!");
|
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
|
source.empty(), false,
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"Start points of topological sorting should not be empty!"));
|
|
|
|
|
// CHECK all the inputs' in-degree is 0
|
|
|
|
|
for (auto *node : source) {
|
|
|
|
|
PADDLE_ENFORCE(CheckNodeIndegreeEquals(*node, 0));
|
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
|
CheckNodeIndegreeEquals(*node, 0), true,
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"In start points of topological sorting, the indegree of each "
|
|
|
|
|
"point should be 0. Node(%s)'s indegree is not 0.",
|
|
|
|
|
node->Name()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::set<Node *> to_visit{source.begin(), source.end()};
|
|
|
|
@ -106,7 +115,11 @@ NodesTSIterator::NodesTSIterator(const NodesTSIterator &other)
|
|
|
|
|
: sorted_(other.sorted_), cursor_(other.cursor_) {}
|
|
|
|
|
|
|
|
|
|
Node &NodesTSIterator::operator*() {
|
|
|
|
|
PADDLE_ENFORCE_LT(cursor_, sorted_.size());
|
|
|
|
|
PADDLE_ENFORCE_LT(
|
|
|
|
|
cursor_, sorted_.size(),
|
|
|
|
|
platform::errors::OutOfRange(
|
|
|
|
|
"The iterator exceeds range. Container size is %d, but index is %d.",
|
|
|
|
|
sorted_.size(), cursor_));
|
|
|
|
|
return *sorted_[cursor_];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -128,7 +141,11 @@ bool NodesTSIterator::operator==(const NodesTSIterator &other) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node *NodesTSIterator::operator->() {
|
|
|
|
|
PADDLE_ENFORCE_LT(cursor_, sorted_.size());
|
|
|
|
|
PADDLE_ENFORCE_LT(
|
|
|
|
|
cursor_, sorted_.size(),
|
|
|
|
|
platform::errors::OutOfRange(
|
|
|
|
|
"The iterator exceeds range. Container size is %d, but index is %d.",
|
|
|
|
|
sorted_.size(), cursor_));
|
|
|
|
|
return sorted_[cursor_];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|