| 341 | } |
| 342 | |
| 343 | void SubgraphBuilder::CreateConstantInt32Tensor(Subgraph* subgraph, |
| 344 | int tensor_index, |
| 345 | const std::vector<int>& shape, |
| 346 | const std::vector<int>& data) { |
| 347 | ASSERT_GT(shape.size(), 0); |
| 348 | int num_elements = 1; |
| 349 | for (int dim : shape) { |
| 350 | num_elements *= dim; |
| 351 | } |
| 352 | ASSERT_EQ(data.size(), num_elements); |
| 353 | size_t size_in_bytes = sizeof(int32_t) * num_elements; |
| 354 | // Maybe aligned. |
| 355 | int32_t* buffer = reinterpret_cast<int32_t*>(malloc(size_in_bytes)); |
| 356 | for (int i = 0; i < num_elements; ++i) { |
| 357 | buffer[i] = data[i]; |
| 358 | } |
| 359 | buffers_.push_back(buffer); |
| 360 | ASSERT_EQ(subgraph->SetTensorParametersReadOnly( |
| 361 | tensor_index, kTfLiteInt32, "", shape, {}, |
| 362 | reinterpret_cast<const char*>(buffer), size_in_bytes), |
| 363 | kTfLiteOk); |
| 364 | } |
| 365 | |
| 366 | void FillIntTensor(TfLiteTensor* tensor, const std::vector<int32_t>& data) { |
| 367 | int count = NumElements(tensor); |
nothing calls this directly
no test coverage detected