| 257 | } |
| 258 | |
| 259 | void SubgraphBuilder::BuildPadLoopBodySubgraph(Subgraph* subgraph, |
| 260 | const std::vector<int> padding) { |
| 261 | const int kInputCounter = 0; |
| 262 | const int kInputValue = 1; |
| 263 | const int kOutputCounter = 2; |
| 264 | const int kOutputValue = 3; |
| 265 | const int kConstStep = 4; |
| 266 | const int kConstPadding = 5; |
| 267 | const int kTensorCount = 6; |
| 268 | |
| 269 | // kInputCounter(0) --> +-----+ |
| 270 | // | ADD | --> kOutputCounter(2) |
| 271 | // kConstStep(4) -----> +-----+ |
| 272 | // |
| 273 | // kInputValue(1) ----> +-----+ |
| 274 | // | PAD | --> kOutputValue(3) |
| 275 | // kConstPadding(5) --> +-----+ |
| 276 | |
| 277 | int first_new_tensor_index; |
| 278 | ASSERT_EQ(subgraph->AddTensors(kTensorCount, &first_new_tensor_index), |
| 279 | kTfLiteOk); |
| 280 | ASSERT_EQ(first_new_tensor_index, 0); |
| 281 | ASSERT_EQ(subgraph->SetInputs({kInputCounter, kInputValue}), kTfLiteOk); |
| 282 | ASSERT_EQ(subgraph->SetOutputs({kOutputCounter, kOutputValue}), kTfLiteOk); |
| 283 | |
| 284 | SetupTensor(subgraph, kInputCounter, kTfLiteInt32); |
| 285 | SetupTensor(subgraph, kInputValue, kTfLiteInt32); |
| 286 | SetupTensor(subgraph, kOutputCounter, kTfLiteInt32); |
| 287 | SetupTensor(subgraph, kOutputValue, kTfLiteInt32); |
| 288 | |
| 289 | CreateConstantInt32Tensor(subgraph, kConstStep, {1}, {1}); |
| 290 | ASSERT_EQ(padding.size() % 2, 0); |
| 291 | int padding_dims = padding.size(); |
| 292 | CreateConstantInt32Tensor(subgraph, kConstPadding, {1, padding_dims}, |
| 293 | padding); |
| 294 | |
| 295 | int node_index; |
| 296 | TfLiteAddParams* add_params = |
| 297 | reinterpret_cast<TfLiteAddParams*>(malloc(sizeof(TfLiteAddParams))); |
| 298 | add_params->activation = kTfLiteActNone; |
| 299 | subgraph->AddNodeWithParameters( |
| 300 | {kInputCounter, kConstStep}, {kOutputCounter}, {}, nullptr, 0, add_params, |
| 301 | ::tflite::ops::builtin::Register_ADD(), &node_index); |
| 302 | TfLitePadParams* pad_params = |
| 303 | reinterpret_cast<TfLitePadParams*>(malloc(sizeof(TfLiteAddParams))); |
| 304 | subgraph->AddNodeWithParameters( |
| 305 | {kInputValue, kConstPadding}, {kOutputValue}, {}, nullptr, 0, pad_params, |
| 306 | ::tflite::ops::builtin::Register_PAD(), &node_index); |
| 307 | } |
| 308 | |
| 309 | void SubgraphBuilder::BuildWhileSubgraph(Subgraph* subgraph) { |
| 310 | const int kInput1 = 0; |
no test coverage detected