| 15759 | g.insertNode(g.createSetAttr(this._value, field, newValue)); |
| 15760 | } |
| 15761 | getitem(loc, m, idx, type_hint) { |
| 15762 | const val = this.getValue(); |
| 15763 | const val_type = val.type(); |
| 15764 | const g = m.graph(); |
| 15765 | if (val_type instanceof torch.ListType || val_type instanceof torch.StringType) { |
| 15766 | return new torch._C.SimpleValue(g.insert('aten::__getitem__', [new torch._C.NamedValue(val), new torch._C.NamedValue(idx)], [], loc)); |
| 15767 | } else if (val_type instanceof torch.DictType) { |
| 15768 | return new torch._C.SimpleValue(g.insert('aten::__getitem__', [new torch._C.NamedValue(val), new torch._C.NamedValue(idx)], [], loc)); |
| 15769 | } else if (val_type.isSubtypeOf(torch.TensorType.get())) { |
| 15770 | return new torch._C.SimpleValue(g.insert('aten::select', [new torch._C.NamedValue(val), new torch._C.NamedValue(0), new torch._C.NamedValue(idx)], [], loc)); |
| 15771 | } else if (val_type instanceof torch.ClassType) { |
| 15772 | const class_type = val_type; |
| 15773 | if (class_type.is_module() && type_hint) { |
| 15774 | const res = g.insert('prim::ModuleContainerIndex', [new torch._C.NamedValue(val), new torch._C.NamedValue(idx)], [], loc); |
| 15775 | res.setType(type_hint); |
| 15776 | return new torch._C.SimpleValue(res); |
| 15777 | } |
| 15778 | return this.attr(loc, m, '__getitem__').call(loc, m, [new torch._C.NamedValue(idx)], [], 1); |
| 15779 | } |
| 15780 | throw new python.Error('Object is not subscriptable.'); |
| 15781 | } |
| 15782 | }); |
| 15783 | this.registerType('torch._C.MethodValue', class extends torch._C.SugaredValue { |
| 15784 | constructor(self, method_names) { |