UNPKG

onnxruntime-web

Version:

A Javascript library for running ONNX models on browsers

258 lines (257 loc) 8.72 kB
'use strict'; // automatically generated by the FlatBuffers compiler, do not modify var __createBinding = (this && this.__createBinding) || (Object.create ? function (o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function () { return m[k]; }, }; } Object.defineProperty(o, k2, desc); } : function (o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; }); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? function (o, v) { Object.defineProperty(o, 'default', { enumerable: true, value: v }); } : function (o, v) { o['default'] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, '__esModule', { value: true }); exports.Attribute = void 0; /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */ const flatbuffers = __importStar(require('flatbuffers')); const attribute_type_js_1 = require('../../onnxruntime/fbs/attribute-type.js'); const graph_js_1 = require('../../onnxruntime/fbs/graph.js'); const tensor_js_1 = require('../../onnxruntime/fbs/tensor.js'); class Attribute { constructor() { this.bb = null; this.bb_pos = 0; } __init(i, bb) { this.bb_pos = i; this.bb = bb; return this; } static getRootAsAttribute(bb, obj) { return (obj || new Attribute()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } static getSizePrefixedRootAsAttribute(bb, obj) { bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH); return (obj || new Attribute()).__init(bb.readInt32(bb.position()) + bb.position(), bb); } name(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 4); return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; } docString(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 6); return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; } type() { const offset = this.bb.__offset(this.bb_pos, 8); return offset ? this.bb.readInt32(this.bb_pos + offset) : attribute_type_js_1.AttributeType.UNDEFINED; } f() { const offset = this.bb.__offset(this.bb_pos, 10); return offset ? this.bb.readFloat32(this.bb_pos + offset) : 0.0; } i() { const offset = this.bb.__offset(this.bb_pos, 12); return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0'); } s(optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 14); return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; } t(obj) { const offset = this.bb.__offset(this.bb_pos, 16); return offset ? (obj || new tensor_js_1.Tensor()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; } g(obj) { const offset = this.bb.__offset(this.bb_pos, 18); return offset ? (obj || new graph_js_1.Graph()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; } floats(index) { const offset = this.bb.__offset(this.bb_pos, 20); return offset ? this.bb.readFloat32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; } floatsLength() { const offset = this.bb.__offset(this.bb_pos, 20); return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } floatsArray() { const offset = this.bb.__offset(this.bb_pos, 20); return offset ? new Float32Array( this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset), ) : null; } ints(index) { const offset = this.bb.__offset(this.bb_pos, 22); return offset ? this.bb.readInt64(this.bb.__vector(this.bb_pos + offset) + index * 8) : BigInt(0); } intsLength() { const offset = this.bb.__offset(this.bb_pos, 22); return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } strings(index, optionalEncoding) { const offset = this.bb.__offset(this.bb_pos, 24); return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; } stringsLength() { const offset = this.bb.__offset(this.bb_pos, 24); return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } tensors(index, obj) { const offset = this.bb.__offset(this.bb_pos, 26); return offset ? (obj || new tensor_js_1.Tensor()).__init( this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb, ) : null; } tensorsLength() { const offset = this.bb.__offset(this.bb_pos, 26); return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } graphs(index, obj) { const offset = this.bb.__offset(this.bb_pos, 28); return offset ? (obj || new graph_js_1.Graph()).__init( this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb, ) : null; } graphsLength() { const offset = this.bb.__offset(this.bb_pos, 28); return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; } static startAttribute(builder) { builder.startObject(13); } static addName(builder, nameOffset) { builder.addFieldOffset(0, nameOffset, 0); } static addDocString(builder, docStringOffset) { builder.addFieldOffset(1, docStringOffset, 0); } static addType(builder, type) { builder.addFieldInt32(2, type, attribute_type_js_1.AttributeType.UNDEFINED); } static addF(builder, f) { builder.addFieldFloat32(3, f, 0.0); } static addI(builder, i) { builder.addFieldInt64(4, i, BigInt('0')); } static addS(builder, sOffset) { builder.addFieldOffset(5, sOffset, 0); } static addT(builder, tOffset) { builder.addFieldOffset(6, tOffset, 0); } static addG(builder, gOffset) { builder.addFieldOffset(7, gOffset, 0); } static addFloats(builder, floatsOffset) { builder.addFieldOffset(8, floatsOffset, 0); } static createFloatsVector(builder, data) { builder.startVector(4, data.length, 4); for (let i = data.length - 1; i >= 0; i--) { builder.addFloat32(data[i]); } return builder.endVector(); } static startFloatsVector(builder, numElems) { builder.startVector(4, numElems, 4); } static addInts(builder, intsOffset) { builder.addFieldOffset(9, intsOffset, 0); } static createIntsVector(builder, data) { builder.startVector(8, data.length, 8); for (let i = data.length - 1; i >= 0; i--) { builder.addInt64(data[i]); } return builder.endVector(); } static startIntsVector(builder, numElems) { builder.startVector(8, numElems, 8); } static addStrings(builder, stringsOffset) { builder.addFieldOffset(10, stringsOffset, 0); } static createStringsVector(builder, data) { builder.startVector(4, data.length, 4); for (let i = data.length - 1; i >= 0; i--) { builder.addOffset(data[i]); } return builder.endVector(); } static startStringsVector(builder, numElems) { builder.startVector(4, numElems, 4); } static addTensors(builder, tensorsOffset) { builder.addFieldOffset(11, tensorsOffset, 0); } static createTensorsVector(builder, data) { builder.startVector(4, data.length, 4); for (let i = data.length - 1; i >= 0; i--) { builder.addOffset(data[i]); } return builder.endVector(); } static startTensorsVector(builder, numElems) { builder.startVector(4, numElems, 4); } static addGraphs(builder, graphsOffset) { builder.addFieldOffset(12, graphsOffset, 0); } static createGraphsVector(builder, data) { builder.startVector(4, data.length, 4); for (let i = data.length - 1; i >= 0; i--) { builder.addOffset(data[i]); } return builder.endVector(); } static startGraphsVector(builder, numElems) { builder.startVector(4, numElems, 4); } static endAttribute(builder) { const offset = builder.endObject(); return offset; } } exports.Attribute = Attribute; //# sourceMappingURL=attribute.js.map