Matrix.fromByteData constructor
Matrix.fromByteData(})
Creates a matrix from byte data of rowCount
* columnCount
elements
A simple usage example:
import 'dart:typed_data';
import 'package:ml_linalg/matrix.dart';
void main() {
final data = Float32List.fromList([
1, 2, 3, 4, 5,
6, 7, 8, 9, 0
]).buffer.asByteData();
final matrix = Matrix.fromByteData(data, 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.fromByteData(
ByteData data,
int rowCount,
int columnCount, {
DType dtype = DType.float32,
}) {
switch (dtype) {
case DType.float32:
return Float32Matrix.fromByteData(data, rowCount, columnCount);
case DType.float64:
return Float64Matrix.fromByteData(data, rowCount, columnCount);
default:
throw UnimplementedMatrixException(dtype);
}
}