import { onnx } from 'onnx-proto'; export declare namespace Tensor { interface DataTypeMap { bool: Uint8Array; float32: Float32Array; float64: Float64Array; string: string[]; int8: Int8Array; uint8: Uint8Array; int16: Int16Array; uint16: Uint16Array; int32: Int32Array; uint32: Uint32Array; } type DataType = keyof DataTypeMap; type StringType = Tensor.DataTypeMap['string']; type BooleanType = Tensor.DataTypeMap['bool']; type IntegerType = Tensor.DataTypeMap['int8'] | Tensor.DataTypeMap['uint8'] | Tensor.DataTypeMap['int16'] | Tensor.DataTypeMap['uint16'] | Tensor.DataTypeMap['int32'] | Tensor.DataTypeMap['uint32']; type FloatType = Tensor.DataTypeMap['float32'] | Tensor.DataTypeMap['float64']; type NumberType = BooleanType | IntegerType | FloatType; interface Id { _tensorDataId_unused?: never; } } declare type TensorData = Tensor.DataTypeMap[Tensor.DataType]; declare type DataProvider = (id: Tensor.Id) => TensorData; declare type AsyncDataProvider = (id: Tensor.Id) => Promise; export declare class Tensor { /** * get the dimensions of the tensor */ readonly dims: ReadonlyArray; /** * get the type of the tensor */ readonly type: Tensor.DataType; private dataProvider?; private asyncDataProvider?; private cache?; /** * get the data ID that used to map to a tensor data */ readonly dataId: Tensor.Id; /** * get the underlying tensor data */ get data(): TensorData; /** * get the underlying string tensor data. Should only use when type is STRING */ get stringData(): string[]; /** * get the underlying integer tensor data. Should only use when type is one of the following: (UINT8, INT8, UINT16, * INT16, INT32, UINT32, BOOL) */ get integerData(): Tensor.IntegerType; /** * get the underlying float tensor data. Should only use when type is one of the following: (FLOAT, DOUBLE) */ get floatData(): Tensor.FloatType; /** * get the underlying number tensor data. Should only use when type is one of the following: (UINT8, INT8, UINT16, * INT16, INT32, UINT32, BOOL, FLOAT, DOUBLE) */ get numberData(): Tensor.NumberType; /** * get value of an element at the given indices */ get(indices: ReadonlyArray): Tensor.DataTypeMap[Tensor.DataType][number]; /** * set value of an element at the given indices */ set(indices: ReadonlyArray, value: Tensor.DataTypeMap[Tensor.DataType][number]): void; /** * get the underlying tensor data asynchronously */ getData(): Promise; /** * get the number of elements in the tensor */ readonly size: number; private _strides; /** * get the strides for each dimension */ get strides(): ReadonlyArray; constructor( /** * get the dimensions of the tensor */ dims: ReadonlyArray, /** * get the type of the tensor */ type: Tensor.DataType, dataProvider?: DataProvider | undefined, asyncDataProvider?: AsyncDataProvider | undefined, cache?: string[] | Uint8Array | Float32Array | Int32Array | Float64Array | Int8Array | Int16Array | Uint16Array | Uint32Array | undefined, /** * get the data ID that used to map to a tensor data */ dataId?: Tensor.Id); /** * Construct new Tensor from a ONNX Tensor object * @param tensorProto the ONNX Tensor */ static fromProto(tensorProto: onnx.ITensorProto): Tensor; /** * Construct new Tensor from raw data * @param data the raw data object. Should be a string array for 'string' tensor, and the corresponding typed array * for other types of tensor. * @param dims the dimensions of the tensor * @param type the type of the tensor */ static fromData(data: Tensor.DataTypeMap[Tensor.DataType], dims: ReadonlyArray, type: Tensor.DataType): Tensor; } export {};