pub fn analyse_one(&mut self, node: usize) -> TractResult<Vec<(OutletId, InferenceFact)>> {
        let mut changed_edges = vec![];
        {
            trace!("Starting step for {}", self.model.borrow().node(node));
            let observed_outlets: Vec<OutletId> = {
                let model = self.model.borrow();
                let node = model.node(node);
                node.op.observe_outlets(&model, &node)?
            };

            let inferred = {
                let (inputs, outputs) = self.model.borrow().node_facts(node)?;
                if outputs.len() != self.model.borrow().node(node).op.nboutputs().unwrap() {
                    bail!(
                        "Wrong nnumber of outputs. Op says {}, node says {}.",
                        self.model.borrow().node(node).op.nboutputs().unwrap(),
                        outputs.len(),
                    )
                }
                let inputs: TVec<InferenceFact> = inputs.into_iter().cloned().collect();
                let outputs: TVec<InferenceFact> = outputs.into_iter().cloned().collect();
                let observed: TVec<(OutletId, InferenceFact)> = {
                    let model = self.model.borrow();
                    let node = model.node(node);
                    node.op
                        .observe_outlets(&model, &node)?
                        .iter()
                        .map(|o| model.outlet_fact(*o).map(|f| (*o, f.clone())))
                        .collect::<TractResult<_>>()?
                };
                if log_enabled!(log::Level::Trace) {
                    for (ix, i) in inputs.iter().enumerate() {
                        trace!("  Input  #{}: {:?}", ix, i);
                    }
                    for (ix, o) in outputs.iter().enumerate() {
                        trace!("  Output #{}: {:?}", ix, o);
                    }
                }

                let inputs: TVec<&InferenceFact> = inputs.iter().collect();
                let outputs: TVec<&InferenceFact> = outputs.iter().collect();
                let observed: TVec<&InferenceFact> = observed.iter().map(|p| &p.1).collect();

                self.model.borrow_mut().node_mut(node).op.infer(inputs, outputs, observed)?
            };

            let node = self.model.borrow().node(node);
            for (ix, &outlet) in node.inputs.iter().enumerate() {
                let inferred_fact = &inferred.0[ix];
                let old_fact = self.model.borrow().outlet_fact(outlet)?;
                let unified = inferred_fact
                    .unify(&old_fact)
                    .with_context(|| format!("while unifying inputs of {}", node))?;

                if &unified != old_fact {
                    debug!("  Refined {:?}: {:?} -> {:?}", outlet, old_fact, unified);
                    changed_edges.push((outlet, unified));
                }
            }

            for (ix, inferred_fact) in inferred.1.iter().enumerate() {
                let old_fact = self.model.borrow().outlet_fact(OutletId::new(node.id, ix))?;
                let unified = old_fact.unify(inferred_fact)?;

                if &unified != old_fact {
                    let outlet = OutletId::new(node.id, ix);
                    debug!("  Refined {:?}: {:?} -> {:?}", outlet, old_fact, unified);
                    changed_edges.push((outlet, unified));
                }
            }

            for (ix, &outlet) in observed_outlets.iter().enumerate() {
                let old_fact = self.model.borrow().outlet_fact(outlet)?;
                let new_fact = &inferred.2[ix];
                let unified = old_fact.unify(new_fact)?;
                if &unified != old_fact {
                    changed_edges.push((outlet, unified));
                }
            }
        }
        for (outlet, fact) in &changed_edges {
            self.model.borrow_mut().set_outlet_fact(*outlet, fact.clone())?;
        }
        Ok(changed_edges)
    }
/// Tries to run a single step of the analysis, and returns whether
/// there was any additional information gained during the step.
Tries to run a single step of the analysis, and returns whether
there was any additional information gained during the step.
Tries to run a single step of the analysis and returns whether there was any additional information gained during the step .
pub fn analyse_one(&mut self, node: usize) -> TractResult<Vec<(OutletId, InferenceFact)>> {
        let mut changed_edges = vec![];
        {
            trace!("Starting step for {}", self.model.borrow().node(node));
            let observed_outlets: Vec<OutletId> = {
                let model = self.model.borrow();
                let node = model.node(node);
                node.op.observe_outlets(&model, &node)?
            };
            let inferred = {
                let (inputs, outputs) = self.model.borrow().node_facts(node)?;
                if outputs.len() != self.model.borrow().node(node).op.nboutputs().unwrap() {
                    bail!(
                        "Wrong nnumber of outputs. Op says {}, node says {}.",
                        self.model.borrow().node(node).op.nboutputs().unwrap(),
                        outputs.len(),
                    )
                }
                let inputs: TVec<InferenceFact> = inputs.into_iter().cloned().collect();
                let outputs: TVec<InferenceFact> = outputs.into_iter().cloned().collect();
                let observed: TVec<(OutletId, InferenceFact)> = {
                    let model = self.model.borrow();
                    let node = model.node(node);
                    node.op
                        .observe_outlets(&model, &node)?
                        .iter()
                        .map(|o| model.outlet_fact(*o).map(|f| (*o, f.clone())))
                        .collect::<TractResult<_>>()?
                };
                if log_enabled!(log::Level::Trace) {
                    for (ix, i) in inputs.iter().enumerate() {
                        trace!("  Input  #{}: {:?}", ix, i);
                    }
                    for (ix, o) in outputs.iter().enumerate() {
                        trace!("  Output #{}: {:?}", ix, o);
                    }
                }
                let inputs: TVec<&InferenceFact> = inputs.iter().collect();
                let outputs: TVec<&InferenceFact> = outputs.iter().collect();
                let observed: TVec<&InferenceFact> = observed.iter().map(|p| &p.1).collect();
                self.model.borrow_mut().node_mut(node).op.infer(inputs, outputs, observed)?
            };
            let node = self.model.borrow().node(node);
            for (ix, &outlet) in node.inputs.iter().enumerate() {
                let inferred_fact = &inferred.0[ix];
                let old_fact = self.model.borrow().outlet_fact(outlet)?;
                let unified = inferred_fact
                    .unify(&old_fact)
                    .with_context(|| format!("while unifying inputs of {}", node))?;
                if &unified != old_fact {
                    debug!("  Refined {:?}: {:?} -> {:?}", outlet, old_fact, unified);
                    changed_edges.push((outlet, unified));
                }
            }
            for (ix, inferred_fact) in inferred.1.iter().enumerate() {
                let old_fact = self.model.borrow().outlet_fact(OutletId::new(node.id, ix))?;
                let unified = old_fact.unify(inferred_fact)?;
                if &unified != old_fact {
                    let outlet = OutletId::new(node.id, ix);
                    debug!("  Refined {:?}: {:?} -> {:?}", outlet, old_fact, unified);
                    changed_edges.push((outlet, unified));
                }
            }
            for (ix, &outlet) in observed_outlets.iter().enumerate() {
                let old_fact = self.model.borrow().outlet_fact(outlet)?;
                let new_fact = &inferred.2[ix];
                let unified = old_fact.unify(new_fact)?;
                if &unified != old_fact {
                    changed_edges.push((outlet, unified));
                }
            }
        }
        for (outlet, fact) in &changed_edges {
            self.model.borrow_mut().set_outlet_fact(*outlet, fact.clone())?;
        }
        Ok(changed_edges)
    }
