273{
274 std::vector<uint32_t> by_id;
275
276 for (const auto &comma_token : comma_tokens)
277 {
278 auto dash_tokens = ::split_into_vector(comma_token, '-');
279 if (not ::is_number(dash_tokens))
280 {
281 throw std::runtime_error{
282 "ERROR: To select operator by id, please use these args: [0-9], '-', ','"};
283 }
284
285
286 std::vector<uint32_t> int_tokens;
287 try
288 {
289 std::transform(dash_tokens.begin(), dash_tokens.end(), std::back_inserter(int_tokens),
290 [](const std::string &str) { return static_cast<uint32_t>(std::stoi(str)); });
291 }
292 catch (const std::out_of_range &)
293 {
294
295 throw std::runtime_error{"ERROR: Argument is out of range."};
296 }
297 catch (...)
298 {
299 throw std::runtime_error{"ERROR: Unknown error"};
300 }
301
302 switch (int_tokens.size())
303 {
304 case 0:
305 {
306 throw std::runtime_error{"ERROR: Nothing was entered"};
307 }
308 case 1:
309 {
310 by_id.push_back(int_tokens.at(0));
311 break;
312 }
313 case 2:
314 {
315 for (uint32_t i = int_tokens.at(0); i <= int_tokens.at(1); i++)
316 {
317 by_id.push_back(i);
318 }
319 break;
320 }
321 default:
322 {
323 throw std::runtime_error{"ERROR: Too many '-' in str."};
324 }
325 }
326 }
327
329 std::vector<const luci::CircleNode *> selected_nodes;
330
332 {
333 auto cnode = loco::must_cast<const luci::CircleNode *>(node);
334
335 try
336 {
338 for (auto selected_id : by_id)
339 {
340 if (selected_id == node_id)
341 {
342 selected_nodes.emplace_back(cnode);
343 }
344 }
345 }
346 catch (const std::runtime_error &)
347 {
348 continue;
349 }
350 }
351
352 return selected_nodes;
353}
std::set< Node * > all_nodes(Graph *)
Enumerate all the nodes in a given graph.
CircleNodeID get_node_id(const luci::CircleNode *circle_node)