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

Function DecodeTensorNameSlice

tensorflow/core/util/saved_tensor_slice_util.cc:45–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45Status DecodeTensorNameSlice(const string& code, string* name,
46 tensorflow::TensorSlice* slice) {
47 StringPiece src(code);
48 uint64 x;
49 if (!tensorflow::strings::OrderedCode::ReadNumIncreasing(&src, &x)) {
50 return errors::Internal("Failed to parse the leading number: src = ", src);
51 }
52 if (x != 0) {
53 return errors::Internal(
54 "The leading number should always be 0 for any valid key: src = ", src);
55 }
56 if (!tensorflow::strings::OrderedCode::ReadString(&src, name)) {
57 return errors::Internal("Failed to parse the tensor name: src = ", src);
58 }
59 if (!tensorflow::strings::OrderedCode::ReadNumIncreasing(&src, &x)) {
60 return errors::Internal("Failed to parse the tensor rank: src = ", src);
61 }
62 if (x == 0) {
63 return errors::Internal("Expecting positive rank of the tensor, got ", x,
64 ", src = ", src);
65 }
66 if (x >= kint32max) {
67 return errors::Internal("Too many elements ", x);
68 }
69 slice->SetFullSlice(x);
70 for (int d = 0; d < static_cast<int32>(x); ++d) {
71 // We expected 2x integers
72 int64 start, length;
73 if (!tensorflow::strings::OrderedCode::ReadSignedNumIncreasing(&src,
74 &start)) {
75 return errors::Internal("Failed to parse start: src = ", src);
76 }
77 if (!tensorflow::strings::OrderedCode::ReadSignedNumIncreasing(&src,
78 &length)) {
79 return errors::Internal("Failed to parse length: src = ", src);
80 }
81 if (length >= 0) {
82 // a non-trivial extent
83 slice->set_start(d, start);
84 slice->set_length(d, length);
85 }
86 }
87 return Status::OK();
88}
89
90Status ParseShapeAndSlice(const string& shape_and_slice, TensorShape* shape,
91 TensorSlice* slice, TensorShape* shape_slice) {

Callers 1

TESTFunction · 0.85

Calls 5

InternalFunction · 0.85
ReadStringFunction · 0.85
SetFullSliceMethod · 0.80
set_startMethod · 0.80
set_lengthMethod · 0.80

Tested by 1

TESTFunction · 0.68