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

Function Encode

euler/core/framework/tensor_util.cc:64–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62} // namespace
63
64Status Encode(const Tensor& tensor, TensorProto* proto) {
65 if (!tensor.Initialized()) {
66 return Status::FailedPrecondition("Tensor should be properly initialized");
67 }
68
69 proto->set_dtype(static_cast<DataTypeProto>(tensor.Type()));
70 for (auto& dim : tensor.Shape().Dims()) {
71 proto->mutable_tensor_shape()->mutable_dims()->Add(dim);
72 }
73
74 if (tensor.Type() == DataType::kString) {
75 return EncodeString(tensor, proto);
76 }
77
78 auto ptr = tensor.Raw<char>();
79 auto bytes = tensor.TotalBytes();
80 auto content = proto->mutable_tensor_content();
81 content->assign(ptr, bytes);
82 return Status::OK();
83}
84
85Status Decode(const TensorProto& proto, Tensor* tensor) {
86 if (!tensor->Initialized()) {

Callers 2

TESTFunction · 0.85
ExecuteAsyncMethod · 0.85

Calls 5

EncodeStringFunction · 0.85
InitializedMethod · 0.80
TypeMethod · 0.80
TotalBytesMethod · 0.80
AddMethod · 0.45

Tested by 1

TESTFunction · 0.68