UNPKG

react-native-executorch

Version:

An easy way to run AI models in react native with ExecuTorch

43 lines (42 loc) 1.34 kB
"use strict"; import { ETError, getError } from '../../Error'; import { ETModuleNativeModule } from '../../native/RnExecutorchModules'; import { getTypeIdentifier } from '../../types/common'; import { BaseModule } from '../BaseModule'; export class ExecutorchModule extends BaseModule { static nativeModule = ETModuleNativeModule; static async load(modelSource) { return await super.load(modelSource); } static async forward(input, shape) { if (!Array.isArray(input)) { input = [input]; } const inputTypeIdentifiers = []; const modelInputs = []; for (const subInput of input) { const typeIdentifier = getTypeIdentifier(subInput); if (typeIdentifier === -1) { throw new Error(getError(ETError.InvalidArgument)); } inputTypeIdentifiers.push(typeIdentifier); modelInputs.push(Array.from(subInput, x => Number(x))); } try { return await this.nativeModule.forward(modelInputs, shape, inputTypeIdentifiers); } catch (e) { throw new Error(getError(e)); } } static async loadMethod(methodName) { try { await this.nativeModule.loadMethod(methodName); } catch (e) { throw new Error(getError(e)); } } static async loadForward() { await this.loadMethod('forward'); } } //# sourceMappingURL=ExecutorchModule.js.map