loadList method
Loads an List
If shape
is null then TensorBuffer.shape
is used.
Implementation
@override
void loadList(List src, {required List<int> shape}) {
SupportPreconditions.checkNotNull(src,
message: "The array to be loaded cannot be null.");
SupportPreconditions.checkArgument(
src.length == TensorBuffer.computeFlatSize(shape),
errorMessage:
"The size of the array to be loaded does not match the specified shape.");
resize(shape);
if (src is List<double>) {
for (int i = 0; i < src.length; i++) {
byteData.setUint8(i, (max(min(src[i], 255.0), 0.0).floor() & 0xFF));
}
} else if (src is List<int>) {
for (int i = 0; i < src.length; i++) {
byteData.setUint8(i, max(min(src[i], 255), 0));
}
} else {
throw ArgumentError(
'Only List<double> and List<int> are supported but src is: ${src.runtimeType}');
}
}