void Rfft2dReorder(int fft_height, int fft_width, double** fft_input_output) {
  int fft_height_half;
  ruy::profiler::ScopeLabel label("Rfft2dReorder");
  double real, img;

  fft_height_half = fft_height >> 1;
  // Use 4x4 input as an example, reorder the frequency matrix from
  //    [[(F(0, 0), F(0, -2/4))       F(0, -1/4),   0],
  //     [ F(-1/4, 0),                F(-1/4, -1/4), 0],
  //     [(F(-2/4, 0),F(-2/4, -2/4)), F(-2/4, -1/4), 0],
  //     [ j*F(-3/4, -2/4),           F(-3/4, -1/4), 0]]
  // to
  //    [[F(0, 0),  F(0, -1/4),   F(0, -2/4)],
  //    [F(-1/4, 0), F(-1/4, -1/4), F(-1/4, -2/4)],
  //    [F(-2/4, 0), F(-2/4, -1/4), F(-2/4, -2/4)],
  //    [F(-3/4, 0), F(-3/4, -1/4), F(-3/4, -2/4)]]
  for (int i = fft_height_half + 1; i < fft_height; ++i) {
    real = fft_input_output[i][0];
    img = fft_input_output[i][1];
    fft_input_output[i][fft_width] = img;
    fft_input_output[i][fft_width + 1] = real;
    fft_input_output[fft_height - i][fft_width] = img;
    fft_input_output[fft_height - i][fft_width + 1] = -real;
    fft_input_output[i][0] = fft_input_output[fft_height - i][0];
    fft_input_output[i][1] = -fft_input_output[fft_height - i][1];
  }

  double temp = fft_input_output[0][1];
  fft_input_output[0][fft_width + 1] = 0;
  fft_input_output[0][1] = 0;
  fft_input_output[fft_height_half][fft_width] =
      fft_input_output[fft_height_half][1];
  fft_input_output[fft_height_half][fft_width + 1] = 0;
  fft_input_output[fft_height_half][1] = 0;
  fft_input_output[0][fft_width] = temp;

  // Reorder the frequency matrix from
  //    [[F(0, 0),  F(0, -1/4),   F(0, -2/4)],
  //    [F(-1/4, 0), F(-1/4, -1/4), F(-1/4, -2/4)],
  //    [F(-2/4, 0), F(-2/4, -1/4), F(-2/4, -2/4)],
  //    [F(-3/4, 0), F(-3/4, -1/4), F(-3/4, -2/4)]]
  // to
  //    [[F(0, 0),  F(0, 1/4),   F(0, 2/4)],
  //    [F(1/4, 0), F(1/4, 1/4), F(1/4, 2/4)],
  //    [F(2/4, 0), F(2/4, 1/4), F(2/4, 2/4)],
  //    [F(3/4, 0), F(3/4, 1/4), F(3/4, 2/4)]]
  for (int i = 0; i < fft_height; ++i) {
    for (int j = 1; j < fft_width + 2; j += 2) {
      fft_input_output[i][j] = -fft_input_output[i][j];
    }
  }
}
void Rfft2dReorder(int fft_height, int fft_width, double** fft_input_output) {
  int fft_height_half;
  ruy::profiler::ScopeLabel label("Rfft2dReorder");
  double real, img;

  fft_height_half = fft_height >> 1;
   
   
   
   
   
   
   
   
   
   
  for (int i = fft_height_half + 1; i < fft_height; ++i) {
    real = fft_input_output[i][0];
    img = fft_input_output[i][1];
    fft_input_output[i][fft_width] = img;
    fft_input_output[i][fft_width + 1] = real;
    fft_input_output[fft_height - i][fft_width] = img;
    fft_input_output[fft_height - i][fft_width + 1] = -real;
    fft_input_output[i][0] = fft_input_output[fft_height - i][0];
    fft_input_output[i][1] = -fft_input_output[fft_height - i][1];
  }

  double temp = fft_input_output[0][1];
  fft_input_output[0][fft_width + 1] = 0;
  fft_input_output[0][1] = 0;
  fft_input_output[fft_height_half][fft_width] =
      fft_input_output[fft_height_half][1];
  fft_input_output[fft_height_half][fft_width + 1] = 0;
  fft_input_output[fft_height_half][1] = 0;
  fft_input_output[0][fft_width] = temp;

   
   
   
   
   
   
   
   
   
   
  for (int i = 0; i < fft_height; ++i) {
    for (int j = 1; j < fft_width + 2; j += 2) {
      fft_input_output[i][j] = -fft_input_output[i][j];
    }
  }
}