From 616af37c2f791b2a2a05069cb55f2dcd7c6e1d80 Mon Sep 17 00:00:00 2001 From: cianciosa Date: Tue, 7 Jan 2025 15:36:25 -0500 Subject: [PATCH] Fix an error in power reductions of negative constant coefficents in the numberator of a divide. --- graph_framework/math.hpp | 6 +++--- graph_framework/timing.hpp | 12 ++++++------ graph_tests/math_test.cpp | 8 ++++++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/graph_framework/math.hpp b/graph_framework/math.hpp index 9e2a0a7..b1fe0a3 100644 --- a/graph_framework/math.hpp +++ b/graph_framework/math.hpp @@ -985,9 +985,9 @@ namespace graph { if (ldlm.get()) { if (rc.get() && rc->evaluate().is_even()) { - if (ldlm->get_left()->is_constant() && - ldlm->get_left()->evaluate().is_negative()) { - return pow(ldlm->get_right()/ld->get_right(), + if (ldlm->get_left()->is_constant()) { + return pow(ldlm->get_left(), this->right) * + pow(ldlm->get_right()/ld->get_right(), this->right); } } diff --git a/graph_framework/timing.hpp b/graph_framework/timing.hpp index 277e8d4..565dad4 100644 --- a/graph_framework/timing.hpp +++ b/graph_framework/timing.hpp @@ -44,17 +44,17 @@ namespace timeing { std::cout << std::endl << " " << label << " : "; if (total_time_ns.count() < 1000) { - std::cout << total_time_ns.count() << " ns" << std::endl; + std::cout << total_time_ns.count() << " ns" << std::endl; } else if (total_time_ns.count() < 1000000) { - std::cout << total_time_ns.count()/1000.0 << " μs" << std::endl; + std::cout << total_time_ns.count()/1000.0 << " μs" << std::endl; } else if (total_time_ns.count() < 1000000000) { - std::cout << total_time_ns.count()/1000000.0 << " ms" << std::endl; + std::cout << total_time_ns.count()/1000000.0 << " ms" << std::endl; } else if (total_time_ns.count() < 60000000000) { - std::cout << total_time_ns.count()/1000000000.0 << " s" << std::endl; + std::cout << total_time_ns.count()/1000000000.0 << " s" << std::endl; } else if (total_time_ns.count() < 3600000000000) { - std::cout << total_time_ns.count()/60000000000.0 << " min" << std::endl; + std::cout << total_time_ns.count()/60000000000.0 << " min" << std::endl; } else { - std::cout << total_time_ns.count()/3600000000000 << " h" << std::endl; + std::cout << total_time_ns.count()/3600000000000.0 << " h" << std::endl; } std::cout << std::endl; } diff --git a/graph_tests/math_test.cpp b/graph_tests/math_test.cpp index d905a4d..47849cc 100644 --- a/graph_tests/math_test.cpp +++ b/graph_tests/math_test.cpp @@ -409,6 +409,14 @@ void test_pow() { graph::pow(var_c, var_b) * graph::pow(var_d, var_b)) && "Expected a^(d/2)*b^2*c^d."); + + auto factorconst = graph::pow(-0.5*var_a/var_b, 2.0); + auto factorconst_cast = graph::multiply_cast(factorconst); + assert(factorconst_cast.get() && "Expected a multiply node."); + assert(factorconst_cast->get_left()->is_match(graph::constant (static_cast (0.25))) && + "Expected 0.25 on the left."); + assert(factorconst_cast->get_right()->is_match(graph::pow(var_a/var_b, 2.0)) && + "Expected (a/b)^2 on the right."); } //------------------------------------------------------------------------------ -- GitLab