Tensor2D.fromNestedList constructor

Tensor2D.fromNestedList(
  1. List<List<double>> x
)

Implementation

factory Tensor2D.fromNestedList(List<List<double>> x) {
  if (x.isEmpty || x[0].isEmpty) {
    throw ArgumentError('Input list must not be empty');
  }
  final r = x.length;
  final c = x[0].length;
  final out = Float64List(r * c);
  var k = 0;
  for (var i = 0; i < r; i++) {
    if (x[i].length != c) {
      throw ArgumentError('Jagged rows not allowed');
    }
    for (var j = 0; j < c; j++) {
      out[k++] = x[i][j];
    }
  }
  return Tensor2D(r, c, data: out);
}