@@ -460,77 +460,6 @@ inline bool CheckNodeIndegreeEquals(const Node &node, size_t n) {
460
460
return node.inputs .size () == n;
461
461
}
462
462
463
- NodesTSIterator::NodesTSIterator (const std::vector<Node *> &source) {
464
- PADDLE_ENFORCE (!source.empty (),
465
- " Start points of topological sorting should not be empty!" );
466
- // CHECK all the inputs' in-degree is 0
467
- for (auto *node : source) {
468
- PADDLE_ENFORCE (CheckNodeIndegreeEquals (*node, 0 ));
469
- }
470
-
471
- std::unordered_set<Node *> visited;
472
- std::unordered_set<Node *> to_visit{source.begin (), source.end ()};
473
-
474
- std::vector<Node *> inlink_visited;
475
- while (!to_visit.empty ()) {
476
- std::vector<Node *> queue (to_visit.begin (), to_visit.end ());
477
- for (auto *p : queue) {
478
- if (Agent (p).deleted ()) {
479
- visited.insert (p);
480
- to_visit.erase (p);
481
- }
482
-
483
- inlink_visited.clear ();
484
-
485
- std::copy_if (p->inputs .begin (), p->inputs .end (),
486
- std::back_inserter (inlink_visited),
487
- [&](Node *x) -> bool { return visited.count (x) != 0 ; });
488
-
489
- if (inlink_visited.size () == p->inputs .size ()) {
490
- sorted_.push_back (p);
491
- for (auto *_ : p->outputs ) {
492
- if (!visited.count (_)) {
493
- to_visit.insert (_);
494
- }
495
- }
496
-
497
- to_visit.erase (p);
498
- visited.insert (p);
499
- }
500
- }
501
- }
502
- }
503
-
504
- NodesTSIterator::NodesTSIterator (const NodesTSIterator &other)
505
- : sorted_(other.sorted_), cursor_(other.cursor_) {}
506
-
507
- Node &NodesTSIterator::operator *() {
508
- PADDLE_ENFORCE_LT (cursor_, sorted_.size ());
509
- return *sorted_[cursor_];
510
- }
511
-
512
- NodesTSIterator &NodesTSIterator::operator ++() {
513
- if (++cursor_ >= sorted_.size ()) {
514
- sorted_.clear ();
515
- cursor_ = 0 ;
516
- }
517
- return *this ;
518
- }
519
- NodesTSIterator &NodesTSIterator::operator =(const NodesTSIterator &other) {
520
- cursor_ = other.cursor_ ;
521
- sorted_ = other.sorted_ ;
522
- return *this ;
523
- }
524
-
525
- bool NodesTSIterator::operator ==(const NodesTSIterator &other) {
526
- return sorted_ == other.sorted_ && cursor_ == other.cursor_ ;
527
- }
528
-
529
- Node *NodesTSIterator::operator ->() {
530
- PADDLE_ENFORCE_LT (cursor_, sorted_.size ());
531
- return sorted_[cursor_];
532
- }
533
-
534
463
} // namespace analysis
535
464
} // namespace inference
536
465
} // namespace paddle
0 commit comments