applied method

FVector applied(
  1. double func(
    1. double
    ), [
  2. Float32x4 funcSIMD(
    1. Float32x4
    )?
])

Applies function func to each element (immutable)

Implementation

FVector applied(double Function(double) func,
    [Float32x4 Function(Float32x4)? funcSIMD]) {
  int start = 0;
  FVector newVec = FVector.zero(nRows);
  if (funcSIMD != null && nRows >= 4) {
    var full4 = nRows ~/ 4;
    for (int i = 0; i < full4; ++i) {
      newVec.columnData[i] = funcSIMD(columnData[i]);
    }
    start = full4 * 4;
  }
  if (start < nRows) {
    Float32List input = columnData.buffer.asFloat32List();
    Float32List result = newVec.columnData.buffer.asFloat32List();
    for (int i = start; i < nRows; ++i) {
      result[i] = func(input[i]);
    }
  }
  return newVec;
}