flatten method

Float32List flatten(
  1. List? array,
  2. int nBlocks,
  3. int blockSize
)

Implementation

Float32List flatten(List? array, int nBlocks, int blockSize) {
  if(array == null || array.isEmpty) return Float32List(0);
  final firstElem = array[0];

  if (firstElem is num || firstElem is double || firstElem is int) {
    List<double> array2 = [];

    for (final element in array) {
      array2.add(element.toDouble());
    }

    return Float32List.fromList(array2);
  }

  final n = nBlocks * blockSize;
  Float32List? r = arrayCacheF32[n];

  if (r == null) {
    r = Float32List(n);
    arrayCacheF32[n] = r;
  }

  if (nBlocks != 0) {
    for (int i = 0; i < nBlocks; i++) {
      List<num> data = array[i].storage.toList();

      data.asMap().forEach((index, element) {
        int idx = i * blockSize + index;
        r![idx] = element.toDouble();
      });
    }
  }
  return r;
}