createFrom static method
Creates a TensorBuffer deep-copying data from another, with specified TfLiteType
.
Throws ArgumentError.notNull if buffer
is null.
Implementation
static TensorBuffer createFrom(TensorBuffer buffer, TfLiteType dataType) {
SupportPreconditions.checkNotNull(buffer,
message: "Cannot create a buffer from null");
TensorBuffer result;
if (buffer.isDynamic) {
result = createDynamic(dataType);
} else {
result = createFixedSize(buffer.shape, dataType);
}
// The only scenario we need float array is FLOAT32->FLOAT32, or we can always use INT as
// intermediate container.
// The assumption is not true when we support other data types.
if (buffer.getDataType() == TfLiteType.float32 &&
dataType == TfLiteType.float32) {
List<double> data = buffer.getDoubleList();
result.loadList(data, shape: buffer.shape);
} else {
List<int> data = buffer.getIntList();
result.loadList(data, shape: buffer.shape);
}
return result;
}