MCPcopy
hub / github.com/lutzroeder/netron / transformLoop

Method transformLoop

source/python.js:18571–18601  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

18569 }
18570 }
18571 transformLoop(node) {
18572 const loop = new torch._C.LoopView(node);
18573 const body = loop.bodyBlock();
18574 const exit_pair = this.transformExits(body);
18575 if (this.getExitStatus(exit_pair) === 'WONT' || this.getExitStatus(exit_pair) === 'THROWS') {
18576 return this.constructWontExitPair();
18577 }
18578 const insert = new torch._C.WithInsertPoint(body);
18579 const new_if = this._graph.insertNode(this._graph.create('prim::If', 0));
18580 new_if.addInput(exit_pair.hasExited());
18581 new_if.addBlock().registerOutput(this._false_val);
18582 new_if.addBlock().registerOutput(loop.nextCond());
18583 const new_condition = new_if.addOutput().setType(torch.BoolType.get());
18584 loop.bodyBlock().eraseOutput(0);
18585 loop.bodyBlock().insertOutput(0, new_condition);
18586 node.addInput(this._false_val);
18587 body.addInput().setType(torch.BoolType.get());
18588 body.registerOutput(exit_pair.hasExited());
18589 const new_has_exited = node.addOutput().setType(torch.BoolType.get());
18590 for (const exit_value of exit_pair.exitValues()) {
18591 const typ = exit_value.type();
18592 node.addInput(this.getUnitValue(typ));
18593 node.addOutput().setType(typ);
18594 body.addInput().setType(typ);
18595 body.registerOutput(exit_value);
18596 }
18597 const exit_vals = node.outputs().slice(node.outputs().length - exit_pair.exitValues().size());
18598 const result = new torch._C.ExitPair(new_has_exited, exit_vals);
18599 insert.dispose();
18600 return result;
18601 }
18602 calcIfExitStatus(then_status, else_status) {
18603 if (then_status === 'THROWS') {
18604 return else_status;

Callers 1

transformExitsMethod · 0.80

Calls 15

bodyBlockMethod · 0.80
transformExitsMethod · 0.80
getExitStatusMethod · 0.80
constructWontExitPairMethod · 0.80
insertNodeMethod · 0.80
addInputMethod · 0.80
hasExitedMethod · 0.80
registerOutputMethod · 0.80
addBlockMethod · 0.80
nextCondMethod · 0.80
setTypeMethod · 0.80
addOutputMethod · 0.80

Tested by

no test coverage detected