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

Method setSugaredVar

source/python.js:14464–14496  ·  view source on GitHub ↗
(loc, name, value, annotated_type)

Source from the content-addressed store, hash-verified

14462 this.setSugaredVar(loc, name, new torch._C.SimpleValue(value), null);
14463 }
14464 setSugaredVar(loc, name, value, annotated_type) {
14465 let as_simple_value = torch._C.asSimple(value);
14466 if (as_simple_value && !as_simple_value.hasDebugName() && torch._C.meaningfulName(name) && as_simple_value.node().owningBlock() === this.block()) {
14467 as_simple_value.setDebugName(name);
14468 }
14469 const parent = this.findInParentFrame(name);
14470 if (parent) {
14471 if (annotated_type) {
14472 throw new python.Error('Type already defined in an outer block.');
14473 }
14474 if (!as_simple_value) {
14475 throw new python.Error('Only reassignments to first-class values are allowed.');
14476 }
14477 const simple_parent = torch._C.asSimple(parent);
14478 if (!simple_parent) {
14479 throw new python.Error('Only reassignments to first-class values are allowed.');
14480 }
14481 const parent_type = torch._C.unshapedType(simple_parent.type());
14482 as_simple_value = torch._C.tryConvertToType(loc, this.b.owningGraph(), parent_type, as_simple_value, /*allow_conversions=*/true);
14483 if (!as_simple_value.type().isSubtypeOf(parent_type)) {
14484 throw new python.Error('Incompatible types.');
14485 }
14486 }
14487 if (as_simple_value) {
14488 if (annotated_type && !as_simple_value.type().isSubtypeOf(annotated_type)) {
14489 throw new python.Error('Invalid type.');
14490 }
14491 const value_store_type = annotated_type ? annotated_type : as_simple_value.type();
14492 this.insertStore(name, loc, as_simple_value, value_store_type);
14493 } else {
14494 this.value_table.set(name, value);
14495 }
14496 }
14497 getSugaredVar(ident, range, required) {
14498 required = required || true;
14499 let retval = this.findInAnyFrame(ident);

Callers 4

setVarMethod · 0.80
emitFormalArgumentsMethod · 0.80
emitSingleAssignmentMethod · 0.80
emitExprsAssignMethod · 0.80

Calls 12

hasDebugNameMethod · 0.80
owningBlockMethod · 0.80
setDebugNameMethod · 0.80
findInParentFrameMethod · 0.80
unshapedTypeMethod · 0.80
owningGraphMethod · 0.80
isSubtypeOfMethod · 0.80
insertStoreMethod · 0.80
nodeMethod · 0.45
blockMethod · 0.45
typeMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected