When sum_product_edges sees a node that appears both in edges and ext, it duplicates the node and puts an identity factor between them. This keeps things simple but is not very efficient. It would be better if sum_product_edges can avoid the duplication by returning some extra info. Hopefully that extra info can also get rid of the handling of disconnected external nodes, which is also not very efficient.
When sum_product_edges sees a node that appears both in edges and ext, it duplicates the node and puts an identity factor between them. This keeps things simple but is not very efficient. It would be better if sum_product_edges can avoid the duplication by returning some extra info. Hopefully that extra info can also get rid of the handling of disconnected external nodes, which is also not very efficient.