(form, apply, sv, type_hint)
| 17431 | return attributes.map((attr) => new torch._C.NamedValue(attr.range(), attr.arg, this.emitExpr(attr.value))); |
| 17432 | } |
| 17433 | emitApplySpecialForm(form, apply, sv, type_hint) { |
| 17434 | switch (form) { |
| 17435 | case 'prim::fork': { |
| 17436 | throw new python.Error('Not implemented.'); |
| 17437 | } |
| 17438 | case 'prim::awaitable': { |
| 17439 | throw new python.Error('Not implemented.'); |
| 17440 | } |
| 17441 | case 'prim::annotate': { |
| 17442 | this.checkApplyNumInputs(apply, 2); |
| 17443 | const type = this._typeParser.parseTypeFromExpr(apply.args[0]); |
| 17444 | let expr = torch._C.tryConvertToType(apply.range(), this.graph, type, this.emitExpr(apply.args[1], type), /*allow_conversions=*/true); |
| 17445 | if (!expr.type().isSubtypeOf(type)) { |
| 17446 | throw new python.Error('Invalid expression type.'); |
| 17447 | } |
| 17448 | if ((type instanceof torch.OptionalType || (type instanceof torch.UnionType && type.expect(torch.UnionType).canHoldType(torch.NoneType.get()))) && expr.type().isSubtypeOf(torch.NoneType.get())) { |
| 17449 | const none = this.graph.createNone(); |
| 17450 | none.output().setType(type); |
| 17451 | this.graph.insertNode(none); |
| 17452 | expr = none.output(); |
| 17453 | } |
| 17454 | return new torch._C.SimpleValue(expr); |
| 17455 | } |
| 17456 | case 'prim::unchecked_cast': { |
| 17457 | this.checkApplyNumInputs(apply, 2); |
| 17458 | const type = this._typeParser.parseTypeFromExpr(apply.args[0]); |
| 17459 | let v = this.emitExpr(apply.args[1]); |
| 17460 | if (v.node().kind() !== 'prim::unchecked_cast' || v.type() !== type) { |
| 17461 | v = this.graph.insertUncheckedCast(v, type); |
| 17462 | } |
| 17463 | return new torch._C.SimpleValue(v); |
| 17464 | } |
| 17465 | case 'prim::GetAttr': { |
| 17466 | this.checkApplyNumInputsRange(apply, 2, 3); |
| 17467 | const obj = this.emitSugaredExpr(apply.args[0], 1); |
| 17468 | if (apply.args[1] instanceof ast.Constant === false || typeof apply.args[1].value !== 'string') { |
| 17469 | throw new python.Error('Invalid argument.'); |
| 17470 | } |
| 17471 | const name = apply.args[1].value; |
| 17472 | if (apply.args.length === 2) { |
| 17473 | return obj.attr(apply, this.method, name); |
| 17474 | } else if (obj.hasAttr(apply, this.method, name)) { |
| 17475 | return obj.attr(apply, this.method, name); |
| 17476 | } |
| 17477 | return this.emitSugaredExpr(apply.inputs()[2], 1); |
| 17478 | } |
| 17479 | case 'prim::Uninitialized': { |
| 17480 | this.checkApplyNumInputs(apply, 1); |
| 17481 | const type = this._typeParser.parseTypeFromExpr(apply.args[0]); |
| 17482 | const out = this.graph.insertNode(this.graph.createUninitialized(type)).setSourceRange(apply.range()); |
| 17483 | return new torch._C.SimpleValue(out.output()); |
| 17484 | } |
| 17485 | case 'prim::TupleConstruct': { |
| 17486 | throw new python.Error('Not implemented.'); |
| 17487 | } |
| 17488 | case 'prim::isinstance': { |
| 17489 | this.checkApplyNumInputs(apply, 2); |
| 17490 | const result = this.emitIsInstance(apply.args[0], apply.args[1]); |
no test coverage detected