(range, emit_body, iter_val, targets, cond)
| 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; |
no test coverage detected