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

Method emitSimpleExpr

source/python.js:17541–17574  ·  view source on GitHub ↗
(tree, type_hint)

Source from the content-addressed store, hash-verified

17539 }
17540 }
17541 emitSimpleExpr(tree, type_hint) {
17542 if (tree instanceof ast.Constant) {
17543 if (tree.value === true) {
17544 return this.graph.insertConstant(new torch._C.IValue(true, 'Bool'), tree.range());
17545 } else if (tree.value === false) {
17546 return this.graph.insertConstant(new torch._C.IValue(false, 'Bool'), tree.range());
17547 } else if (tree.value === null) {
17548 return this.graph.insertConstant(new torch._C.IValue(), tree.range());
17549 } else if (typeof tree.value === 'string') {
17550 return this.emitStringLiteral(tree);
17551 }
17552 return this.emitConst(tree);
17553 } else if (tree instanceof ast.List) {
17554 return this.emitListLiteral(tree, type_hint);
17555 } else if (tree instanceof ast.UnaryOp && tree.op instanceof ast.USub && tree.operand instanceof ast.Name && tree.operand.id === 'inf') {
17556 return this.emitConst(new ast.Constant(-Infinity, 'float'));
17557 } else if (tree instanceof ast.UnaryOp && tree.op instanceof ast.USub && tree.operand instanceof ast.Constant) {
17558 const c = tree.operand;
17559 if (c.type === 'complex') {
17560 return this.emitConst(new ast.Constant(new builtins.complex(-c.value.real, -c.value.imag), 'complex'));
17561 }
17562 return this.emitConst(new ast.Constant(-c.value, c.type));
17563 } else if (tree instanceof ast.UnaryOp && tree.op instanceof ast.USub) {
17564 return this.emitUnaryOp(tree, '__neg__', 'aten::neg');
17565 } else if (tree instanceof ast.BinOp) {
17566 return this.emitBinaryOp(tree);
17567 } else if (tree instanceof ast.Dict) {
17568 return this.emitDictLiteral(tree, type_hint);
17569 } else if (tree instanceof ast.Tuple) {
17570 const values = this.getValues(tree.elts, /*maybe_unpack=*/true);
17571 return this.graph.insertNode(this.graph.createTuple(values)).output();
17572 }
17573 throw new python.Error(`Simple expression '${tree.__class__.__name__}' not implemented.`);
17574 }
17575 getNodeKind(kind /*, ninputs */) {
17576 if (kind instanceof ast.Add) {
17577 return 'aten::add';

Callers 1

emitSugaredExprMethod · 0.80

Calls 11

insertConstantMethod · 0.80
emitStringLiteralMethod · 0.80
emitConstMethod · 0.80
emitListLiteralMethod · 0.80
emitUnaryOpMethod · 0.80
emitBinaryOpMethod · 0.80
emitDictLiteralMethod · 0.80
getValuesMethod · 0.80
insertNodeMethod · 0.80
createTupleMethod · 0.80
outputMethod · 0.45

Tested by

no test coverage detected