Tensor.fromList constructor

Tensor.fromList(
  1. List list
)

Creates a tensor from a nested list of doubles.

Implementation

factory Tensor.fromList(List<dynamic> list) {
  final shape = <int>[];
  dynamic current = list;
  while (current is List) {
    shape.add(current.length);
    if (current.isEmpty) break;
    current = current[0];
  }
  final flat = <double>[];
  _flattenList(list, flat);
  return Tensor(Float32List.fromList(flat), shape);
}