diff options
author | JSDurand <mmemmew@gmail.com> | 2023-07-16 18:06:18 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2023-07-16 18:06:18 +0800 |
commit | 780f3cc80cadf87ecfdb702ef90fcb606f2783fd (patch) | |
tree | 7d978d43b1c6f58c358e6f8e8d9f30c0303a7a98 /chain/src/default.rs | |
parent | 6a24e0a805c597b8f835c5c72a0e4dcdd64ca39b (diff) |
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.
Diffstat (limited to 'chain/src/default.rs')
-rw-r--r-- | chain/src/default.rs | 21 |
1 files changed, 7 insertions, 14 deletions
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<bool, Self::Error> { @@ -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); } |