MCPcopy Index your code
hub / github.com/lutzroeder/netron / emitReturn

Method emitReturn

source/python.js:17356–17383  ·  view source on GitHub ↗
(stmt)

Source from the content-addressed store, hash-verified

17354 }
17355 }
17356 emitReturn(stmt) {
17357 let declared_return_type = this._def_stack[this._def_stack.length - 1]._declared_return_type;
17358 let actual_return = this.emitExpr(stmt.value, declared_return_type);
17359 if (declared_return_type) {
17360 if (!(actual_return.type().isSubtypeOf(torch.TensorType.get()) && actual_return.type().isSubtypeOf(torch.NoneType.get()))) {
17361 actual_return = torch._C.tryConvertToType(stmt, this.graph, declared_return_type, actual_return, /*allow_conversions=*/true);
17362 }
17363 if (!actual_return.type().isSubtypeOf(declared_return_type)) {
17364 throw new python.Error(`Invalid return type.`);
17365 }
17366 } else {
17367 declared_return_type = this._def_stack[this._def_stack.length - 1]._merged_return_type;
17368 if (!declared_return_type) {
17369 declared_return_type = actual_return.type();
17370 }
17371 const merged_return_type = torch._C.unifyTypes(declared_return_type, actual_return.type());
17372 if (!merged_return_type) {
17373 throw new python.Error(`Invalid return type.`);
17374 }
17375 declared_return_type = merged_return_type;
17376 }
17377 this._def_stack[this._def_stack.length - 1]._merged_return_type = declared_return_type;
17378 if (declared_return_type === torch.AnyType.get() && actual_return.type() !== torch.AnyType.get()) {
17379 actual_return = this.graph.insertUncheckedCast(actual_return, declared_return_type);
17380 }
17381 this.graph.insertNode(this.graph.create('prim::ReturnStmt', [actual_return], 0));
17382 this.exit_blocks.add(this.environment_stack.block());
17383 }
17384 getNamedValues(trees, maybe_unpack) {
17385 const values = [];
17386 for (const tree of trees) {

Callers 1

emitStatementsMethod · 0.80

Calls 9

emitExprMethod · 0.80
isSubtypeOfMethod · 0.80
insertUncheckedCastMethod · 0.80
insertNodeMethod · 0.80
typeMethod · 0.45
getMethod · 0.45
createMethod · 0.45
addMethod · 0.45
blockMethod · 0.45

Tested by

no test coverage detected