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

Method attr

source/python.js:15658–15720  ·  view source on GitHub ↗
(loc, m, field)

Source from the content-addressed store, hash-verified

15656 throw new python.Error(`Cannot use '${this._value.type().toString()}' as tuple.`);
15657 }
15658 attr(loc, m, field) {
15659 if (this._value.type().isSubtypeOf(torch.TensorType.get())) {
15660 if (torch._C.builtin_cast_method_to_scalar_type().has(field)) {
15661 return new torch._C.TensorCastValue(torch._C.builtin_cast_method_to_scalar_type().get(field), new torch._C.NamedValue(loc, 'self', this._value));
15662 }
15663 }
15664 if (this._value.type() instanceof torch.TupleType) {
15665 throw new python.Error('Not implemented.');
15666 }
15667 if (this._value.type() instanceof torch.AwaitType) {
15668 throw new python.Error('Not implemented.');
15669 }
15670 if (this._value.type() instanceof torch.ClassType) {
15671 const classType = this._value.type();
15672 if (classType.findMethod(field)) {
15673 return new torch._C.MethodValue(this.getValue(), [field]);
15674 }
15675 if (classType.hasAttribute(field)) {
15676 const g = m.graph();
15677 const n = g.insertNode(g.createGetAttr(this._value, field));
15678 return new torch._C.SimpleValue(n.output());
15679 }
15680 const prop = classType.getProperty(field);
15681 if (prop) {
15682 return new torch._C.MethodValue(this._value, [prop.getter.name()]).call(loc, m, {}, {}, /*n_binders=*/1);
15683 }
15684 } else if (this._value.type() instanceof torch.InterfaceType) {
15685 throw new python.Error('Not implemented.');
15686 } else if (this._value.type() instanceof torch.EnumType) {
15687 const g = m.graph();
15688 if (field === 'name') {
15689 const n = g.insertNode(g.createEnumName(this._value));
15690 return new torch._C.SimpleValue(n.output());
15691 }
15692 if (field === 'value') {
15693 const n = g.insertNode(g.createEnumValue(this._value));
15694 return new torch._C.SimpleValue(n.output());
15695 }
15696 }
15697 if (field === 'type') {
15698 const builtin = torch._C.BuiltinFunction.tryCreate('aten::to', new torch._C.NamedValue(loc, 'self', this._value));
15699 if (builtin) {
15700 return builtin;
15701 }
15702 }
15703 const builtin = torch._C.BuiltinFunction.tryCreate(`aten::${field}`, new torch._C.NamedValue(loc, 'self', this._value));
15704 if (builtin) {
15705 return builtin;
15706 }
15707 if (this._value.type().isSubtypeOf(torch.TensorType.get()) && field === 'tolist') {
15708 return torch._C.SpecialFormValue.create('prim::tolist');
15709 }
15710 if (this._value.type().isSubtypeOf(torch.TensorType.get()) && field === '__getitem__') {
15711 return torch._C.SpecialFormValue.create('aten::index');
15712 }
15713 if (this._value.type() instanceof torch._C._GeneratorType && (field === 'manual_seed' || field === 'initial_seed' || field === 'seed')) {
15714 const builtin = torch._C.BuiltinFunction.tryCreate(`aten::${field}`, new torch._C.NamedValue(loc, 'self', this._value));
15715 if (builtin) {

Callers 4

getitemMethod · 0.45
callMethod · 0.45
emitSugaredExprMethod · 0.45
emitApplySpecialFormMethod · 0.45

Calls 15

isSubtypeOfMethod · 0.80
findMethodMethod · 0.80
insertNodeMethod · 0.80
createGetAttrMethod · 0.80
getPropertyMethod · 0.80
createEnumValueMethod · 0.80
tryCreateMethod · 0.80
findHookMethod · 0.80
enumNamesValuesMethod · 0.80
insertConstantMethod · 0.80
toObjectMethod · 0.80

Tested by

no test coverage detected