pub fn analyse_one ( & mut self , node : usize ) -> TractResult < Vec < ( OutletId , InferenceFact ) > > { let mut changed_edges = vec ! [ ] ; { trace ! ( " " self model borrow ( ) node ( node ) ) ; let observed_outlets : Vec < OutletId > = { let model = self . model . borrow ( ) ; let node = model . node ( node ) ; node . op . observe_outlets ( & model , & node ) ? } ; let inferred = { let ( inputs , outputs ) = self . model . borrow ( ) . node_facts ( node ) ? ; if outputs . len ( ) != self . model . borrow ( ) . node ( node ) . op . nboutputs ( ) . unwrap ( ) { bail ! ( " " self model borrow ( ) node ( node ) op nboutputs ( ) unwrap ( ) outputs len ( ) ) } let inputs : TVec < InferenceFact > = inputs . into_iter ( ) . cloned ( ) . collect ( ) ; let outputs : TVec < InferenceFact > = outputs . into_iter ( ) . cloned ( ) . collect ( ) ; let observed : TVec < ( OutletId , InferenceFact ) > = { let model = self . model . borrow ( ) ; let node = model . node ( node ) ; node . op . observe_outlets ( & model , & node ) ? . iter ( ) . map ( | o | model . outlet_fact ( * o ) . map ( | f | ( * o , f . clone ( ) ) ) ) . collect :: < TractResult < _ > > ( ) ? } ; if log_enabled ! ( log Level Trace ) { for ( ix , i ) in inputs . iter ( ) . enumerate ( ) { trace ! ( " " ix i ) ; } for ( ix , o ) in outputs . iter ( ) . enumerate ( ) { trace ! ( " " ix o ) ; } } let inputs : TVec < & InferenceFact > = inputs . iter ( ) . collect ( ) ; let outputs : TVec < & InferenceFact > = outputs . iter ( ) . collect ( ) ; let observed : TVec < & InferenceFact > = observed . iter ( ) . map ( | p | & p . 1 ) . collect ( ) ; self . model . borrow_mut ( ) . node_mut ( node ) . op . infer ( inputs , outputs , observed ) ? } ; let node = self . model . borrow ( ) . node ( node ) ; for ( ix , & outlet ) in node . inputs . iter ( ) . enumerate ( ) { let inferred_fact = & inferred . 0 [ ix ] ; let old_fact = self . model . borrow ( ) . outlet_fact ( outlet ) ? ; let unified = inferred_fact . unify ( & old_fact ) . with_context ( | | format ! ( " " node ) ) ? ; if & unified != old_fact { debug ! ( " " outlet old_fact unified ) ; changed_edges . push ( ( outlet , unified ) ) ; } } for ( ix , inferred_fact ) in inferred . 1 . iter ( ) . enumerate ( ) { let old_fact = self . model . borrow ( ) . outlet_fact ( OutletId :: new ( node . id , ix ) ) ? ; let unified = old_fact . unify ( inferred_fact ) ? ; if & unified != old_fact { let outlet = OutletId :: new ( node . id , ix ) ; debug ! ( " " outlet old_fact unified ) ; changed_edges . push ( ( outlet , unified ) ) ; } } for ( ix , & outlet ) in observed_outlets . iter ( ) . enumerate ( ) { let old_fact = self . model . borrow ( ) . outlet_fact ( outlet ) ? ; let new_fact = & inferred . 2 [ ix ] ; let unified = old_fact . unify ( new_fact ) ? ; if & unified != old_fact { changed_edges . push ( ( outlet , unified ) ) ; } } } for ( outlet , fact ) in & changed_edges { self . model . borrow_mut ( ) . set_outlet_fact ( * outlet , fact . clone ( ) ) ? ; } Ok ( changed_edges ) }
Tries to run a single step of the analysis, and returns whether
there was any additional information gained during the step.
Tries to run a single step of the analysis and returns whether there was any additional information gained during the step .
&mut self
node
usize
&mut self
node
usize