Matrix.fromFlattenedList constructor

Matrix.fromFlattenedList(
  1. List<double> source,
  2. int rowCount,
  3. int columnCount, {
  4. DType dtype = DType.float32,
})

Creates a matrix from flattened list of length equal to rowCount * columnCount

A simple usage example:

import 'package:ml_linalg/matrix.dart';

void main() {
  final source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];

  final matrix = Matrix.fromFlattenedList(source, 2, 5);

  print(matrix);
}

The output:

Matrix 2 x 5:
(1.0, 2.0, 3.0, 4.0, 5.0)
(6.0, 7.0, 8.0, 9.0, 0.0)

Implementation

factory Matrix.fromFlattenedList(
  List<double> source,
  int rowCount,
  int columnCount, {
  DType dtype = DType.float32,
}) {
  switch (dtype) {
    case DType.float32:
      return Float32Matrix.fromFlattenedList(source, rowCount, columnCount);

    case DType.float64:
      return Float64Matrix.fromFlattenedList(source, rowCount, columnCount);

    default:
      throw UnimplementedMatrixException(dtype);
  }
}