Matrix<T>.fromRows constructor

Matrix<T>.fromRows(
  1. DataType<T> dataType,
  2. List<List<T>> source, {
  3. MatrixFormat? format,
})

Constructs a matrix from a nested list of rows.

If format is specified, source is copied into a mutable matrix of the selected format; otherwise a view onto the possibly mutable source is provided.

Implementation

factory Matrix.fromRows(DataType<T> dataType, List<List<T>> source,
    {MatrixFormat? format}) {
  final rowCount = source.length;
  final columnCount = source.isEmpty ? 0 : source[0].length;
  if (!source.every((row) => row.length == columnCount)) {
    throw ArgumentError.value(
        source, 'source', 'All rows must be equally sized.');
  }
  final result =
      NestedRowMatrix.fromList(dataType, rowCount, columnCount, source);
  return format == null ? result : result.toMatrix(format: format);
}