Skip to content

Commit

Permalink
Add common pair removal
Browse files Browse the repository at this point in the history
- Refactoring
  • Loading branch information
benruijl committed Jul 3, 2024
1 parent 43a14a9 commit de11355
Show file tree
Hide file tree
Showing 2 changed files with 871 additions and 393 deletions.
18 changes: 15 additions & 3 deletions examples/nested_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,21 @@ fn main() {

let mut tree = e.as_view().to_eval_tree(|r| r.clone(), &const_map, &params);

tree.horner_scheme(); // optimize the tree using an occurrence-order Horner scheme
// optimize the tree using an occurrence-order Horner scheme
println!("Op original {:?}", tree.count_operations());
tree.horner_scheme();
println!("Op horner {:?}", tree.count_operations());
// the compiler seems to do this as well
tree.common_subexpression_elimination();
println!("op CSSE {:?}", tree.count_operations());

let cpp = tree.export_cpp();
println!("{}", cpp); // print C++ code

let t2 = tree.map_coeff::<f64, _>(&|r| r.into());
tree.common_pair_elimination();
println!("op CPE {:?}", tree.count_operations());

let cpp = t2.export_cpp();
let cpp = tree.export_cpp();
println!("{}", cpp); // print C++ code

std::fs::write("nested_evaluation.cpp", cpp).unwrap();
Expand All @@ -78,6 +88,7 @@ fn main() {
.arg("-shared")
.arg("-fPIC")
.arg("-O3")
.arg("-ffastmath")
.arg("-o")
.arg("libneval.so")
.arg("nested_evaluation.cpp")
Expand All @@ -101,6 +112,7 @@ fn main() {
println!("C++ time {:#?}", t.elapsed());
};

let t2 = tree.map_coeff::<f64, _>(&|r| r.into());
let mut evaluator: ExpressionEvaluator<f64> = t2.linearize(params.len());

println!("Eval: {}", evaluator.evaluate(&[5.]));
Expand Down
Loading

0 comments on commit de11355

Please sign in to comment.