static fromProto(tensorProto) {
        if (!tensorProto) {
            throw new Error('cannot construct Value from an empty tensor');
        }
        const type = util_1.ProtoUtil.tensorDataTypeFromProto(tensorProto.dataType);
        const dims = util_1.ProtoUtil.tensorDimsFromProto(tensorProto.dims);
        const value = new Tensor(dims, type);
        if (type === 'string') {
            // When it's STRING type, the value should always be stored in field
            // 'stringData'
            tensorProto.stringData.forEach((str, i) => {
                const buf = Buffer.from(str.buffer, str.byteOffset, str.byteLength);
                value.data[i] = buf.toString();
            });
        }
        else if (tensorProto.rawData && typeof tensorProto.rawData.byteLength === 'number' &&
            tensorProto.rawData.byteLength > 0) {
            // NOT considering segment for now (IMPORTANT)
            // populate value from rawData
            const dataDest = value.data;
            const dataSource = new DataView(tensorProto.rawData.buffer, tensorProto.rawData.byteOffset, tensorProto.rawData.byteLength);
            const elementSize = sizeofProto(tensorProto.dataType);
            const length = tensorProto.rawData.byteLength / elementSize;
            if (tensorProto.rawData.byteLength % elementSize !== 0) {
                throw new Error('invalid buffer length');
            }
            if (dataDest.length !== length) {
                throw new Error('buffer length mismatch');
            }
            for (let i = 0; i < length; i++) {
                const n = readProto(dataSource, tensorProto.dataType, i * elementSize);
                dataDest[i] = n;
            }
        }
        else {
            // populate value from array
            let array;
            switch (tensorProto.dataType) {
                case onnx_proto_1.onnx.TensorProto.DataType.FLOAT:
                    array = tensorProto.floatData;
                    break;
                case onnx_proto_1.onnx.TensorProto.DataType.INT32:
                case onnx_proto_1.onnx.TensorProto.DataType.INT16:
                case onnx_proto_1.onnx.TensorProto.DataType.UINT16:
                case onnx_proto_1.onnx.TensorProto.DataType.INT8:
                case onnx_proto_1.onnx.TensorProto.DataType.UINT8:
                case onnx_proto_1.onnx.TensorProto.DataType.BOOL:
                    array = tensorProto.int32Data;
                    break;
                case onnx_proto_1.onnx.TensorProto.DataType.INT64:
                    array = tensorProto.int64Data;
                    break;
                case onnx_proto_1.onnx.TensorProto.DataType.DOUBLE:
                    array = tensorProto.doubleData;
                    break;
                case onnx_proto_1.onnx.TensorProto.DataType.UINT32:
                case onnx_proto_1.onnx.TensorProto.DataType.UINT64:
                    array = tensorProto.uint64Data;
                    break;
                default:
                    // should never run here
                    throw new Error('unspecific error');
            }
            if (array === null || array === undefined) {
                throw new Error('failed to populate data from a tensorproto value');
            }
            const data = value.data;
            if (data.length !== array.length) {
                throw new Error('array length mismatch');
            }
            for (let i = 0; i < array.length; i++) {
                const element = array[i];
                if (long_1.default.isLong(element)) {
                    data[i] = longToNumber(element, tensorProto.dataType);
                }
                else {
                    data[i] = element;
                }
            }
        }
        return value;
    }
/**
     * Construct new Tensor from a ONNX Tensor object
     * @param tensorProto the ONNX Tensor
     */
Construct new Tensor from a ONNX Tensor object
@param tensorProto the ONNX Tensor
Construct new Tensor from a ONNX Tensor object @param tensorProto the ONNX Tensor
static fromProto(tensorProto) {
        if (!tensorProto) {
            throw new Error('cannot construct Value from an empty tensor');
        }
        const type = util_1.ProtoUtil.tensorDataTypeFromProto(tensorProto.dataType);
        const dims = util_1.ProtoUtil.tensorDimsFromProto(tensorProto.dims);
        const value = new Tensor(dims, type);
        if (type === 'string') {
            tensorProto.stringData.forEach((str, i) => {
                const buf = Buffer.from(str.buffer, str.byteOffset, str.byteLength);
                value.data[i] = buf.toString();
            });
        }
        else if (tensorProto.rawData && typeof tensorProto.rawData.byteLength === 'number' &&
            tensorProto.rawData.byteLength > 0) {
            const dataDest = value.data;
            const dataSource = new DataView(tensorProto.rawData.buffer, tensorProto.rawData.byteOffset, tensorProto.rawData.byteLength);
            const elementSize = sizeofProto(tensorProto.dataType);
            const length = tensorProto.rawData.byteLength / elementSize;
            if (tensorProto.rawData.byteLength % elementSize !== 0) {
                throw new Error('invalid buffer length');
            }
            if (dataDest.length !== length) {
                throw new Error('buffer length mismatch');
            }
            for (let i = 0; i < length; i++) {
                const n = readProto(dataSource, tensorProto.dataType, i * elementSize);
                dataDest[i] = n;
            }
        }
        else {
            let array;
            switch (tensorProto.dataType) {
                case onnx_proto_1.onnx.TensorProto.DataType.FLOAT:
                    array = tensorProto.floatData;
                    break;
                case onnx_proto_1.onnx.TensorProto.DataType.INT32:
                case onnx_proto_1.onnx.TensorProto.DataType.INT16:
                case onnx_proto_1.onnx.TensorProto.DataType.UINT16:
                case onnx_proto_1.onnx.TensorProto.DataType.INT8:
                case onnx_proto_1.onnx.TensorProto.DataType.UINT8:
                case onnx_proto_1.onnx.TensorProto.DataType.BOOL:
                    array = tensorProto.int32Data;
                    break;
                case onnx_proto_1.onnx.TensorProto.DataType.INT64:
                    array = tensorProto.int64Data;
                    break;
                case onnx_proto_1.onnx.TensorProto.DataType.DOUBLE:
                    array = tensorProto.doubleData;
                    break;
                case onnx_proto_1.onnx.TensorProto.DataType.UINT32:
                case onnx_proto_1.onnx.TensorProto.DataType.UINT64:
                    array = tensorProto.uint64Data;
                    break;
                default:
                    throw new Error('unspecific error');
            }
            if (array === null || array === undefined) {
                throw new Error('failed to populate data from a tensorproto value');
            }
            const data = value.data;
            if (data.length !== array.length) {
                throw new Error('array length mismatch');
            }
            for (let i = 0; i < array.length; i++) {
                const element = array[i];
                if (long_1.default.isLong(element)) {
                    data[i] = longToNumber(element, tensorProto.dataType);
                }
                else {
                    data[i] = element;
                }
            }
        }
        return value;
    }
