| 43 | } |
| 44 | |
| 45 | Status 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 | |
| 90 | Status ParseShapeAndSlice(const string& shape_and_slice, TensorShape* shape, |
| 91 | TensorSlice* slice, TensorShape* shape_slice) { |