createInt32Tensor method
You MUST call calloc.free on the returned pointer when you are done with
it, i.e. once inference is complete.
Implementation
Pointer<Int32> createInt32Tensor(
Pointer<Pointer<OrtValue>> inputTensorPointer, {
required Pointer<OrtMemoryInfo> memoryInfo,
required List<int> values,
}) {
final sizeOfInt32 = sizeOf<Int32>();
final inputTensorNative = calloc<Int32>(values.length * sizeOfInt32);
for (var i = 0; i < values.length; i++) {
inputTensorNative[i] = values[i];
}
final inputShape = calloc<Int64>(1 * sizeOf<Int64>());
inputShape[0] = values.length;
final ptrVoid = inputTensorNative.cast<Void>();
final status = createTensorWithDataAsOrtValue(
inputTensorPointer,
memoryInfo: memoryInfo,
inputData: ptrVoid,
inputDataLengthInBytes: values.length * sizeOfInt32,
inputShape: inputShape,
inputShapeLengthInBytes: 1,
onnxTensorElementDataType:
ONNXTensorElementDataType.ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32.value,
);
if (status.isError) {
final error =
'Code: ${getErrorCodeMessage(status)}\n'
'Message: ${consumeErrorMessage(status)}';
calloc.free(inputTensorNative);
calloc.free(inputShape);
throw Exception(error);
}
calloc.free(inputShape);
return inputTensorNative;
}