From dc21b9ff637aa6354fd958ce5fe72f6253b55c08 Mon Sep 17 00:00:00 2001 From: "petro.zarytskyi" Date: Tue, 23 Apr 2024 13:14:14 +0300 Subject: [PATCH] WIP --- lib/Differentiator/BaseForwardModeVisitor.cpp | 10 +- test/FirstDerivative/BasicArithmeticAddSub.C | 122 ++++++------ test/FirstDerivative/BasicArithmeticAll.C | 34 ++-- test/FirstDerivative/BasicArithmeticMulDiv.C | 173 +++++++++--------- test/FirstDerivative/Loops.C | 36 +--- 5 files changed, 174 insertions(+), 201 deletions(-) diff --git a/lib/Differentiator/BaseForwardModeVisitor.cpp b/lib/Differentiator/BaseForwardModeVisitor.cpp index 6f2dd6962..11552a630 100644 --- a/lib/Differentiator/BaseForwardModeVisitor.cpp +++ b/lib/Differentiator/BaseForwardModeVisitor.cpp @@ -1372,10 +1372,13 @@ BaseForwardModeVisitor::DifferentiateVarDecl(const VarDecl* VD) { BuildVarDecl(VD->getType(), VD->getNameAsString(), initDiff.getExpr(), VD->isDirectInit(), nullptr, VD->getInitStyle()); // FIXME: Create unique identifier for derivative. - VarDecl* VDDerived = BuildVarDecl( + VarDecl* VDDerived = nullptr; + if (IsDifferentiableType(VD->getType())) { + VDDerived = BuildVarDecl( VD->getType(), "_d_" + VD->getNameAsString(), initDiff.getExpr_dx(), VD->isDirectInit(), nullptr, VD->getInitStyle()); - m_Variables.emplace(VDClone, BuildDeclRef(VDDerived)); + m_Variables.emplace(VDClone, BuildDeclRef(VDDerived)); + } return DeclDiff(VDClone, VDDerived); } @@ -1437,7 +1440,8 @@ StmtDiff BaseForwardModeVisitor::VisitDeclStmt(const DeclStmt* DS) { if (VDDiff.getDecl()->getDeclName() != VD->getDeclName()) m_DeclReplacements[VD] = VDDiff.getDecl(); decls.push_back(VDDiff.getDecl()); - declsDiff.push_back(VDDiff.getDecl_dx()); + if (VDDiff.getDecl_dx()) + declsDiff.push_back(VDDiff.getDecl_dx()); } else if (auto* SAD = dyn_cast(D)) { DeclDiff SADDiff = DifferentiateStaticAssertDecl(SAD); if (SADDiff.getDecl()) diff --git a/test/FirstDerivative/BasicArithmeticAddSub.C b/test/FirstDerivative/BasicArithmeticAddSub.C index a69483586..aa5dda314 100644 --- a/test/FirstDerivative/BasicArithmeticAddSub.C +++ b/test/FirstDerivative/BasicArithmeticAddSub.C @@ -7,90 +7,90 @@ extern "C" int printf(const char* fmt, ...); -int a_1(int x) { - int y = 4; +float a_1(float x) { + float y = 4; return y + y; // == 0 } -// CHECK: int a_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float a_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return _d_y + _d_y; // CHECK-NEXT: } -int a_2(int x) { +float a_2(float x) { return 1 + 1; // == 0 } -// CHECK: int a_2_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float a_2_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return 0 + 0; // CHECK-NEXT: } -int a_3(int x) { +float a_3(float x) { return x + x; // == 2 } -// CHECK: int a_3_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float a_3_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return _d_x + _d_x; // CHECK-NEXT: } -int a_4(int x) { - int y = 4; +float a_4(float x) { + float y = 4; return x + y + x + 3 + x; // == 3x } -// CHECK: int a_4_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float a_4_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return _d_x + _d_y + _d_x + 0 + _d_x; // CHECK-NEXT: } -int s_1(int x) { - int y = 4; +float s_1(float x) { + float y = 4; return y - y; // == 0 } -// CHECK: int s_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float s_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return _d_y - _d_y; // CHECK-NEXT: } -int s_2(int x) { +float s_2(float x) { return 1 - 1; // == 0 } -// CHECK: int s_2_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float s_2_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return 0 - 0; // CHECK-NEXT: } -int s_3(int x) { +float s_3(float x) { return x - x; // == 0 } -// CHECK: int s_3_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float s_3_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return _d_x - _d_x; // CHECK-NEXT: } -int s_4(int x) { - int y = 4; +float s_4(float x) { + float y = 4; return x - y - x - 3 - x; // == -1 } -// CHECK: int s_4_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float s_4_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return _d_x - _d_y - _d_x - 0 - _d_x; // CHECK-NEXT: } -int as_1(int x) { - int y = 4; +float as_1(float x) { + float y = 4; return x + x - x + y - y + 3 - 3; // == 1 } -// CHECK: int as_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float as_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return _d_x + _d_x - _d_x + _d_y - _d_y + 0 - 0; // CHECK-NEXT: } @@ -103,45 +103,45 @@ float IntegerLiteralToFloatLiteral(float x, float y) { // CHECK-NEXT: return _d_x * x + x * _d_x - _d_y; // CHECK-NEXT: } -int a_1_darg0(int x); -int a_2_darg0(int x); -int a_3_darg0(int x); -int a_4_darg0(int x); -int s_1_darg0(int x); -int s_2_darg0(int x); -int s_3_darg0(int x); -int s_4_darg0(int x); -int as_1_darg0(int x); +float a_1_darg0(float x); +float a_2_darg0(float x); +float a_3_darg0(float x); +float a_4_darg0(float x); +float s_1_darg0(float x); +float s_2_darg0(float x); +float s_3_darg0(float x); +float s_4_darg0(float x); +float as_1_darg0(float x); float IntegerLiteralToFloatLiteral_darg0(float x, float y); int main () { // expected-no-diagnostics - int x = 4; + float x = 4; clad::differentiate(a_1, 0); - printf("Result is = %d\n", a_1_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %f\n", a_1_darg0(1)); // CHECK-EXEC: Result is = 0 clad::differentiate(a_2, 0); - printf("Result is = %d\n", a_2_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %f\n", a_2_darg0(1)); // CHECK-EXEC: Result is = 0 clad::differentiate(a_3, 0); - printf("Result is = %d\n", a_3_darg0(1)); // CHECK-EXEC: Result is = 2 + printf("Result is = %f\n", a_3_darg0(1)); // CHECK-EXEC: Result is = 2 clad::differentiate(a_4, 0); - printf("Result is = %d\n", a_4_darg0(1)); // CHECK-EXEC: Result is = 3 + printf("Result is = %f\n", a_4_darg0(1)); // CHECK-EXEC: Result is = 3 clad::differentiate(s_1, 0); - printf("Result is = %d\n", s_1_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %f\n", s_1_darg0(1)); // CHECK-EXEC: Result is = 0 clad::differentiate(s_2, 0); - printf("Result is = %d\n", s_2_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %f\n", s_2_darg0(1)); // CHECK-EXEC: Result is = 0 clad::differentiate(s_3, 0); - printf("Result is = %d\n", s_3_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %f\n", s_3_darg0(1)); // CHECK-EXEC: Result is = 0 clad::differentiate(s_4, 0); - printf("Result is = %d\n", s_4_darg0(1)); // CHECK-EXEC: Result is = -1 + printf("Result is = %f\n", s_4_darg0(1)); // CHECK-EXEC: Result is = -1 clad::differentiate(as_1, 0); - printf("Result is = %d\n", as_1_darg0(1)); // CHECK-EXEC: Result is = 1 + printf("Result is = %f\n", as_1_darg0(1)); // CHECK-EXEC: Result is = 1 clad::differentiate(IntegerLiteralToFloatLiteral, 0); printf("Result is = %f\n", IntegerLiteralToFloatLiteral_darg0(5., 0.)); // CHECK-EXEC: Result is = 10 diff --git a/test/FirstDerivative/BasicArithmeticAll.C b/test/FirstDerivative/BasicArithmeticAll.C index 0ac24212d..18c8b4bb3 100644 --- a/test/FirstDerivative/BasicArithmeticAll.C +++ b/test/FirstDerivative/BasicArithmeticAll.C @@ -7,27 +7,27 @@ extern "C" int printf(const char* fmt, ...); -float basic_1(int x) { - int y = 4; - int z = 3; +float basic_1(float x) { + float y = 4; + float z = 3; return (y + x) / (x - z) * ((x * y * z) / 5); // == y * z * (x * x - 2 * x * z - y * z) / (5 * (x - z) * (x - z)) } -// CHECK: float basic_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; -// CHECK-NEXT: int _d_z = 0; -// CHECK-NEXT: int z = 3; -// CHECK-NEXT: int _t0 = (y + x); -// CHECK-NEXT: int _t1 = (x - z); -// CHECK-NEXT: int _t2 = x * y; -// CHECK-NEXT: int _t3 = (_t2 * z); -// CHECK-NEXT: int _t4 = _t0 / _t1; -// CHECK-NEXT: int _t5 = (_t3 / 5); +// CHECK: float basic_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; +// CHECK-NEXT: float _d_z = 0; +// CHECK-NEXT: float z = 3; +// CHECK-NEXT: float _t0 = (y + x); +// CHECK-NEXT: float _t1 = (x - z); +// CHECK-NEXT: float _t2 = x * y; +// CHECK-NEXT: float _t3 = (_t2 * z); +// CHECK-NEXT: float _t4 = _t0 / _t1; +// CHECK-NEXT: float _t5 = (_t3 / 5); // CHECK-NEXT: return (((_d_y + _d_x) * _t1 - _t0 * (_d_x - _d_z)) / (_t1 * _t1)) * _t5 + _t4 * ((((_d_x * y + x * _d_y) * z + _t2 * _d_z) * 5 - _t3 * 0) / (5 * 5)); // CHECK-NEXT: } -float basic_1_darg0(int x); +float basic_1_darg0(float x); double fn1(double i, double j) { double t = 1; @@ -98,7 +98,7 @@ double fn3(double i, double j) { int main () { clad::differentiate(basic_1, 0); - printf("Result is = %f\n", basic_1_darg0(1)); // CHECK-EXEC: Result is = -6 + printf("Result is = %.2f\n", basic_1_darg0(1)); // CHECK-EXEC: Result is = -10.20 INIT(fn1, "i"); INIT(fn2, "i"); INIT(fn3, "i"); diff --git a/test/FirstDerivative/BasicArithmeticMulDiv.C b/test/FirstDerivative/BasicArithmeticMulDiv.C index b02506b36..932a5567e 100644 --- a/test/FirstDerivative/BasicArithmeticMulDiv.C +++ b/test/FirstDerivative/BasicArithmeticMulDiv.C @@ -7,60 +7,60 @@ extern "C" int printf(const char* fmt, ...); -int m_1(int x) { - int y = 4; +float m_1(float x) { + float y = 4; return y * y; // == 0 } -// CHECK: int m_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float m_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return _d_y * y + y * _d_y; // CHECK-NEXT: } -int m_2(int x) { +float m_2(float x) { return 1 * 1; // == 0 } -// CHECK: int m_2_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float m_2_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return 0 * 1 + 1 * 0; // CHECK-NEXT: } -int m_3(int x) { +float m_3(float x) { return x * x; // == 2 * x } -// CHECK: int m_3_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float m_3_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return _d_x * x + x * _d_x; // CHECK-NEXT: } -int m_4(int x) { - int y = 4; +float m_4(float x) { + float y = 4; return x * y * x * 3 * x; // == 9 * x * x * y } -// CHECK: int m_4_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; -// CHECK-NEXT: int _t0 = x * y; -// CHECK-NEXT: int _t1 = _t0 * x; -// CHECK-NEXT: int _t2 = _t1 * 3; +// CHECK: float m_4_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; +// CHECK-NEXT: float _t0 = x * y; +// CHECK-NEXT: float _t1 = _t0 * x; +// CHECK-NEXT: float _t2 = _t1 * 3; // CHECK-NEXT: return (((_d_x * y + x * _d_y) * x + _t0 * _d_x) * 3 + _t1 * 0) * x + _t2 * _d_x; // CHECK-NEXT: } -double m_5(int x) { +double m_5(float x) { return 3.14 * x; } -// CHECK: double m_5_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: double m_5_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return 0. * x + 3.1400000000000001 * _d_x; // CHECK-NEXT: } -float m_6(int x) { +float m_6(float x) { return 3.f * x; } -// CHECK: float m_6_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float m_6_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return 0.F * x + 3.F * _d_x; // CHECK-NEXT: } @@ -100,7 +100,6 @@ double m_10(double x, bool flag) { } // CHECK: double m_10_darg0(double x, bool flag) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: bool _d_flag = 0; // CHECK-NEXT: return flag ? (((_d_x = _d_x * 2 + x * 0) , (x *= 2)) , (_d_x * x + x * _d_x)) : (((_d_x += 0) , (x += 1)) , (_d_x * x + x * _d_x)); // CHECK-NEXT: } @@ -121,44 +120,44 @@ double m_11(double x) { // CHECK-NEXT: return _d_x * m + x * _d_m; // CHECK-NEXT: } -int d_1(int x) { - int y = 4; +float d_1(float x) { + float y = 4; return y / y; // == 0 } -// CHECK: int d_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float d_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return (_d_y * y - y * _d_y) / (y * y); // CHECK-NEXT: } -int d_2(int x) { +float d_2(float x) { return 1 / 1; // == 0 } -// CHECK: int d_2_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float d_2_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return (0 * 1 - 1 * 0) / (1 * 1); // CHECK-NEXT: } -int d_3(int x) { +float d_3(float x) { return x / x; // == 0 } -// CHECK: int d_3_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float d_3_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return (_d_x * x - x * _d_x) / (x * x); // CHECK-NEXT: } -int d_4(int x) { - int y = 4; +float d_4(float x) { + float y = 4; return x / y / x / 3 / x; // == -1 / 3 / x / x / y } -// CHECK: int d_4_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; -// CHECK-NEXT: int _t0 = x / y; -// CHECK-NEXT: int _t1 = _t0 / x; -// CHECK-NEXT: int _t2 = _t1 / 3; +// CHECK: float d_4_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; +// CHECK-NEXT: float _t0 = x / y; +// CHECK-NEXT: float _t1 = _t0 / x; +// CHECK-NEXT: float _t2 = _t1 / 3; // CHECK-NEXT: return (((((((_d_x * y - x * _d_y) / (y * y)) * x - _t0 * _d_x) / (x * x)) * 3 - _t1 * 0) / (3 * 3)) * x - _t2 * _d_x) / (x * x); // CHECK-NEXT: } @@ -180,94 +179,94 @@ double issue25(double x, double y) { // return 1.; // } -int md_1(int x) { - int y = 4; +float md_1(float x) { + float y = 4; return x * x / x * y / y * 3 / 3; // == 1 } -// CHECK: int md_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; -// CHECK-NEXT: int _t0 = x * x; -// CHECK-NEXT: int _t1 = _t0 / x; -// CHECK-NEXT: int _t2 = _t1 * y; -// CHECK-NEXT: int _t3 = _t2 / y; -// CHECK-NEXT: int _t4 = _t3 * 3; +// CHECK: float md_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; +// CHECK-NEXT: float _t0 = x * x; +// CHECK-NEXT: float _t1 = _t0 / x; +// CHECK-NEXT: float _t2 = _t1 * y; +// CHECK-NEXT: float _t3 = _t2 / y; +// CHECK-NEXT: float _t4 = _t3 * 3; // CHECK-NEXT: return ((((((((_d_x * x + x * _d_x) * x - _t0 * _d_x) / (x * x)) * y + _t1 * _d_y) * y - _t2 * _d_y) / (y * y)) * 3 + _t3 * 0) * 3 - _t4 * 0) / (3 * 3); // CHECK-NEXT: } -int m_1_darg0(int x); -int m_2_darg0(int x); -int m_3_darg0(int x); -int m_4_darg0(int x); -double m_5_darg0(int x); -float m_6_darg0(int x); +float m_1_darg0(float x); +float m_2_darg0(float x); +float m_3_darg0(float x); +float m_4_darg0(float x); +double m_5_darg0(float x); +float m_6_darg0(float x); double m_7_darg0(double x); double m_8_darg0(double x); double m_9_darg0(double x); double m_10_darg0(double x, bool flag); double m_11_darg0(double x); -int d_1_darg0(int x); -int d_2_darg0(int x); -int d_3_darg0(int x); -int d_4_darg0(int x); +float d_1_darg0(float x); +float d_2_darg0(float x); +float d_3_darg0(float x); +float d_4_darg0(float x); double issue25_darg0(double x, double y); -int md_1_darg0(int x); +float md_1_darg0(float x); int main () { - int x = 4; + float x = 4; clad::differentiate(m_1, 0); - printf("Result is = %d\n", m_1_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", m_1_darg0(1)); // CHECK-EXEC: Result is = 0.00 clad::differentiate(m_2, 0); - printf("Result is = %d\n", m_2_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", m_2_darg0(1)); // CHECK-EXEC: Result is = 0.00 clad::differentiate(m_3, 0); - printf("Result is = %d\n", m_3_darg0(1)); // CHECK-EXEC: Result is = 2 + printf("Result is = %.2f\n", m_3_darg0(1)); // CHECK-EXEC: Result is = 2.00 clad::differentiate(m_4, 0); - printf("Result is = %d\n", m_4_darg0(1)); // CHECK-EXEC: Result is = 36 + printf("Result is = %.2f\n", m_4_darg0(1)); // CHECK-EXEC: Result is = 36.00 clad::differentiate(m_5, 0); printf("Result is = %f\n", m_5_darg0(1)); // CHECK-EXEC: Result is = 3.14 clad::differentiate(m_6, 0); - printf("Result is = %f\n", m_6_darg0(1)); // CHECK-EXEC: Result is = 3 + printf("Result is = %f\n", m_6_darg0(1)); // CHECK-EXEC: Result is = 3.00 clad::differentiate(m_7, 0); - printf("Result is = %f\n", m_7_darg0(1)); // CHECK-EXEC: Result is = 4 + printf("Result is = %f\n", m_7_darg0(1)); // CHECK-EXEC: Result is = 4.00 clad::differentiate(m_8, 0); - printf("Result is = %f\n", m_8_darg0(1)); // CHECK-EXEC: Result is = 4 + printf("Result is = %f\n", m_8_darg0(1)); // CHECK-EXEC: Result is = 4.00 clad::differentiate(m_9, 0); - printf("Result is = %f\n", m_9_darg0(1)); // CHECK-EXEC: Result is = 8 + printf("Result is = %f\n", m_9_darg0(1)); // CHECK-EXEC: Result is = 8.00 clad::differentiate(m_10, 0); - printf("Result is = %f\n", m_10_darg0(1, true)); // CHECK-EXEC: Result is = 8 - printf("Result is = %f\n", m_10_darg0(1, false)); // CHECK-EXEC: Result is = 4 + printf("Result is = %f\n", m_10_darg0(1, true)); // CHECK-EXEC: Result is = 8.00 + printf("Result is = %f\n", m_10_darg0(1, false)); // CHECK-EXEC: Result is = 4.00 clad::differentiate(m_11<64>, 0); printf("Result is = %f\n", m_11_darg0(1)); // CHECK-EXEC: Result is = 53 clad::differentiate(d_1, 0); - printf("Result is = %d\n", d_1_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", d_1_darg0(1)); // CHECK-EXEC: Result is = 0.00 clad::differentiate(d_2, 0); - printf("Result is = %d\n", d_2_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", d_2_darg0(1)); // CHECK-EXEC: Result is = 0.00 clad::differentiate(d_3, 0); - printf("Result is = %d\n", d_3_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", d_3_darg0(1)); // CHECK-EXEC: Result is = 0.00 clad::differentiate(d_4, 0); - printf("Result is = %d\n", d_4_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", d_4_darg0(1)); // CHECK-EXEC: Result is = -0.08 //clad::differentiate(issue25, 0); //printf("Result is = %f\n", issue25_darg0(1.4, 2.3)); Result is = 1 clad::differentiate(md_1, 0); - printf("Result is = %d\n", md_1_darg0(1)); // CHECK-EXEC: Result is = 1 + printf("Result is = %.2f\n", md_1_darg0(1)); // CHECK-EXEC: Result is = 1.00 return 0; } diff --git a/test/FirstDerivative/Loops.C b/test/FirstDerivative/Loops.C index 03257ff34..40c6bae76 100644 --- a/test/FirstDerivative/Loops.C +++ b/test/FirstDerivative/Loops.C @@ -15,12 +15,10 @@ double f1(double x, int y) { double f1_darg0(double x, int y); // CHECK: double f1_darg0(double x, int y) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: int _d_y = 0; // CHECK-NEXT: double _d_r = 0.; // CHECK-NEXT: double r = 1.; // CHECK-NEXT: { -// CHECK-NEXT: int _d_i = 0; -// CHECK-NEXT: for (int i = 0; i < y; (_d_i = _d_i + 0) , (i = i + 1)) { +// CHECK-NEXT: for (int i = 0; i < y; i = i + 1) { // CHECK-NEXT: _d_r = _d_r * x + r * _d_x; // CHECK-NEXT: r = r * x; // CHECK-NEXT: } @@ -43,11 +41,9 @@ double f1_inc(double x, int y) { double f1_inc_darg0(double x, int y); //CHECK: double f1_inc_darg0(double x, int y) { //CHECK-NEXT: double _d_x = 1; -//CHECK-NEXT: int _d_y = 0; //CHECK-NEXT: double _d_r = 0.; //CHECK-NEXT: double r = 1.; //CHECK-NEXT: { -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: for (int i = 0; i < y; i++) { //CHECK-NEXT: _d_r = _d_r * x + r * _d_x; //CHECK-NEXT: r *= x; @@ -66,10 +62,8 @@ double f2(double x, int y) { double f2_darg0(double x, int y); // CHECK: double f2_darg0(double x, int y) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: int _d_y = 0; // CHECK-NEXT: { -// CHECK-NEXT: int _d_i = 0; -// CHECK-NEXT: for (int i = 0; i < y; (_d_i = _d_i + 0) , (i = i + 1)) { +// CHECK-NEXT: for (int i = 0; i < y; i = i + 1) { // CHECK-NEXT: _d_x = _d_x * x + x * _d_x; // CHECK-NEXT: x = x * x; // CHECK-NEXT: } @@ -92,9 +86,7 @@ double f2_inc(double x, int y) { double f2_inc_darg0(double x, int y); //CHECK: double f2_inc_darg0(double x, int y) { //CHECK-NEXT: double _d_x = 1; -//CHECK-NEXT: int _d_y = 0; //CHECK-NEXT: { -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: for (int i = 0; i < y; i++) { //CHECK-NEXT: _d_x = _d_x * x + x * _d_x; //CHECK-NEXT: x *= x; @@ -114,13 +106,10 @@ double f3(double x, int y) { double f3_darg0(double x, int y); // CHECK: double f3_darg0(double x, int y) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: int _d_y = 0; // CHECK-NEXT: double _d_r = 0.; // CHECK-NEXT: double r = 1.; // CHECK-NEXT: { -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: for (int i = 0; i < y; (_d_r = _d_r * x + r * _d_x) , (r = r * x)) { -// CHECK-NEXT: _d_i = _d_i + 0; // CHECK-NEXT: i = i + 1; // CHECK-NEXT: } // CHECK-NEXT: } @@ -138,11 +127,9 @@ double f3_inc(double x, int y) { double f3_inc_darg0(double x, int y); //CHECK: double f3_inc_darg0(double x, int y) { //CHECK-NEXT: double _d_x = 1; -//CHECK-NEXT: int _d_y = 0; //CHECK-NEXT: double _d_r = 0.; //CHECK-NEXT: double r = 1.; //CHECK-NEXT: { -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: for (int i = 0; i < y; (_d_r = _d_r * x + r * _d_x) , (r *= x)) //CHECK-NEXT: i++; //CHECK-NEXT: } @@ -161,10 +148,8 @@ double f4(double x, int y) { double f4_darg0(double x, int y); // CHECK: double f4_darg0(double x, int y) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: int _d_y = 0; // CHECK-NEXT: double _d_r = 0; // CHECK-NEXT: double r = 1; -// CHECK-NEXT: int _d_i; // CHECK-NEXT: int i; // CHECK-NEXT: { // CHECK-NEXT: _d_i = 0; @@ -174,10 +159,7 @@ double f4_darg0(double x, int y); // CHECK-NEXT: _d_r = _d_r * _t3 + r * _t2.pushforward; // CHECK-NEXT: r = r * _t3; // CHECK: } -// CHECK: ()) { -// CHECK-NEXT: _d_i = _d_i + 0; -// CHECK-NEXT: i = i + 1; -// CHECK-NEXT: } +// CHECK: ()) i = i + 1; // CHECK-NEXT: } // CHECK-NEXT: return _d_r; // CHECK-NEXT: } @@ -194,10 +176,8 @@ double f4_inc(double x, int y) { double f4_inc_darg0(double x, int y); //CHECK: double f4_inc_darg0(double x, int y) { //CHECK-NEXT: double _d_x = 1; -//CHECK-NEXT: int _d_y = 0; //CHECK-NEXT: double _d_r = 0; //CHECK-NEXT: double r = 1; -//CHECK-NEXT: int _d_i; //CHECK-NEXT: int i; //CHECK-NEXT: { //CHECK-NEXT: _d_i = 0; @@ -227,7 +207,6 @@ double fn5(double i, double j) { // CHECK: double fn5_darg0(double i, double j) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_b = 0; // CHECK-NEXT: int b = 3; // CHECK-NEXT: double _d_a = 0; // CHECK-NEXT: double a = 0; @@ -235,7 +214,6 @@ double fn5(double i, double j) { // CHECK-NEXT: { // CHECK-NEXT: _d_a += _d_i; // CHECK-NEXT: a += i; -// CHECK-NEXT: _d_b -= 0; // CHECK-NEXT: b -= 1; // CHECK-NEXT: } // CHECK-NEXT: return _d_a; @@ -254,14 +232,12 @@ double fn6(double i, double j) { // CHECK: double fn6_darg0(double i, double j) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_b = 0; // CHECK-NEXT: int b = 3; // CHECK-NEXT: double _d_a = 0; // CHECK-NEXT: double a = 0; // CHECK-NEXT: do { // CHECK-NEXT: _d_a += _d_i; // CHECK-NEXT: a += i; -// CHECK-NEXT: _d_b -= 0; // CHECK-NEXT: b -= 1; // CHECK-NEXT: } while (b); // CHECK-NEXT: return _d_a; @@ -284,7 +260,6 @@ double fn7(double i, double j) { // CHECK: double fn7_darg0(double i, double j) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_b = 0; // CHECK-NEXT: int b = 3; // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: double res = 0; @@ -295,14 +270,12 @@ double fn7(double i, double j) { // CHECK-NEXT: a += i; // CHECK-NEXT: _d_res += _d_a; // CHECK-NEXT: res += a; -// CHECK-NEXT: _d_b -= 0; // CHECK-NEXT: b -= 1; // CHECK-NEXT: } // CHECK-NEXT: _d_b = 0; // CHECK-NEXT: b = 1; // CHECK-NEXT: while (b) // CHECK-NEXT: { -// CHECK-NEXT: _d_b -= 0; // CHECK-NEXT: b -= 1; // CHECK-NEXT: } // CHECK-NEXT: return _d_res; @@ -339,14 +312,11 @@ double fn9(double i, double j) { // CHECK: double fn9_darg0(double i, double j) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: int counter = 4; // CHECK-NEXT: double _d_a = _d_i * j + i * _d_j; // CHECK-NEXT: double a = i * j; // CHECK-NEXT: while (int num = counter) // CHECK-NEXT: { -// CHECK-NEXT: int _d_num = _d_counter; -// CHECK-NEXT: _d_counter -= 0; // CHECK-NEXT: counter -= 1; // CHECK-NEXT: if (num == 2) // CHECK-NEXT: continue;