zeroOutputBuffers function

void zeroOutputBuffers(
  1. Map<int, Object> outputs,
  2. List<List<int>> shapes
)

Zeros all values in pre-allocated output buffers.

Implementation

void zeroOutputBuffers(Map<int, Object> outputs, List<List<int>> shapes) {
  for (int i = 0; i < shapes.length; i++) {
    final List<int> shape = shapes[i];
    final Object buf = outputs[i]!;
    if (shape.length == 3) {
      final list3d = buf as List<List<List<double>>>;
      for (int j = 0; j < shape[0]; j++) {
        for (int k = 0; k < shape[1]; k++) {
          list3d[j][k].fillRange(0, shape[2], 0.0);
        }
      }
    } else if (shape.length == 2) {
      final list2d = buf as List<List<double>>;
      for (int j = 0; j < shape[0]; j++) {
        list2d[j].fillRange(0, shape[1], 0.0);
      }
    } else {
      final list1d = buf as List<double>;
      list1d.fillRange(0, list1d.length, 0.0);
    }
  }
}