| 315 | } |
| 316 | |
| 317 | TfLiteStatus Rfft2dHelper(TfLiteContext* context, TfLiteNode* node) { |
| 318 | const TfLiteTensor* input = GetInput(context, node, kInputTensor); |
| 319 | const float* input_data = GetTensorData<float>(input); |
| 320 | const TfLiteTensor* fft_length = GetInput(context, node, kFftLengthTensor); |
| 321 | const int32_t* fft_length_data = GetTensorData<int32_t>(fft_length); |
| 322 | TfLiteTensor* output = GetOutput(context, node, kOutputTensor); |
| 323 | complex<float>* output_data = GetTensorData<complex<float>>(output); |
| 324 | |
| 325 | int fft_height, fft_width; |
| 326 | fft_height = fft_length_data[0]; |
| 327 | fft_width = fft_length_data[1]; |
| 328 | |
| 329 | // FFT is processed for every slice on the inner most 2 dimensions. |
| 330 | // Count the number of slices in the input tensor. |
| 331 | const RuntimeShape input_shape = GetTensorShape(input); |
| 332 | const int input_dims_count = input_shape.DimensionsCount(); |
| 333 | const auto* input_dims_data = input_shape.DimsData(); |
| 334 | int num_slices = 1; |
| 335 | for (int i = 0; i < input_dims_count - 2; ++i) { |
| 336 | num_slices *= input_dims_data[i]; |
| 337 | } |
| 338 | |
| 339 | int input_height = input_dims_data[input_dims_count - 2]; |
| 340 | int input_width = input_dims_data[input_dims_count - 1]; |
| 341 | int input_slice_size = input_height * input_width; |
| 342 | int output_slice_size = fft_height * (fft_width / 2 + 1); |
| 343 | |
| 344 | // Create input/output buffer for FFT |
| 345 | double** fft_input_output = new double*[fft_height]; |
| 346 | for (int i = 0; i < fft_height; ++i) { |
| 347 | fft_input_output[i] = new double[fft_width + 2]; |
| 348 | } |
| 349 | |
| 350 | // Get buffer for integer working area. |
| 351 | TfLiteTensor* fft_integer_working_area = |
| 352 | GetTemporary(context, node, kFftIntegerWorkingAreaTensor); |
| 353 | int* fft_integer_working_area_data = |
| 354 | GetTensorData<int>(fft_integer_working_area); |
| 355 | |
| 356 | // Get buffer for double working area. |
| 357 | TfLiteTensor* fft_double_working_area = |
| 358 | GetTemporary(context, node, kFftDoubleWorkingAreaTensor); |
| 359 | // Get double value out of the memory of fft_double_working_area_data. |
| 360 | double* fft_double_working_area_data = reinterpret_cast<double*>( |
| 361 | GetTensorData<int64_t>(fft_double_working_area)); |
| 362 | |
| 363 | // Process evert slice in the input buffer |
| 364 | for (int i = 0; i < num_slices; ++i) { |
| 365 | PrepareInputBuffer(input_data, input_height, input_width, fft_height, |
| 366 | fft_width, fft_input_output); |
| 367 | memset(fft_integer_working_area_data, 0, fft_integer_working_area->bytes); |
| 368 | memset(fft_double_working_area_data, 0, fft_double_working_area->bytes); |
| 369 | Rfft2dImpl(fft_height, fft_width, fft_input_output, |
| 370 | fft_integer_working_area_data, fft_double_working_area_data); |
| 371 | PrepareOutputBuffer(output_data, fft_height, fft_width, fft_input_output); |
| 372 | input_data += input_slice_size; |
| 373 | output_data += output_slice_size; |
| 374 | } |
no test coverage detected