void Block::cloneFrom(Block * src, std::function<Value*(Value*)> outer_map) { std::unordered_map<Value*, Value*> local_map; auto env = [&](Value * v) { auto it = local_map.find(v); if(it != local_map.end()) return it->second; return outer_map(v); }; auto graph = owningGraph(); for(auto input : src->inputs()) { local_map[input] = this->addInput()->copyMetadata(input)->setStage(input->stage()); graph->setStage(std::max(graph->stage(), input->stage())); } for(auto node : src->nodes()) { auto new_node = this->appendNode(graph->createClone(node, env)); new_node->setStage(node->stage()); graph->setStage(std::max(graph->stage(), node->stage())); for(size_t i = 0; i < node->outputs().size(); ++i) { auto oo = node->outputs()[i]; auto no = new_node->outputs()[i]; local_map[oo] = no; no->copyMetadata(oo); no->setStage(oo->stage()); } } for(auto output : src->outputs()) { this->registerOutput(env(output)); } }
void Genome::copy(Genome *dest) const { copyDimensions(dest); copySequence(dest); copyTopSegments(dest); copyBottomSegments(dest); copyMetadata(dest); }