createFloat method
Implementation
Pointer<OrtValue> createFloat(List<int> shape, Float32List data) {
_runtime.ensureInitialized();
final api = _runtime.api.ref;
final memInfo = createCpuMemoryInfo();
final valuePtr = calloc<Pointer<OrtValue>>();
final shapePtr = calloc<Int64>(shape.length);
final dataPtr = calloc<Float>(data.length);
try {
for (var i = 0; i < shape.length; i++) {
shapePtr[i] = shape[i];
}
for (var i = 0; i < data.length; i++) {
dataPtr[i] = data[i];
}
final status = api.CreateTensorWithDataAsOrtValue
.asFunction<
Pointer<OrtStatus> Function(
Pointer<OrtMemoryInfo>,
Pointer<Void>,
int,
Pointer<Int64>,
int,
int,
Pointer<Pointer<OrtValue>>,
)
>()(
memInfo,
dataPtr.cast(),
data.length * sizeOf<Float>(),
shapePtr,
shape.length,
ONNXTensorElementDataType.ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT.value,
valuePtr,
);
_checkStatus(status);
return valuePtr.value;
} finally {
releaseMemoryInfo(memInfo);
calloc.free(valuePtr);
calloc.free(shapePtr);
}
}