Matrix<T>.fromData constructor

Matrix<T>.fromData({
  1. required int rows,
  2. required int columns,
  3. required List<List<T>> data,
})

Creates a new N x M matrix where rows is N and columns is M. The matrix is filled with values from data.

Implementation

Matrix.fromData({
  required int rows,
  required int columns,
  required List<List<T>> data,
})  : rowCount = rows,
      columnCount = columns {
  // "Flattening" the source into a single list
  _data = data.expand((e) => e).toList();

  // Exposing data to the outside in read-only mode
  flattenData = UnmodifiableListView<T>(_data);

  // Making sure the size is correct
  if (_data.length != (rows * columns)) {
    throw const MatrixException("The given sizes don't match the size of the "
        'data to be inserted.');
  }
}