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

Method parseSingleConstant

source/python.js:6233–6343  ·  view source on GitHub ↗
(type, kind, real_type)

Source from the content-addressed store, hash-verified

6231 }
6232 }
6233 parseSingleConstant(type, kind, real_type) {
6234 const L = this.L;
6235 if (kind === torch._C.TypeKind.DynamicType) {
6236 return this.parseSingleConstant(type, type.dynamicKind(), real_type);
6237 }
6238 // const auto& str2dtype = c10::getStringToDtypeMap();
6239 if (L.cur().kind === 'id') {
6240 if (L.cur().text() === 'True') {
6241 L.next();
6242 return new torch._C.IValue(true);
6243 }
6244 if (L.cur().text() === 'False') {
6245 L.next();
6246 return new torch._C.IValue(false);
6247 }
6248 if (L.cur().text() === 'None') {
6249 L.next();
6250 return new torch._C.IValue();
6251 }
6252 } else if (L.cur().kind === 'string') {
6253 const token = L.next();
6254 return new torch._C.IValue(torch._C.parseStringLiteral(null, token.text()));
6255 } else if (L.cur().kind === '#') {
6256 let n = '';
6257 if (L.nextIf('-')) {
6258 n = `-${L.expect('#').text()}`; // # .text();
6259 } else {
6260 n = L.expect('#').text(); // # .text();
6261 }
6262 if (kind === torch._C.TypeKind.ComplexType || n.indexOf('j') !== -1) {
6263 throw new Error("Complex type not implemented.");
6264 /*
6265 const imag = std::stod(n.substr(0, n.size() - 1));
6266 return c10::complex<double>(0, imag);
6267 */
6268 } else if (kind === torch._C.TypeKind.FloatType || n.indexOf('.') !== -1 || n.indexOf('e') !== -1) {
6269 const v = parseFloat(n);
6270 return new torch._C.IValue(v, 'Double');
6271 } else {
6272 const v = parseInt(n, 10);
6273 return new torch._C.IValue(v, 'Int');
6274 }
6275 }
6276 throw new python.Error('Not implemented.');
6277 /*
6278 switch (L.cur().kind) {
6279 case TK_TRUE:
6280 L.next();
6281 return true;
6282 case TK_FALSE:
6283 L.next();
6284 return false;
6285 case TK_NONE:
6286 L.next();
6287 return IValue();
6288 case TK_STRINGLITERAL: {
6289 const token = L.next();
6290 return parseStringLiteral(token.range, token.text());

Callers 2

parseDefaultValueMethod · 0.80
parseConstantListMethod · 0.80

Calls 5

curMethod · 0.80
textMethod · 0.80
nextIfMethod · 0.80
nextMethod · 0.45
expectMethod · 0.45

Tested by

no test coverage detected