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

Method Parse

tensorflow/core/framework/tensor_slice.cc:78–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78Status TensorSlice::Parse(const string& str, TensorSlice* slice) {
79 std::vector<string> items = str_util::Split(str, ':', str_util::SkipEmpty());
80 slice->starts_.reserve(items.size());
81 slice->lengths_.reserve(items.size());
82 for (const string& x : items) {
83 int64 s, l;
84 if (x == "-") {
85 // "everything"
86 s = 0;
87 l = kFullExtent;
88 } else {
89 std::vector<string> sl = str_util::Split(x, ',', str_util::SkipEmpty());
90 if (sl.size() != 2 || !strings::safe_strto64(sl[0], &s) ||
91 !strings::safe_strto64(sl[1], &l)) {
92 return errors::InvalidArgument(
93 "Expected a pair of numbers or '-' "
94 "but got '",
95 x, "': string = ", str);
96 }
97 if (s < 0 || l <= 0) {
98 return errors::InvalidArgument(
99 "Expected non-negative start and "
100 "positive length but got start = ",
101 s, ", length = ", l, ": string = ", str);
102 }
103 }
104 slice->starts_.push_back(s);
105 slice->lengths_.push_back(l);
106 }
107
108 return Status::OK();
109}
110
111void TensorSlice::Clear() {
112 starts_.clear();

Callers 2

ParseTextProtoFunction · 0.45
OpenArrowFileFunction · 0.45

Calls 7

SkipEmptyClass · 0.85
safe_strto64Function · 0.85
InvalidArgumentFunction · 0.85
SplitFunction · 0.70
reserveMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected