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

Function ParseShapeAndSlice

tensorflow/core/util/saved_tensor_slice_util.cc:90–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90Status ParseShapeAndSlice(const string& shape_and_slice, TensorShape* shape,
91 TensorSlice* slice, TensorShape* shape_slice) {
92 CHECK(!shape_and_slice.empty());
93 // Syntax: dim0 dim1 dim2 ... <slice string>
94 // Where slice string is defined in core/framework/tensor_slice.h
95 std::vector<string> splits = str_util::Split(shape_and_slice, ' ');
96
97 // Must have at least 2 strings.
98 if (splits.size() < 2) {
99 return errors::InvalidArgument(
100 "Need least two elements in shape_and_slice specification: ",
101 shape_and_slice);
102 }
103
104 // The last split is the slice specification.
105 slice->Clear();
106 auto status = slice->Parse(splits.back(), slice);
107 if (!status.ok()) return status;
108
109 // The first n-1 are the shape specification.
110 splits.pop_back();
111 shape->Clear();
112 for (const auto& s : splits) {
113 int64 dim;
114 if (!strings::safe_strto64(s, &dim)) {
115 return errors::InvalidArgument(
116 "Non numerical dimension in shape_and_slice: ", shape_and_slice);
117 }
118 shape->AddDim(dim);
119 }
120
121 // The specified slice must be compatible with the specified shape.
122 return slice->SliceTensorShape(*shape, shape_slice);
123}
124
125} // namespace checkpoint
126

Callers 10

ReadTensorFromCheckpointFunction · 0.85
io_ops.ccFile · 0.85
ComputeMethod · 0.85
ComputeMethod · 0.85
ComputeAsyncMethod · 0.85
ComputeAsyncMethod · 0.85
SaveTensorsFunction · 0.85
RestoreTensorFunction · 0.85
runMethod · 0.85
ComputeMethod · 0.85

Calls 12

InvalidArgumentFunction · 0.85
safe_strto64Function · 0.85
pop_backMethod · 0.80
SliceTensorShapeMethod · 0.80
SplitFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
ClearMethod · 0.45
ParseMethod · 0.45
backMethod · 0.45
okMethod · 0.45
AddDimMethod · 0.45

Tested by

no test coverage detected