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

Method emitLoopCommon

source/python.js:16796–16844  ·  view source on GitHub ↗
(range, emit_body, iter_val, targets, cond)

Source from the content-addressed store, hash-verified

16794 }
16795 }
16796 emitLoopCommon(range, emit_body, iter_val, targets, cond) {
16797 let max_trip_count_val = null;
16798 if (iter_val === null) {
16799 max_trip_count_val = torch._C.materializeConstant(Number.MAX_SAFE_INTEGER /*std::numeric_limits<int64_t>::max()*/, this.graph, range, this.integral_constants);
16800 } else {
16801 max_trip_count_val = iter_val.len(range, this.method);
16802 }
16803 const n = this.graph.insertNode(this.create('prim::Loop', range, 0));
16804 const body_block = n.addBlock();
16805 {
16806 const condition_block = n.addBlock();
16807 this.pushFrame(condition_block);
16808 let out = null;
16809 if (cond) {
16810 const insert = new torch._C.WithInsertPoint(condition_block);
16811 out = this.emitToBool(cond.range(), this.emitExpr(cond));
16812 insert.dispose();
16813 } else {
16814 const insert = new torch._C.WithInsertPoint(n);
16815 out = this.graph.insertConstant(true, range);
16816 insert.dispose();
16817 }
16818 condition_block.registerOutput(out);
16819 this.popFrame();
16820 }
16821 n.addInput(max_trip_count_val);
16822 const loop_guard = new torch._C.WithLoopStatus(this, 'IN_LOOP');
16823 const trip_count = body_block.addInput().setType(torch.IntType.get());
16824 {
16825 this.pushFrame(body_block);
16826 const guard = new torch._C.WithInsertPoint(body_block);
16827 if (iter_val !== null && targets) {
16828 const cur_elem = iter_val.getitem(range, this.method, trip_count).asValue(range, this.method);
16829 const sv = new torch._C.SimpleValue(cur_elem);
16830 const target_exprs = targets;
16831 this.validateAssignLhsExpr(target_exprs, range);
16832 if (target_exprs.length > 1) {
16833 throw new python.Error('Not implemented.');
16834 // const tl = torch.TupleLiteral.create(range, target_exprs);
16835 // target_exprs = ListExpr.create(range, [tl]);
16836 }
16837 this.emitExprsAssign(target_exprs, [sv], range, /*n_binders=*/1);
16838 }
16839 emit_body();
16840 this.popFrame();
16841 guard.dispose();
16842 }
16843 loop_guard.dispose();
16844 }
16845 emitFor(...args) {
16846 if (args.length === 1 && args[0] instanceof ast.For) {
16847 const [stmt] = args;

Callers 2

emitForMethod · 0.80
emitWhileMethod · 0.80

Calls 15

lenMethod · 0.80
insertNodeMethod · 0.80
addBlockMethod · 0.80
pushFrameMethod · 0.80
emitToBoolMethod · 0.80
emitExprMethod · 0.80
insertConstantMethod · 0.80
registerOutputMethod · 0.80
popFrameMethod · 0.80
addInputMethod · 0.80
setTypeMethod · 0.80
asValueMethod · 0.80

Tested by

no test coverage detected