split function

List<VARP> split(
  1. VARP arr,
  2. List<int> indicesOrSections, {
  3. int axis = 0,
})

Implementation

List<VARP> split(VARP arr, List<int> indicesOrSections, {int axis = 0}) {
  MnnAssert(arr.shape != null, "arr must have a shape");
  final sizeSplits = <int>[indicesOrSections[0]];
  var idxExceeds = false;

  final axisLength = arr.shape![axis];
  for (var i = 1; i < indicesOrSections.length; i++) {
    var nowIdx = indicesOrSections[i];
    if (indicesOrSections[i] > axisLength) {
      idxExceeds = true;
      nowIdx = axisLength;
    }
    sizeSplits.add(nowIdx - indicesOrSections[i - 1]);
  }
  final res = F.split(arr, sizeSplits, axis: axis);
  if (idxExceeds) {
    res.add(array<int32>([0])); // TODO: MNN not support empty Var
  }
  return res;
}