torch/csrc/jit/passes/loop_unrolling.cpp
// Replaces the builtin loop counter with a "mutable" variable outside of the loop.
Replaces the builtin loop counter with a "mutable" variable outside of the loop.
Replaces the builtin loop counter with a " mutable " variable outside of the loop .
void replaceLoopCounter(Node *loop) {
  Graph *graph = loop->owningGraph();
  Block *body = loop->blocks().at(0);
  WithInsertPoint guard(loop);
  Value* init_counter = graph->insertConstant(0);
  loop->insertInput(2, init_counter);
  loop->insertOutput(0);
  Value * internal_counter = body->insertInput(1);
  body->inputs()[0]->replaceAllUsesWith(internal_counter);
  WithInsertPoint insertPointGuard{ body->return_node() };
  body->insertOutput(1, intMath(aten::add, internal_counter, 1) );
}
void replaceLoopCounter ( Node * loop ) { Graph * graph = loop -> owningGraph ( ) ; Block * body = loop -> blocks ( ) . at ( 0 ) ; WithInsertPoint guard ( loop ) ; Value * init_counter = graph -> insertConstant ( 0 ) ; loop -> insertInput ( 2 , init_counter ) ; loop -> insertOutput ( 0 ) ; Value * internal_counter = body -> insertInput ( 1 ) ; body -> inputs ( ) [ 0 ] -> replaceAllUsesWith ( internal_counter ) ; WithInsertPoint insertPointGuard { body -> return_node ( ) } ; body -> insertOutput ( 1 , intMath ( aten :: add , internal_counter , 1 ) ) ; }
Replaces the builtin loop counter with a "mutable" variable outside of the loop.
Replaces the builtin loop counter with a " mutable " variable outside of the loop .