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

Method getitem

source/python.js:15761–15781  ·  view source on GitHub ↗
(loc, m, idx, type_hint)

Source from the content-addressed store, hash-verified

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) {

Callers 2

emitLoopCommonMethod · 0.80
emitSubscriptMethod · 0.80

Calls 10

insertMethod · 0.80
isSubtypeOfMethod · 0.80
is_moduleMethod · 0.80
setTypeMethod · 0.80
getValueMethod · 0.45
typeMethod · 0.45
graphMethod · 0.45
getMethod · 0.45
callMethod · 0.45
attrMethod · 0.45

Tested by

no test coverage detected