| 45 | } |
| 46 | |
| 47 | static std::string remap_layer(const std::string & orig_name, const std::vector<int> & prune, std::map<int, std::string> & mapped, int & next_id) { |
| 48 | if (prune.empty()) { |
| 49 | return orig_name; |
| 50 | } |
| 51 | |
| 52 | static const std::regex pattern(R"(blk\.(\d+)\.)"); |
| 53 | if (std::smatch match; std::regex_search(orig_name, match, pattern)) { |
| 54 | const int blk = std::stoi(match[1]); |
| 55 | std::string new_name = orig_name; |
| 56 | |
| 57 | if (mapped.count(blk)) { |
| 58 | // Already mapped, do nothing |
| 59 | } else if (std::find(prune.begin(), prune.end(), blk) != prune.end()) { |
| 60 | mapped[blk] = ""; |
| 61 | } else if (blk < prune.front()) { |
| 62 | mapped[blk] = std::to_string(blk); |
| 63 | next_id = blk + 1; |
| 64 | } else { |
| 65 | mapped[blk] = std::to_string(next_id); |
| 66 | ++next_id; |
| 67 | } |
| 68 | |
| 69 | return mapped[blk].empty() ? mapped[blk] : new_name.replace(match.position(1), match.length(1), mapped[blk]); |
| 70 | } |
| 71 | |
| 72 | return orig_name; |
| 73 | } |
| 74 | |
| 75 | static std::string remap_imatrix(const std::string & orig_name, const std::map<int, std::string> & mapped) { |
| 76 | if (mapped.empty()) { |