Matrix<T>.fromColumns constructor
Matrix<T>.fromColumns (
- DataType<
T> dataType, - List<
List< source, {T> > - MatrixFormat? format,
Constructs a matrix from a nested list of columns.
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.fromColumns(DataType<T> dataType, List<List<T>> source,
{MatrixFormat? format}) {
final rowCount = source.isEmpty ? 0 : source[0].length;
final columnCount = source.length;
if (!source.every((column) => column.length == rowCount)) {
throw ArgumentError.value(
source, 'source', 'All columns must be equally sized.');
}
final result =
NestedColumnMatrix.fromList(dataType, rowCount, columnCount, source);
return format == null ? result : result.toMatrix(format: format);
}