MCPcopy Create free account
hub / github.com/alibaba/euler / DecodeString

Function DecodeString

euler/core/framework/tensor_util.cc:41–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41Status DecodeString(const TensorProto& proto, Tensor* tensor) {
42 auto pstr = tensor->Raw<std::string*>();
43 auto start = proto.tensor_content().c_str();
44 auto end = start + proto.tensor_content().size();
45 for (int i = 0; i < tensor->NumElements(); ++i) {
46 if (start + sizeof(uint32_t) > end) {
47 return Status::Internal("Invalid tensor proto");
48 }
49 uint32_t len = *reinterpret_cast<const uint32_t*>(start);
50 start += sizeof(uint32_t);
51 (*pstr)->resize(len);
52 if (start + len > end) {
53 return Status::Internal("Invalid tensor proto");
54 }
55 (*pstr)->assign(start, len);
56 pstr++;
57 start += len;
58 }
59 return Status::OK();
60}
61
62} // namespace
63

Callers 1

DecodeFunction · 0.85

Calls 2

sizeMethod · 0.45
NumElementsMethod · 0.45

Tested by

no test coverage detected