static MTensor maxPool1D()

in FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/ML/FBSDKModelRuntime.hpp [179:200]


  static MTensor maxPool1D(const MTensor &x, const int pool_size)
  {
    int n_examples = x.size(0);
    int input_len = x.size(1);
    int n_channel = x.size(2);
    int output_len = input_len - pool_size + 1;
    MTensor y({n_examples, output_len, n_channel});
    const float *x_data = x.data();
    float *y_data = y.mutable_data();
    for (int n = 0; n < n_examples; n++) {
      for (int c = 0; c < n_channel; c++) {
        for (int i = 0; i < output_len; i++) {
          float this_max = -FLT_MAX;
          for (int r = i; r < i + pool_size; r++) {
            this_max = fmax(this_max, x_data[n * (n_channel * input_len) + r * n_channel + c]);
          }
          y_data[n * (n_channel * output_len) + i * n_channel + c] = this_max;
        }
      }
    }
    return y;
  }