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

Function ArrayShapeFromString

tensorflow/compiler/xla/tools/driver.cc:145–161  ·  view source on GitHub ↗

Input: TYPE[D1,D2,...DN]

Source from the content-addressed store, hash-verified

143
144// Input: TYPE[D1,D2,...DN]
145ArrayShape ArrayShapeFromString(const std::string& s) {
146 Log("Array shape from string: " + s);
147 Check(s.find('(') == std::string::npos, "Tuple shape is not supported");
148 std::regex shape_r("([^\\[]+)\\[(.*)\\]");
149 std::smatch match;
150 Check(std::regex_match(s, match, shape_r), "Shape not found");
151 std::string type = match[1];
152 std::string dims = match[2];
153 PrimitiveType ptype = PrimitiveTypeFromString(type);
154 std::istringstream dims_stream(dims);
155 std::string dim;
156 std::vector<int> dimensions;
157 while (std::getline(dims_stream, dim, ',')) {
158 dimensions.push_back(std::stoi(dim));
159 }
160 return {ptype, dimensions};
161}
162
163// E.g. (f32[10,20], u32[])
164TupleShape TupleShapeFromString(std::string s) {

Callers 1

TupleShapeFromStringFunction · 0.85

Calls 5

PrimitiveTypeFromStringFunction · 0.85
LogFunction · 0.70
CheckFunction · 0.70
findMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected