Skip to content

Commit 67c708d

Browse files
authored
Merge pull request #10 from ORNL-Fusion/reduction_bugs
Fix reduction of c1 - (c2 + a) -> c3 - a.
2 parents ad80b4a + c528fa1 commit 67c708d

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎graph_framework/arithmetic.hpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ namespace graph {
970970
pl2->get_right(), pl2->get_y_scale(), pl2->get_y_offset());
971971
}
972972
// (c1 + a) - c2 -> c3 + a
973-
// c1 - (c2 + a) -> c3 + a
973+
// c1 - (c2 + a) -> c3 - a
974974
auto la = add_cast(this->left);
975975
if (la.get()) {
976976
if (is_constant_combinable(la->get_left(), this->right)) {
@@ -980,7 +980,7 @@ namespace graph {
980980
auto ra = add_cast(this->right);
981981
if (ra.get()) {
982982
if (is_constant_combinable(this->left, ra->get_left())) {
983-
return (this->left - ra->get_left()) + ra->get_right();
983+
return (this->left - ra->get_left()) - ra->get_right();
984984
}
985985
}
986986

@@ -995,12 +995,12 @@ namespace graph {
995995
return -(ls->get_right() + this->right) - ls->get_left();
996996
}
997997
}
998-
// c1 - (c2 - a) -> c3 - a
998+
// c1 - (c2 - a) -> c3 + a
999999
// c1 - (a - c2) -> c3 - a
10001000
auto rs = subtract_cast(this->right);
10011001
if (rs.get()) {
10021002
if (is_constant_combinable(this->left, rs->get_left())) {
1003-
return (this->left - rs->get_left()) - rs->get_right();
1003+
return (this->left - rs->get_left()) + rs->get_right();
10041004
} else if (is_constant_combinable(this->left, rs->get_right())) {
10051005
return (this->left + rs->get_right()) - rs->get_left();
10061006
}

‎graph_tests/arithmetic_test.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,14 +951,14 @@ template<jit::float_scalar T> void test_subtract() {
951951
assert(constant_combine3_cast->get_right()->is_match(var_a) &&
952952
"Expected a on the right.");
953953
auto constant_combine4 = 2.0 - (1.0 - var_a);
954-
auto constant_combine4_cast = graph::subtract_cast(constant_combine4);
954+
auto constant_combine4_cast = graph::add_cast(constant_combine4);
955955
assert(constant_combine4_cast.get() && "Expected a subtract node.");
956956
assert(constant_combine4_cast->get_left()->evaluate().at(0) == static_cast<T> (1.0) &&
957957
"Expected 1 on the left.");
958958
assert(constant_combine4_cast->get_right()->is_match(var_a) &&
959959
"Expected a on the right.");
960960
auto constant_combine5 = 2.0 - (1.0 + var_a);
961-
auto constant_combine5_cast = graph::add_cast(constant_combine5);
961+
auto constant_combine5_cast = graph::subtract_cast(constant_combine5);
962962
assert(constant_combine5_cast.get() && "Expected an add node.");
963963
assert(constant_combine5_cast->get_left()->evaluate().at(0) == static_cast<T> (1.0) &&
964964
"Expected 1 on the left.");

0 commit comments

Comments
 (0)