| 215 | } |
| 216 | |
| 217 | bool ParseSbpParallelFromString(const std::string& sbp_str, SbpParallel* sbp_parallel) { |
| 218 | bool success = false; |
| 219 | if (sbp_str.length() >= 1) { |
| 220 | if (sbp_str == "B") { |
| 221 | sbp_parallel->mutable_broadcast_parallel(); |
| 222 | success = true; |
| 223 | } else if (sbp_str == "P") { |
| 224 | sbp_parallel->mutable_partial_sum_parallel(); |
| 225 | success = true; |
| 226 | } else if (sbp_str[0] == 'S') { |
| 227 | if (sbp_str.length() >= 4 && sbp_str[1] == '(' && sbp_str[sbp_str.length() - 1] == ')') { |
| 228 | int split_axis = 0; |
| 229 | if (sbp_str.length() == 4) { |
| 230 | split_axis = sbp_str[2] - '0'; |
| 231 | if (split_axis >= 0 && split_axis <= 9) { success = true; } |
| 232 | } else { |
| 233 | std::string split_axis_str = sbp_str.substr(2, sbp_str.length() - 3); |
| 234 | if (std::all_of(split_axis_str.cbegin(), split_axis_str.cend(), |
| 235 | [](char ch) { return std::isdigit(ch); })) { |
| 236 | size_t pos = 0; |
| 237 | split_axis = std::stoi(split_axis_str, &pos); |
| 238 | if (pos == split_axis_str.length()) { success = true; } |
| 239 | } |
| 240 | } |
| 241 | if (success) { sbp_parallel->mutable_split_parallel()->set_axis(split_axis); } |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | return success; |
| 246 | } |
| 247 | |
| 248 | std::string SbpParallelToString(const SbpParallel& sbp_parallel) { |
| 249 | return SbpToString(sbp_parallel); |
no test coverage detected