| 48 | } |
| 49 | |
| 50 | TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { |
| 51 | Subgraph* subgraph = reinterpret_cast<Subgraph*>(context->impl_); |
| 52 | |
| 53 | const TfLiteTensor* input_variable_id_tensor = |
| 54 | GetInput(context, node, kInputVariableId); |
| 55 | int variable_id = input_variable_id_tensor->data.i32[0]; |
| 56 | auto& resource_variables = subgraph->resource_variables(); |
| 57 | |
| 58 | const auto& variable_iterator = resource_variables.find(variable_id); |
| 59 | if (variable_iterator == resource_variables.end()) { |
| 60 | context->ReportError(context, "Variable ID %d is read before initialized.", |
| 61 | variable_id); |
| 62 | return kTfLiteError; |
| 63 | } |
| 64 | auto& variable = variable_iterator->second; |
| 65 | |
| 66 | TfLiteTensor* variable_tensor = variable.GetTensor(); |
| 67 | TfLiteTensor* output = GetOutput(context, node, kOutputValue); |
| 68 | |
| 69 | TF_LITE_ENSURE_EQ(context, variable_tensor->type, output->type); |
| 70 | TF_LITE_ENSURE_OK( |
| 71 | context, context->ResizeTensor( |
| 72 | context, output, TfLiteIntArrayCopy(variable_tensor->dims))); |
| 73 | memcpy(output->data.raw, variable_tensor->data.raw, output->bytes); |
| 74 | |
| 75 | return kTfLiteOk; |
| 76 | } |
| 77 | |
| 78 | } // namespace read_variable |
| 79 |
nothing calls this directly
no test coverage detected