From 780f3cc80cadf87ecfdb702ef90fcb606f2783fd Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sun, 16 Jul 2023 18:06:18 +0800 Subject: Fix the bug of forgetting to check cloned nodes. In the process of splitting, cloning, and planting the forest, I forgot to check whether some cloned node of the node inquestion satisfy the condition. This used to cause forests that violate some fundamental assumptions. Now this is supposed to be fixed, but more tests await us. --- chain/src/default.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'chain/src/default.rs') diff --git a/chain/src/default.rs b/chain/src/default.rs index 7de720f..23baa5f 100644 --- a/chain/src/default.rs +++ b/chain/src/default.rs @@ -20,10 +20,7 @@ use std::fmt::Display; use graph_macro::Graph; -use std::{ - borrow::Borrow, - collections::{HashMap as Map, HashSet, TryReserveError}, -}; +use std::collections::{HashMap as Map, HashSet, TryReserveError}; /// The errors related to taking derivatives by chain rule. #[non_exhaustive] @@ -404,7 +401,7 @@ impl Chain for DefaultChain { } fn atom(&self) -> &Self::Atom { - self.atom.borrow() + &self.atom } fn epsilon(&self) -> Result { @@ -805,6 +802,8 @@ impl Chain for DefaultChain { // The 1-th node is a dummy node that should be removed. assert_ne!(root, 1); + // let _ = self.forest.print_viz("help.gv"); + self.forest.remove_node(1)?; let root_degree = self.forest.degree(root)?; @@ -858,10 +857,7 @@ impl Chain for DefaultChain { } for clone in all_completed_clones { - nodes.push( - self.forest - .reduction(clone, pos, ter, self.atom.borrow(), true)?, - ); + nodes.push(self.forest.reduction(clone, pos, ter, &self.atom, true)?); } } else if root_label.clone_index().is_some() { panic!( @@ -887,10 +883,7 @@ impl Chain for DefaultChain { } } - nodes.push( - self.forest - .reduction(root, pos, ter, self.atom.borrow(), true)?, - ); + nodes.push(self.forest.reduction(root, pos, ter, &self.atom, true)?); } dbg!(&nodes); @@ -1080,7 +1073,7 @@ mod test_chain { for (pos, t) in input.iter().copied().enumerate().take(2) { chain.chain(t, pos, no_item)?; - chain.forest().print_viz(&format!("forest {pos}.gv"))?; + // chain.forest().print_viz(&format!("forest {pos}.gv"))?; dbg!(pos, t); } -- cgit v1.2.3-18-g5258