Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 6 additions & 50 deletions omnn/math/Sum.cpp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good! The PR simplifies the Sum::operator+= method by removing complex optimization logic in favor of a more streamlined approach, which improves code maintainability.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good! The PR simplifies the Sum::operator+= method by removing complex optimization logic in favor of a more streamlined approach, which improves code maintainability.

Original file line number Diff line number Diff line change
Expand Up @@ -805,68 +805,24 @@ namespace

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good! The PR simplifies the Sum::operator+= method by removing complex optimization logic and replacing it with a more streamlined approach. This is a good improvement in code maintainability.

Valuable& Sum::operator +=(const Valuable& add)
{
if (add.IsZero()) {
}
else if (add.IsSum()) {
operator+=(add.as<Sum>());
}
else if (optimizations)
if (optimizations)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good! The PR simplifies the Sum::operator+= method by removing complex optimization logic in favor of a more streamlined approach, which improves code maintainability. The changes maintain the same functionality while making the code more readable and easier to maintain.

{
std::optional<Valuable> optimizedValue;
if (!add.is_optimized()) {
auto addOptimizedValue = add.is_optimized();
if (!addOptimizedValue) {
optimizedValue = add.Optimized();
}
auto& value = add.is_optimized() ? add : *optimizedValue;
if (value.IsZero()) {
return *this;
}
auto AddTheValue = [&,this]() -> Valuable& {
if (add.is_optimized())
auto& value = addOptimizedValue ? add : *optimizedValue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good! The PR simplifies the Sum::operator+= method by removing complex optimization logic in favor of a more streamlined approach, which improves code maintainability.

if (!value.IsZero()) {
if (addOptimizedValue)
Add(value);
else
Add(std::move(*optimizedValue));
optimize();
return *this;
};

if (value.IsSum()
|| members.empty()
|| !is_optimized()
)
{
return AddTheValue();
}
auto& addendCommonVars = value.getCommonVars();
for (auto it = members.begin(); it != members.end(); ++it)
{
auto simplified = it->IsSummationSimplifiable(value);
if (simplified.first) {
Update(it, std::move(simplified.second));
optimize();
return *this;
}
auto doAdditionalCheck = it->is_optimized()
? (it->OfSameType(value) && it->getCommonVars() == addendCommonVars)
: it->GCD(value) != constants::one;
if (doAdditionalCheck)
{
auto s = *it + value;
if (!s.IsSum()) {
#if !defined(NDEBUG) && !defined(NOOMDEBUG)
std::cout << *it << " + " << add << " = " << s
<< "\t\tIMPLEMENT: must be covered by IsSummationSimpifiable call" << std::endl;
#endif
Update(it, s);
optimize();
return *this;
}
}
}
AddTheValue();
} else {
Add(add);
}

return *this;
}

Expand Down