| 1018 | } |
| 1019 | |
| 1020 | void FixNoOrphanedArray(Model* model) { |
| 1021 | std::unordered_set<string> arrays_without_known_use; |
| 1022 | for (const auto& array : model->GetArrayMap()) { |
| 1023 | arrays_without_known_use.insert(array.first); |
| 1024 | } |
| 1025 | for (const auto& op : model->operators) { |
| 1026 | for (const auto& input : op->inputs) { |
| 1027 | arrays_without_known_use.erase(input); |
| 1028 | } |
| 1029 | for (const auto& output : op->outputs) { |
| 1030 | arrays_without_known_use.erase(output); |
| 1031 | } |
| 1032 | } |
| 1033 | for (const auto& rnn_state : model->flags.rnn_states()) { |
| 1034 | arrays_without_known_use.erase(rnn_state.state_array()); |
| 1035 | arrays_without_known_use.erase(rnn_state.back_edge_source_array()); |
| 1036 | } |
| 1037 | for (const auto& array : arrays_without_known_use) { |
| 1038 | if (IsDiscardableArray(*model, array)) { |
| 1039 | model->EraseArray(array); |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | // Apply checks to arrays individually (for-each fashion). |
| 1045 | // |
no test coverage detected