MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / CreateConstantInt32Tensor

Method CreateConstantInt32Tensor

tensorflow/lite/kernels/subgraph_test_util.cc:343–364  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341}
342
343void 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
366void FillIntTensor(TfLiteTensor* tensor, const std::vector<int32_t>& data) {
367 int count = NumElements(tensor);

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected