flattenDynamicTensor function
Flattens an arbitrarily nested tensor to a flat Float32List.
Implementation
Float32List flattenDynamicTensor(Object? out) {
if (out == null) {
throw TypeError();
}
final List<double> flat = <double>[];
void walk(dynamic x) {
if (x is num) {
flat.add(x.toDouble());
} else if (x is List) {
for (final e in x) {
walk(e);
}
} else {
throw StateError('Unexpected output element type: ${x.runtimeType}');
}
}
walk(out);
return Float32List.fromList(flat);
}