emptyBuffer function
Returns an empty buffer list of the given length according to the dType.
If dType is a numeric one, it will return one of the TypedData Lists,
but if dType is not supported yet - it will throw an ArgumentError.
length must be a positive integer, otherwise throws an ArgumentError.
Implementation
List emptyBuffer(DType dType, int length) {
if (length <= 0) {
throw ArgumentError('Length of a buffer list must be a positive integer, but received $length');
}
if (dType == DType.float32) {
return Float32List(length);
} else if (dType == DType.float64) {
return Float64List(length);
} else if (dType == DType.uint8) {
return Uint8List(length);
} else if (dType == DType.int32) {
return Int32List(length);
} else if (dType == DType.int64) {
return Int64List(length);
} else {
throw ArgumentError('$dType is not supported for empty buffer', 'dType');
}
}