pub fn apply(self, target: &mut Model<TI>) -> TractResult<()> {
        let ModelPatch { model: patch, incoming: mut mapping, shunt_outlet_by } = self;
        for node in patch.nodes {
            if node.op_is::<crate::ops::source::Source>() {
                continue;
            }
            let Node { id, name, inputs, op, outputs } = node;
            let n_outputs = outputs.len();
            let facts = outputs.into_iter().map(|of| of.fact).collect();
            let added_node_id = target.add_node_disable_output_guess(name, op, facts, true)?;
            for (ix, input) in inputs.into_iter().enumerate() {
                target.add_edge(mapping[&input], InletId::new(added_node_id, ix))?;
            }
            for ix in 0..n_outputs {
                mapping.insert(OutletId::new(id, ix), OutletId::new(added_node_id, ix));
            }
        }
        for (outlet, by) in shunt_outlet_by {
            let fixed_by = mapping[&by];
            let succs = target.nodes()[outlet.node].outputs[outlet.slot].successors.clone();
            for succ in succs {
                target.add_edge(fixed_by, succ)?;
            }
            for o in target.outputs.iter_mut() {
                if *o == outlet {
                    *o = fixed_by;
                }
            }
        }
        Ok(())
    }
/// Apply all changes in the patch to the target model.
Apply all changes in the patch to the target model.
Apply all changes in the patch to the target model .
pub fn apply(self, target: &mut Model<TI>) -> TractResult<()> {
        let ModelPatch { model: patch, incoming: mut mapping, shunt_outlet_by } = self;
        for node in patch.nodes {
            if node.op_is::<crate::ops::source::Source>() {
                continue;
            }
            let Node { id, name, inputs, op, outputs } = node;
            let n_outputs = outputs.len();
            let facts = outputs.into_iter().map(|of| of.fact).collect();
            let added_node_id = target.add_node_disable_output_guess(name, op, facts, true)?;
            for (ix, input) in inputs.into_iter().enumerate() {
                target.add_edge(mapping[&input], InletId::new(added_node_id, ix))?;
            }
            for ix in 0..n_outputs {
                mapping.insert(OutletId::new(id, ix), OutletId::new(added_node_id, ix));
            }
        }
        for (outlet, by) in shunt_outlet_by {
            let fixed_by = mapping[&by];
            let succs = target.nodes()[outlet.node].outputs[outlet.slot].successors.clone();
            for succ in succs {
                target.add_edge(fixed_by, succ)?;
            }
            for o in target.outputs.iter_mut() {
                if *o == outlet {
                    *o = fixed_by;
                }
            }
        }
        Ok(())
    }
pub fn apply ( self , target : & mut Model < TI > ) -> TractResult < ( ) > { let ModelPatch { model : patch , incoming : mut mapping , shunt_outlet_by } = self ; for node in patch . nodes { if node . op_is :: < crate :: ops :: source :: Source > ( ) { continue ; } let Node { id , name , inputs , op , outputs } = node ; let n_outputs = outputs . len ( ) ; let facts = outputs . into_iter ( ) . map ( | of | of . fact ) . collect ( ) ; let added_node_id = target . add_node_disable_output_guess ( name , op , facts , true ) ? ; for ( ix , input ) in inputs . into_iter ( ) . enumerate ( ) { target . add_edge ( mapping [ & input ] , InletId :: new ( added_node_id , ix ) ) ? ; } for ix in 0 .. n_outputs { mapping . insert ( OutletId :: new ( id , ix ) , OutletId :: new ( added_node_id , ix ) ) ; } } for ( outlet , by ) in shunt_outlet_by { let fixed_by = mapping [ & by ] ; let succs = target . nodes ( ) [ outlet . node ] . outputs [ outlet . slot ] . successors . clone ( ) ; for succ in succs { target . add_edge ( fixed_by , succ ) ? ; } for o in target . outputs . iter_mut ( ) { if * o == outlet { * o = fixed_by ; } } } Ok ( ( ) ) }
Apply all changes in the patch to the target model.
Apply all changes in the patch to the target model .
self
target
&mut Model<TI>
self
target
&mut Model<TI>