Matrix<T>.fromFlattenedData constructor

Matrix<T>.fromFlattenedData({
  1. required int rows,
  2. required int columns,
  3. required 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.

The source matrix is expressed as an array whose size must exactly be N * M.

Implementation

Matrix.fromFlattenedData({
  required int rows,
  required int columns,
  required List<T> data,
})  : rowCount = rows,
      columnCount = columns {
  // 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.');
  }

  // Making a deep copy of the data
  _data = List<T>.from(data);

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