static fromProto ( tensorProto ) { if ( ! tensorProto ) { throw new Error ( 'cannot construct Value from an empty tensor' ) ; } const type = util_1 . ProtoUtil . tensorDataTypeFromProto ( tensorProto . dataType ) ; const dims = util_1 . ProtoUtil . tensorDimsFromProto ( tensorProto . dims ) ; const value = new Tensor ( dims , type ) ; if ( type === 'string' ) { tensorProto . stringData . forEach ( ( str , i ) => { const buf = Buffer . from ( str . buffer , str . byteOffset , str . byteLength ) ; value . data [ i ] = buf . toString ( ) ; } ) ; } else if ( tensorProto . rawData && typeof tensorProto . rawData . byteLength === 'number' && tensorProto . rawData . byteLength > 0 ) { const dataDest = value . data ; const dataSource = new DataView ( tensorProto . rawData . buffer , tensorProto . rawData . byteOffset , tensorProto . rawData . byteLength ) ; const elementSize = sizeofProto ( tensorProto . dataType ) ; const length = tensorProto . rawData . byteLength / elementSize ; if ( tensorProto . rawData . byteLength % elementSize !== 0 ) { throw new Error ( 'invalid buffer length' ) ; } if ( dataDest . length !== length ) { throw new Error ( 'buffer length mismatch' ) ; } for ( let i = 0 ; i < length ; i ++ ) { const n = readProto ( dataSource , tensorProto . dataType , i * elementSize ) ; dataDest [ i ] = n ; } } else { let array ; switch ( tensorProto . dataType ) { case onnx_proto_1 . onnx . TensorProto . DataType . FLOAT : array = tensorProto . floatData ; break ; case onnx_proto_1 . onnx . TensorProto . DataType . INT32 : case onnx_proto_1 . onnx . TensorProto . DataType . INT16 : case onnx_proto_1 . onnx . TensorProto . DataType . UINT16 : case onnx_proto_1 . onnx . TensorProto . DataType . INT8 : case onnx_proto_1 . onnx . TensorProto . DataType . UINT8 : case onnx_proto_1 . onnx . TensorProto . DataType . BOOL : array = tensorProto . int32Data ; break ; case onnx_proto_1 . onnx . TensorProto . DataType . INT64 : array = tensorProto . int64Data ; break ; case onnx_proto_1 . onnx . TensorProto . DataType . DOUBLE : array = tensorProto . doubleData ; break ; case onnx_proto_1 . onnx . TensorProto . DataType . UINT32 : case onnx_proto_1 . onnx . TensorProto . DataType . UINT64 : array = tensorProto . uint64Data ; break ; default : throw new Error ( 'unspecific error' ) ; } if ( array === null || array === undefined ) { throw new Error ( 'failed to populate data from a tensorproto value' ) ; } const data = value . data ; if ( data . length !== array . length ) { throw new Error ( 'array length mismatch' ) ; } for ( let i = 0 ; i < array . length ; i ++ ) { const element = array [ i ] ; if ( long_1 . default . isLong ( element ) ) { data [ i ] = longToNumber ( element , tensorProto . dataType ) ; } else { data [ i ] = element ; } } } return value ; }
Construct new Tensor from a ONNX Tensor object
 @param tensorProto the ONNX Tensor
Construct new Tensor from a ONNX Tensor object @param tensorProto the ONNX Tensor
// When it's STRING type, the value should always be stored in field // 'stringData' // NOT considering segment for now (IMPORTANT) // populate value from rawData // populate value from array // should never run here