Merge multi condition nets into a single condition nets. Args: name: name of the new condition net. condition_nets: a list of condition nets. The last external_output of each condition net must be single bool value. relation: can be 'And' or
(name, condition_nets, relation)
| 168 | |
| 169 | |
| 170 | def MergeConditionNets(name, condition_nets, relation): |
| 171 | """ |
| 172 | Merge multi condition nets into a single condition nets. |
| 173 | |
| 174 | Args: |
| 175 | name: name of the new condition net. |
| 176 | condition_nets: a list of condition nets. The last external_output |
| 177 | of each condition net must be single bool value. |
| 178 | relation: can be 'And' or 'Or'. |
| 179 | |
| 180 | Returns: |
| 181 | - A new condition net. Its last external output is relation of all |
| 182 | condition_nets. |
| 183 | """ |
| 184 | if not isinstance(condition_nets, list): |
| 185 | return condition_nets |
| 186 | if len(condition_nets) <= 1: |
| 187 | return condition_nets[0] if condition_nets else None |
| 188 | |
| 189 | merged_net = core.Net(name) |
| 190 | for i in range(len(condition_nets)): |
| 191 | net_proto = condition_nets[i].Proto() |
| 192 | assert net_proto.device_option == merged_net.Proto().device_option |
| 193 | assert net_proto.type == merged_net.Proto().type |
| 194 | merged_net.Proto().op.extend(net_proto.op) |
| 195 | merged_net.Proto().external_input.extend(net_proto.external_input) |
| 196 | # discard external outputs as we're combining them together |
| 197 | curr_cond = GetConditionBlobFromNet(condition_nets[i]) |
| 198 | if i == 0: |
| 199 | last_cond = curr_cond |
| 200 | else: |
| 201 | last_cond = merged_net.__getattr__(relation)([last_cond, curr_cond]) |
| 202 | # merge attributes |
| 203 | for k, v in condition_nets[i]._attr_dict.items(): |
| 204 | merged_net._attr_dict[k] += v |
| 205 | |
| 206 | merged_net.AddExternalOutput(last_cond) |
| 207 | |
| 208 | return merged_net |
| 209 | |
| 210 | |
| 211 | def CombineConditions(name, condition_nets, relation): |
nothing calls this directly
no test coverage detected
searching dependent graphs…