pub fn analyse_obstinate(&mut self, obstinate: bool) -> TractResult<bool> {
        let mut nodes_to_visit: BTreeSet<usize> =
            self.model.borrow().eval_order()?.iter().cloned().collect();
        let mut observed_outlets: HashMap<usize, Vec<OutletId>> = HashMap::new();
        let mut observers: HashMap<OutletId, TVec<usize>> = HashMap::new();
        for node in self.model.borrow().nodes() {
            if !nodes_to_visit.contains(&node.id) {
                nodes_to_visit.insert(node.id);
            }
            let observed = node.op.observe_outlets(self.model.borrow(), node)?;
            for outlet in &observed {
                observers.entry(*outlet).or_insert(tvec!()).push(node.id);
            }
            observed_outlets.insert(node.id, observed);
        }
        let mut first_error = None;
        let mut did_something = false;
        loop {
            trace!("Remaining nodes {}", nodes_to_visit.len());
            let node = match nodes_to_visit.iter().next() {
                None => break,
                Some(n) => *n,
            };
            match self.analyse_one(node) {
                Ok(changed_edges) => {
                    for (edge, _fact) in changed_edges {
                        did_something = true;
                        trace!("Changed edge: {:?}", edge);
                        for dst in self.model.borrow().nodes()[edge.node].outputs[edge.slot]
                            .successors
                            .iter()
                        {
                            if dst.node != edge.node {
                                trace!("Inserting node dn {:?}", dst.node);
                                nodes_to_visit.insert(dst.node);
                            }
                        }
                        if edge.node != node {
                            trace!("Inserting node up {}", edge.node);
                            nodes_to_visit.insert(edge.node);
                        }
                        if let Some(observers) = observers.get(&edge) {
                            for observer in observers {
                                nodes_to_visit.insert(*observer);
                            }
                        }
                    }
                }
                Err(e) => {
                    let e = e.context(format!(
                        "Failed analyse for node {}",
                        self.model.borrow().node(node)
                    ));
                    if !obstinate {
                        return Err(e);
                    }
                    debug!("{:?}", e);
                    if first_error.is_none() {
                        first_error = Some(e);
                    }
                }
            }
            nodes_to_visit.remove(&node);
        }
        trace!("analyse done");
        if let Some(e) = first_error {
            Err(e)?
        }
        Ok(did_something)
    }
/// Runs the entire analysis at once. Will not stop on error if obstinate is
/// true.
Runs the entire analysis at once. Will not stop on error if obstinate is
true.
Runs the entire analysis at once . Will not stop on error if obstinate is true .
pub fn analyse_obstinate(&mut self, obstinate: bool) -> TractResult<bool> {
        let mut nodes_to_visit: BTreeSet<usize> =
            self.model.borrow().eval_order()?.iter().cloned().collect();
        let mut observed_outlets: HashMap<usize, Vec<OutletId>> = HashMap::new();
        let mut observers: HashMap<OutletId, TVec<usize>> = HashMap::new();
        for node in self.model.borrow().nodes() {
            if !nodes_to_visit.contains(&node.id) {
                nodes_to_visit.insert(node.id);
            }
            let observed = node.op.observe_outlets(self.model.borrow(), node)?;
            for outlet in &observed {
                observers.entry(*outlet).or_insert(tvec!()).push(node.id);
            }
            observed_outlets.insert(node.id, observed);
        }
        let mut first_error = None;
        let mut did_something = false;
        loop {
            trace!("Remaining nodes {}", nodes_to_visit.len());
            let node = match nodes_to_visit.iter().next() {
                None => break,
                Some(n) => *n,
            };
            match self.analyse_one(node) {
                Ok(changed_edges) => {
                    for (edge, _fact) in changed_edges {
                        did_something = true;
                        trace!("Changed edge: {:?}", edge);
                        for dst in self.model.borrow().nodes()[edge.node].outputs[edge.slot]
                            .successors
                            .iter()
                        {
                            if dst.node != edge.node {
                                trace!("Inserting node dn {:?}", dst.node);
                                nodes_to_visit.insert(dst.node);
                            }
                        }
                        if edge.node != node {
                            trace!("Inserting node up {}", edge.node);
                            nodes_to_visit.insert(edge.node);
                        }
                        if let Some(observers) = observers.get(&edge) {
                            for observer in observers {
                                nodes_to_visit.insert(*observer);
                            }
                        }
                    }
                }
                Err(e) => {
                    let e = e.context(format!(
                        "Failed analyse for node {}",
                        self.model.borrow().node(node)
                    ));
                    if !obstinate {
                        return Err(e);
                    }
                    debug!("{:?}", e);
                    if first_error.is_none() {
                        first_error = Some(e);
                    }
                }
            }
            nodes_to_visit.remove(&node);
        }
        trace!("analyse done");
        if let Some(e) = first_error {
            Err(e)?
        }
        Ok(did_something)
    }
pub fn analyse_obstinate ( & mut self , obstinate : bool ) -> TractResult < bool > { let mut nodes_to_visit : BTreeSet < usize > = self . model . borrow ( ) . eval_order ( ) ? . iter ( ) . cloned ( ) . collect ( ) ; let mut observed_outlets : HashMap < usize , Vec < OutletId > > = HashMap :: new ( ) ; let mut observers : HashMap < OutletId , TVec < usize > > = HashMap :: new ( ) ; for node in self . model . borrow ( ) . nodes ( ) { if ! nodes_to_visit . contains ( & node . id ) { nodes_to_visit . insert ( node . id ) ; } let observed = node . op . observe_outlets ( self . model . borrow ( ) , node ) ? ; for outlet in & observed { observers . entry ( * outlet ) . or_insert ( tvec ! ( ) ) . push ( node . id ) ; } observed_outlets . insert ( node . id , observed ) ; } let mut first_error = None ; let mut did_something = false ; loop { trace ! ( " " nodes_to_visit len ( ) ) ; let node = match nodes_to_visit . iter ( ) . next ( ) { None => break , Some ( n ) => * n , } ; match self . analyse_one ( node ) { Ok ( changed_edges ) => { for ( edge , _fact ) in changed_edges { did_something = true ; trace ! ( " " edge ) ; for dst in self . model . borrow ( ) . nodes ( ) [ edge . node ] . outputs [ edge . slot ] . successors . iter ( ) { if dst . node != edge . node { trace ! ( " " dst node ) ; nodes_to_visit . insert ( dst . node ) ; } } if edge . node != node { trace ! ( " " edge node ) ; nodes_to_visit . insert ( edge . node ) ; } if let Some ( observers ) = observers . get ( & edge ) { for observer in observers { nodes_to_visit . insert ( * observer ) ; } } } } Err ( e ) => { let e = e . context ( format ! ( " " self model borrow ( ) node ( node ) ) ) ; if ! obstinate { return Err ( e ) ; } debug ! ( " " e ) ; if first_error . is_none ( ) { first_error = Some ( e ) ; } } } nodes_to_visit . remove ( & node ) ; } trace ! ( " " ) ; if let Some ( e ) = first_error { Err ( e ) ? } Ok ( did_something ) }
Runs the entire analysis at once.
Runs the entire analysis at once .
&mut self
obstinate
bool
&mut self
obstinate
bool