-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: add debug logging and fix coefficient handling #770
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,12 @@ | |
using namespace omnn; | ||
using namespace math; | ||
|
||
std::ostream& operator<<(std::ostream& os, const System& sys) { | ||
for (const auto& eq : sys) { | ||
os << eq << std::endl; | ||
} | ||
return os; | ||
} | ||
|
||
bool is_subset(const auto& smaller_set, const auto& larger_set) { | ||
return std::includes(larger_set.begin(), larger_set.end(), smaller_set.begin(), smaller_set.end()); | ||
|
@@ -265,10 +271,15 @@ | |
|
||
System::solutions_t System::Solve(const Variable& va) | ||
{ | ||
std::cout << "Solving system for variable " << va << std::endl; | ||
std::cout << "System equations: " << *this << std::endl; | ||
Check failure on line 275 in omnn/math/System.cpp
|
||
|
||
auto solutions = Known(va); | ||
InProgress SolvingInProgress(solving, va); | ||
if (SolvingInProgress) | ||
if (SolvingInProgress) { | ||
std::cout << "Already solving " << va << ", returning known solutions: " << solutions.size() << std::endl; | ||
return solutions; | ||
} | ||
|
||
if (makeTotalEqu) { | ||
auto vars = sqs.Vars(); | ||
|
@@ -503,6 +514,11 @@ | |
} | ||
} | ||
|
||
std::cout << "Found " << solutions.size() << " solutions for " << va << std::endl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The debug logging in System.cpp should be conditionally compiled:
|
||
for (const auto& sol : solutions) { | ||
std::cout << "Solution: " << sol << std::endl; | ||
} | ||
|
||
return solutions; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,25 @@ BOOST_AUTO_TEST_CASE(Product_optimize_off_comparision_test) | |
EqualOrderCheck(_1, _2); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(Product_coefficient_handling_test) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Product_coefficient_handling_test should be expanded to cover more cases:
|
||
{ | ||
DECL_VA(x); | ||
|
||
// Test direct multiplication with negative coefficients | ||
auto _1 = -1_v * x; | ||
auto _2 = x * -1_v; | ||
BOOST_TEST(_1 == _2); // Order independence | ||
|
||
// Test coefficient normalization | ||
auto _3 = (-1_v * x) * (-1_v * x); | ||
BOOST_TEST(_3 == (x ^ 2)); // Double negation | ||
|
||
// Test polynomial coefficient handling | ||
auto _4 = -1_v * x + x * x; | ||
auto _5 = (x ^ 2) - x; | ||
BOOST_TEST(_4 == _5); // Equivalent polynomial forms | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(Product_tests) | ||
{ | ||
auto f = 1_v / 2; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The coefficient handling logic in Sum.cpp needs better documentation:
-1*x
pattern should explain why this case needs different handling// Don't set isNormalizedPolynomial to false here
should explain the reasoning