multiplyBatch method

List<List<double>> multiplyBatch(
  1. List<List<double>> vecs
)

Multiply a batch of vectors: vecs.length = batchSize, each vec length = rows Returns a list of length batchSize, each sublist length = cols.

Implementation

List<List<double>> multiplyBatch(List<List<double>> vecs) {
  if (vecs.any((v) => v.length != rows)) throw ArgumentError('vec length must equal rows');
  final batch = vecs.length;
  final out = List<List<double>>.generate(batch, (_) => List<double>.filled(cols, 0.0));
  final localData = data;
  final r = rows;
  final c = cols;
  for (var b = 0; b < batch; b++) {
    final vec = vecs[b];
    for (var col = 0; col < c; col++) {
      var acc = 0.0;
      for (var row = 0; row < r; row++) {
        acc += vec[row] * localData[row * c + col];
      }
      out[b][col] = acc;
    }
  }
  return out;
}