| 48 | } |
| 49 | |
| 50 | Status TensorSlice::BuildTensorSlice(const TensorSliceProto& proto, |
| 51 | TensorSlice* output) { |
| 52 | output->Clear(); |
| 53 | output->starts_.reserve(proto.extent_size()); |
| 54 | output->lengths_.reserve(proto.extent_size()); |
| 55 | for (const auto& e : proto.extent()) { |
| 56 | int64_t l = GetExtentLength(e); |
| 57 | if (e.start() != 0 || l != kFullExtent) { |
| 58 | if (e.start() < 0 || l <= 0) { |
| 59 | return errors::InvalidArgument( |
| 60 | "Expected non-negative start and positive length but got start = ", |
| 61 | e.start(), ", length = ", l, ": extent = ", e.ShortDebugString()); |
| 62 | } |
| 63 | // Calculating the extent end must not cause signed integer overflow. |
| 64 | if (static_cast<uint64_t>(e.start()) + static_cast<uint64_t>(e.length()) > |
| 65 | std::numeric_limits<int64_t>::max()) { |
| 66 | return errors::InvalidArgument( |
| 67 | "Extent end exceeds the maximum possible size: extent = ", |
| 68 | e.ShortDebugString()); |
| 69 | } |
| 70 | } |
| 71 | output->starts_.push_back(e.start()); |
| 72 | output->lengths_.push_back(l); |
| 73 | } |
| 74 | |
| 75 | return Status::OK(); |
| 76 | } |
| 77 | |
| 78 | Status TensorSlice::Parse(const string& str, TensorSlice* slice) { |
| 79 | std::vector<string> items = str_util::Split(str, ':', str_util::SkipEmpty()); |
nothing calls this directly
no test coverage detected