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.

A MatrixException object is thrown if rows*columns is not equal to data length.

Implementation

Matrix.fromData({
  required int rows,
  required int columns,
  required List<List<T>> data,
})  : rowCount = rows,
      columnCount = columns,
      _data = data.expand((e) => e).toList(growable: false) {
  // 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.",
    );
  }
}