matrix method

NativeMatrix? matrix(
  1. String name,
  2. int rows,
  3. int cols
)

The cached matrix name, or null if absent or of another shape.

Implementation

NativeMatrix? matrix(String name, int rows, int cols) {
  final o = offsets(name, rows, cols);
  if (o == null) return null;
  return switch (o.format) {
    'q8' => NativeQ8Matrix.fromPointers(
      rows,
      cols,
      (_file.address + o.qs).cast<Int8>(),
      (_file.address + o.scales).cast<Float>(),
    ),
    'q4' => NativeQ4Matrix.fromPointers(
      rows,
      cols,
      _file.address + o.qs,
      (_file.address + o.scales).cast<Uint16>(),
    ),
    _ => throw StateError('unknown format ${o.format} of $name'),
  };
}