| 88 | } |
| 89 | |
| 90 | Status 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 |
no test coverage detected