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

Method WriteToBuffer

tensorflow/lite/string_util.cc:70–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70int DynamicBuffer::WriteToBuffer(char** buffer) {
71 // Allocate sufficient memory to tensor buffer.
72 int32_t num_strings = offset_.size() - 1;
73 // Total bytes include:
74 // * size of content (data_.size)
75 // * offset of each tensor (sizeof(int32_t) * num_strings)
76 // * length of whole buffer (int32_t)
77 // * num of strings (int32_t).
78 int32_t bytes = data_.size() // size of content
79 + sizeof(int32_t) * (num_strings + 2); // size of header
80
81 // Caller will take ownership of buffer.
82 *buffer = reinterpret_cast<char*>(malloc(bytes));
83
84 // Set num of string
85 memcpy(*buffer, &num_strings, sizeof(int32_t));
86
87 // Set offset of strings.
88 int32_t start = sizeof(int32_t) * (num_strings + 2);
89 for (size_t i = 0; i < offset_.size(); i++) {
90 int32_t offset = start + offset_[i];
91 memcpy(*buffer + sizeof(int32_t) * (i + 1), &offset, sizeof(int32_t));
92 }
93
94 // Copy data of strings.
95 memcpy(*buffer + start, data_.data(), data_.size());
96 return bytes;
97}
98
99void DynamicBuffer::WriteToTensorAsVector(TfLiteTensor* tensor) {
100 auto dims = TfLiteIntArrayCreate(1);

Callers 4

TESTFunction · 0.45
SerializeAsHexStringFunction · 0.45
CopyStringToBufferFunction · 0.45

Calls 2

sizeMethod · 0.45
dataMethod · 0.45

Tested by 1

TESTFunction · 0.36