pub fn condition(&self, values: HashMap<usize, usize>) -> (Self, Vec<usize>) {
        let new_n_nodes = self.n_nodes() - values.len();
        let mut new_to_old = Vec::with_capacity(new_n_nodes);
        let mut old_to_new = HashMap::new();
        // make translations from new to old nodes and vice versa
        for i in 0..self.n_nodes() {
            if !values.contains_key(&i) {
                old_to_new.insert(i, new_to_old.len());
                new_to_old.push(i);
            }
        }
        let mut new_node_potentials = Vec::with_capacity(new_n_nodes);
        let mut new_edge_potentials = HashMap::new();
        for (new_index, old_index) in new_to_old.iter().enumerate() {
            let mut new_potential = self.node_potentials[*old_index].clone();
            // check each old neighbor
            for neighbor in self.neighbors(*old_index) {
                let ep = self.edge_potential(*old_index, *neighbor).unwrap();
                match values.get(neighbor) {
                    Some(&neighbor_val) => {
                        // condition it out
                        new_potential = new_potential.update_potentials(&ep.fixed_v2(neighbor_val));
                    }
                    None => {
                        // translate to new indices
                        new_edge_potentials.insert((new_index, old_to_new[neighbor]), ep.clone());
                    }
                }
            }
            new_node_potentials.push(new_potential)
        }
        (
            DiscreteUndirectedGraph::new(new_node_potentials, new_edge_potentials),
            new_to_old,
        )
    }
// false positive with two different maps
false positive with two different maps
false positive with two different maps
pub fn condition(&self, values: HashMap<usize, usize>) -> (Self, Vec<usize>) {
        let new_n_nodes = self.n_nodes() - values.len();
        let mut new_to_old = Vec::with_capacity(new_n_nodes);
        let mut old_to_new = HashMap::new();
        // make translations from new to old nodes and vice versa
        for i in 0..self.n_nodes() {
            if !values.contains_key(&i) {
                old_to_new.insert(i, new_to_old.len());
                new_to_old.push(i);
            }
        }
        let mut new_node_potentials = Vec::with_capacity(new_n_nodes);
        let mut new_edge_potentials = HashMap::new();
        for (new_index, old_index) in new_to_old.iter().enumerate() {
            let mut new_potential = self.node_potentials[*old_index].clone();
            // check each old neighbor
            for neighbor in self.neighbors(*old_index) {
                let ep = self.edge_potential(*old_index, *neighbor).unwrap();
                match values.get(neighbor) {
                    Some(&neighbor_val) => {
                        // condition it out
                        new_potential = new_potential.update_potentials(&ep.fixed_v2(neighbor_val));
                    }
                    None => {
                        // translate to new indices
                        new_edge_potentials.insert((new_index, old_to_new[neighbor]), ep.clone());
                    }
                }
            }
            new_node_potentials.push(new_potential)
        }
        (
            DiscreteUndirectedGraph::new(new_node_potentials, new_edge_potentials),
            new_to_old,
        )
    }
pub fn condition ( & self , values : HashMap < usize , usize > ) -> ( Self , Vec < usize > ) { let new_n_nodes = self . n_nodes ( ) - values . len ( ) ; let mut new_to_old = Vec :: with_capacity ( new_n_nodes ) ; let mut old_to_new = HashMap :: new ( ) ; // make translations from new to old nodes and vice versa for i in 0 .. self . n_nodes ( ) { if ! values . contains_key ( & i ) { old_to_new . insert ( i , new_to_old . len ( ) ) ; new_to_old . push ( i ) ; } } let mut new_node_potentials = Vec :: with_capacity ( new_n_nodes ) ; let mut new_edge_potentials = HashMap :: new ( ) ; for ( new_index , old_index ) in new_to_old . iter ( ) . enumerate ( ) { let mut new_potential = self . node_potentials [ * old_index ] . clone ( ) ; // check each old neighbor for neighbor in self . neighbors ( * old_index ) { let ep = self . edge_potential ( * old_index , * neighbor ) . unwrap ( ) ; match values . get ( neighbor ) { Some ( & neighbor_val ) => { // condition it out new_potential = new_potential . update_potentials ( & ep . fixed_v2 ( neighbor_val ) ) ; } None => { // translate to new indices new_edge_potentials . insert ( ( new_index , old_to_new [ neighbor ] ) , ep . clone ( ) ) ; } } } new_node_potentials . push ( new_potential ) } ( DiscreteUndirectedGraph :: new ( new_node_potentials , new_edge_potentials ) , new_to_old , ) }
false positive with two different maps
false positive with two different maps
&self
values
HashMap<usize, usize>