From e04d04e9f483e033cffde7e1a669be622da27269 Mon Sep 17 00:00:00 2001 From: Rohan Julka Date: Tue, 12 Mar 2024 00:50:25 +0000 Subject: [PATCH] Differentiate for loop conditions in reverse mode (vgvassilev#746) This change differentiates the loop condition expression. Additionaly if in forward pass a loop terminates pre-maturely due to break stmt. The reverse pass should start differentiation with break statment and not the loop condition differentiation. This change keeps track of whether the break was called in forward pass and based on that in reverse mode it is decided whether the loop differentiation is skipped for the first iteration or not. --- .../clad/Differentiator/ReverseModeVisitor.h | 13 +- lib/Differentiator/ReverseModeVisitor.cpp | 113 +- test/Arrays/ArrayInputsReverseMode.C | 188 +- test/CUDA/GradientCuda.cu | 12 +- test/ErrorEstimation/LoopsAndArrays.C | 36 +- test/ErrorEstimation/LoopsAndArraysExec.C | 48 +- test/Gradient/Assignments.C | 2 +- test/Gradient/FunctionCalls.C | 37 +- test/Gradient/Gradients.C | 15 +- test/Gradient/Loops.C | 1775 +++++++++++++---- test/Gradient/Pointers.C | 12 +- test/Gradient/Switch.C | 12 +- test/Gradient/TestTypeConversion.C | 12 +- test/Gradient/UserDefinedTypes.C | 48 +- test/Misc/RunDemos.C | 62 +- 15 files changed, 1881 insertions(+), 504 deletions(-) diff --git a/include/clad/Differentiator/ReverseModeVisitor.h b/include/clad/Differentiator/ReverseModeVisitor.h index 11673bb63..76e28c9db 100644 --- a/include/clad/Differentiator/ReverseModeVisitor.h +++ b/include/clad/Differentiator/ReverseModeVisitor.h @@ -61,6 +61,11 @@ namespace clad { /// Output variable of vector-valued function std::string outputArrayStr; std::vector m_LoopBlock; + /// This expression checks if the forward pass loop was terminted due to + /// break. It is used to determine whether to run the loop cond + /// differentiation. One additional time. + clang::Expr* m_CurrentBreakFlagExpr; + unsigned outputArrayCursor = 0; unsigned numParams = 0; // FIXME: Should we make this an object instead of a pointer? @@ -561,7 +566,6 @@ namespace clad { ReverseModeVisitor& m_RMV; - const bool m_IsInvokedBySwitchStmt = false; /// Builds and returns a literal expression of type `std::size_t` with /// `value` as value. clang::Expr* CreateSizeTLiteralExpr(std::size_t value); @@ -576,6 +580,8 @@ namespace clad { clang::Expr* CreateCFTapePushExpr(std::size_t value); public: + bool m_IsInvokedBySwitchStmt = false; + BreakContStmtHandler(ReverseModeVisitor& RMV, bool forSwitchStmt = false) : m_RMV(RMV), m_IsInvokedBySwitchStmt(forSwitchStmt) {} @@ -598,6 +604,11 @@ namespace clad { /// by their actual values respectively. clang::Stmt* CreateCFTapePushExprToCurrentCase(); + /// Builds and return `clad::back(TapeRef) != m_CaseCounter` + /// expression, where `TapeRef` and `m_CaseCounter` are replaced + /// by their actual values respectively + clang::Expr* CreateCFTapeBackExprForCurrentCase(); + /// Does final modifications on forward and reverse blocks /// so that `break` and `continue` statements are handled /// accurately. diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index 6394ee9dd..ad2a85df2 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -880,7 +880,6 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, StmtDiff thenDiff = VisitBranch(If->getThen()); StmtDiff elseDiff = VisitBranch(If->getElse()); - Stmt* Forward = clad_compat::IfStmt_Create( m_Context, noLoc, If->isConstexpr(), /*Init=*/nullptr, /*Var=*/nullptr, condDiffStored, noLoc, noLoc, thenDiff.getStmt(), noLoc, @@ -992,6 +991,9 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, Scope::ContinueScope); beginBlock(direction::reverse); LoopCounter loopCounter(*this); + llvm::SaveAndRestore SaveCurrentBreakFlagExpr( + m_CurrentBreakFlagExpr); + m_CurrentBreakFlagExpr = nullptr; const Stmt* init = FS->getInit(); if (m_ExternalSource) m_ExternalSource->ActBeforeDifferentiatingLoopInitStmt(); @@ -1000,7 +1002,6 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // Save the isInsideLoop value (we may be inside another loop). llvm::SaveAndRestore SaveIsInsideLoop(isInsideLoop); isInsideLoop = true; - StmtDiff condVarRes; VarDecl* condVarClone = nullptr; if (FS->getConditionVariable()) { @@ -1011,11 +1012,12 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } } - // FIXME: for now we assume that cond has no differentiable effects, // but it is not generally true, e.g. for (...; (x = y); ...)... - StmtDiff cond; + StmtDiff condDiff; + StmtDiff condExprDiff; if (FS->getCond()) - cond = Visit(FS->getCond()); + std::tie(condDiff, condExprDiff) = DifferentiateSingleExpr(FS->getCond()); + const auto* IDRE = dyn_cast(FS->getInc()); const Expr* inc = IDRE ? Visit(FS->getInc()).getExpr() : FS->getInc(); @@ -1063,7 +1065,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, /// with function globals and replace initializations with assignments. /// This is a temporary measure to avoid the bug that arises from /// overwriting local variables on different loop passes. - Expr* forwardCond = cond.getExpr(); + Expr* forwardCond = condExprDiff.getExpr(); /// If there is a declaration in the condition, `cond` will be /// a DeclRefExpr of the declared variable. There is no point in /// inserting it since condVarRes.getExpr() represents an assignment with @@ -1073,8 +1075,36 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, if (condVarRes.getExpr() != nullptr && isa(condVarRes.getExpr())) forwardCond = cast(condVarRes.getExpr()); + Stmt* breakStmt = m_Sema.ActOnBreakStmt(noLoc, getCurrentScope()).get(); + + /// This part adds the forward pass of loop condition stmt in the body + /// In this first loop condition diff stmts execute then loop condition + /// is checked if and loop is terminated. + beginBlock(); + if (utils::unwrapIfSingleStmt(condDiff.getStmt())) + addToCurrentBlock(condDiff.getStmt()); + + Stmt* IfStmt = clad_compat::IfStmt_Create( + /*Ctx=*/m_Context, /*IL=*/noLoc, /*IsConstexpr=*/false, + /*Init=*/nullptr, /*Var=*/nullptr, + /*Cond=*/ + BuildOp(clang::UnaryOperatorKind::UO_LNot, BuildParens(forwardCond)), + /*LPL=*/noLoc, /*RPL=*/noLoc, + /*Then=*/breakStmt, + /*EL=*/noLoc, + /*Else=*/nullptr); + addToCurrentBlock(IfStmt); + + Stmt* forwardCondStmts = endBlock(); + if (BodyDiff.getStmt()) { + BodyDiff.updateStmt(utils::PrependAndCreateCompoundStmt( + m_Context, BodyDiff.getStmt(), forwardCondStmts)); + } else { + BodyDiff.updateStmt(utils::unwrapIfSingleStmt(forwardCondStmts)); + } + Stmt* Forward = new (m_Context) - ForStmt(m_Context, initResult.getStmt(), forwardCond, condVarClone, + ForStmt(m_Context, initResult.getStmt(), nullptr, condVarClone, incResult, BodyDiff.getStmt(), noLoc, noLoc, noLoc); // Create a condition testing counter for being zero, and its decrement. @@ -1084,12 +1114,45 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, CounterCondition = loopCounter.getCounterConditionResult().get().second; Expr* CounterDecrement = loopCounter.getCounterDecrement(); - Stmt* ReverseResult = BodyDiff.getStmt_dx(); - if (!ReverseResult) - ReverseResult = new (m_Context) NullStmt(noLoc); + /// This part adds the reverse pass of loop condition stmt in the body + beginBlock(direction::reverse); + Stmt* RevIfStmt = clad_compat::IfStmt_Create( + /*Ctx=*/m_Context, /*IL=*/noLoc, /*IsConstexpr=*/false, + /*Init=*/nullptr, /*Var=*/nullptr, + /*Cond=*/BuildOp(clang::UnaryOperatorKind::UO_LNot, CounterCondition), + /*LPL=*/noLoc, /*RPL=*/noLoc, + /*Then=*/Clone(breakStmt), + /*EL=*/noLoc, + /*Else=*/nullptr); + addToCurrentBlock(RevIfStmt, direction::reverse); + + if (condDiff.getStmt_dx()) { + if (m_CurrentBreakFlagExpr) { + Expr* loopBreakFlagCond = + BuildOp(BinaryOperatorKind::BO_LOr, + BuildOp(UnaryOperatorKind::UO_LNot, CounterCondition), + BuildParens(m_CurrentBreakFlagExpr)); + auto* RevIfStmt = clad_compat::IfStmt_Create( + m_Context, noLoc, false, nullptr, nullptr, loopBreakFlagCond, noLoc, + noLoc, condDiff.getStmt_dx(), noLoc, nullptr); + addToCurrentBlock(RevIfStmt, direction::reverse); + } else { + addToCurrentBlock(condDiff.getStmt_dx(), direction::reverse); + } + } + + Stmt* revPassCondStmts = endBlock(direction::reverse); + if (BodyDiff.getStmt_dx()) { + BodyDiff.updateStmtDx(utils::PrependAndCreateCompoundStmt( + m_Context, BodyDiff.getStmt_dx(), revPassCondStmts)); + } else { + BodyDiff.updateStmtDx(utils::unwrapIfSingleStmt(revPassCondStmts)); + } + Stmt* Reverse = new (m_Context) - ForStmt(m_Context, nullptr, CounterCondition, nullptr, CounterDecrement, - ReverseResult, noLoc, noLoc, noLoc); + ForStmt(m_Context, nullptr, nullptr, nullptr, CounterDecrement, + BodyDiff.getStmt_dx(), noLoc, noLoc, noLoc); + addToCurrentBlock(initResult.getStmt_dx(), direction::reverse); addToCurrentBlock(Reverse, direction::reverse); Reverse = endBlock(direction::reverse); @@ -2391,14 +2454,18 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } else if (opCode == BO_Comma) { auto* zero = ConstantFolder::synthesizeLiteral(m_Context.IntTy, m_Context, 0); - Ldiff = Visit(L, zero); Rdiff = Visit(R, dfdx()); + Ldiff = Visit(L, zero); valueForRevPass = Ldiff.getRevSweepAsExpr(); ResultRef = Ldiff.getExpr(); } else if (opCode == BO_LAnd) { VarDecl* condVar = GlobalStoreImpl(m_Context.BoolTy, "_cond"); VarDecl* derivedCondVar = GlobalStoreImpl( m_Context.DoubleTy, "_d" + condVar->getNameAsString()); + addToBlock(BuildOp(BO_Assign, BuildDeclRef(derivedCondVar), + ConstantFolder::synthesizeLiteral( + m_Context.DoubleTy, m_Context, /*val=*/0)), + m_Globals); Expr* condVarRef = BuildDeclRef(condVar); Expr* assignExpr = BuildOp(BO_Assign, condVarRef, Clone(R)); m_Variables.emplace(condVar, BuildDeclRef(derivedCondVar)); @@ -3546,6 +3613,18 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, Stmt* CFCaseStmt = activeBreakContHandler->GetNextCFCaseStmt(); Stmt* pushExprToCurrentCase = activeBreakContHandler ->CreateCFTapePushExprToCurrentCase(); + if (isInsideLoop && !activeBreakContHandler->m_IsInvokedBySwitchStmt) { + Expr* tapeBackExprForCurrentCase = + activeBreakContHandler->CreateCFTapeBackExprForCurrentCase(); + if (m_CurrentBreakFlagExpr) { + m_CurrentBreakFlagExpr = + BuildOp(BinaryOperatorKind::BO_LAnd, m_CurrentBreakFlagExpr, + tapeBackExprForCurrentCase); + + } else { + m_CurrentBreakFlagExpr = tapeBackExprForCurrentCase; + } + } addToCurrentBlock(pushExprToCurrentCase); addToCurrentBlock(newBS); return {endBlock(direction::forward), CFCaseStmt}; @@ -3607,6 +3686,14 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, return CS; } + Expr* ReverseModeVisitor::BreakContStmtHandler:: + CreateCFTapeBackExprForCurrentCase() { + return m_RMV.BuildOp( + BinaryOperatorKind::BO_NE, m_ControlFlowTape->Last(), + ConstantFolder::synthesizeLiteral(m_RMV.m_Context.IntTy, + m_RMV.m_Context, m_CaseCounter)); + } + Stmt* ReverseModeVisitor::BreakContStmtHandler:: CreateCFTapePushExprToCurrentCase() { if (!m_ControlFlowTape) diff --git a/test/Arrays/ArrayInputsReverseMode.C b/test/Arrays/ArrayInputsReverseMode.C index 74d6b0e3a..b8accb35f 100644 --- a/test/Arrays/ArrayInputsReverseMode.C +++ b/test/Arrays/ArrayInputsReverseMode.C @@ -46,7 +46,11 @@ float func(float* a, float* b) { //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: float sum = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, a[i]); //CHECK-NEXT: a[i] *= b[i]; @@ -54,7 +58,11 @@ float func(float* a, float* b) { //CHECK-NEXT: sum += a[i]; //CHECK-NEXT: } //CHECK-NEXT: _d_sum += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: { //CHECK-NEXT: sum = clad::pop(_t2); @@ -92,13 +100,21 @@ float func2(float* a) { //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: float sum = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sum); //CHECK-NEXT: sum += helper(a[i]); //CHECK-NEXT: } //CHECK-NEXT: _d_sum += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: sum = clad::pop(_t1); //CHECK-NEXT: float _r_d0 = _d_sum; @@ -124,14 +140,22 @@ float func3(float* a, float* b) { //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: float sum = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sum); //CHECK-NEXT: clad::push(_t2, a[i]); //CHECK-NEXT: sum += (a[i] += b[i]); //CHECK-NEXT: } //CHECK-NEXT: _d_sum += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: sum = clad::pop(_t1); //CHECK-NEXT: float _r_d0 = _d_sum; @@ -161,13 +185,21 @@ double func4(double x) { //CHECK-NEXT: double arr[3] = {x, 2 * x, x * x}; //CHECK-NEXT: double sum = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sum); //CHECK-NEXT: sum += addArr(arr, 3); //CHECK-NEXT: } //CHECK-NEXT: _d_sum += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: { //CHECK-NEXT: sum = clad::pop(_t1); @@ -217,20 +249,32 @@ double func5(int k) { //CHECK-NEXT: clad::zero_init(_d_arr, n); //CHECK-NEXT: double arr[n]; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < n; i++) { +//CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, arr[i]); //CHECK-NEXT: arr[i] = k; //CHECK-NEXT: } //CHECK-NEXT: double sum = 0; //CHECK-NEXT: _t2 = {{0U|0UL}}; -//CHECK-NEXT: for (i0 = 0; i0 < 3; i0++) { +//CHECK-NEXT: for (i0 = 0; ; i0++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i0 < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t2++; //CHECK-NEXT: clad::push(_t3, sum); //CHECK-NEXT: sum += addArr(arr, n); //CHECK-NEXT: } //CHECK-NEXT: _d_sum += 1; -//CHECK-NEXT: for (; _t2; _t2--) { +//CHECK-NEXT: for (;; _t2--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t2) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i0--; //CHECK-NEXT: { //CHECK-NEXT: sum = clad::pop(_t3); @@ -240,7 +284,11 @@ double func5(int k) { //CHECK-NEXT: _d_n += _r0; //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: { //CHECK-NEXT: arr[i] = clad::pop(_t1); @@ -272,14 +320,22 @@ double func6(double seed) { //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: double sum = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 3; i++) { +//CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, arr) , arr = {seed, seed * i, seed + i}; //CHECK-NEXT: clad::push(_t2, sum); //CHECK-NEXT: sum += addArr(arr, 3); //CHECK-NEXT: } //CHECK-NEXT: _d_sum += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: { //CHECK-NEXT: sum = clad::pop(_t2); @@ -325,14 +381,22 @@ double func7(double *params) { //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: double out = 0.; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 1; ++i) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: clad::push(_t1, paramsPrime) , paramsPrime = {params[0]}; -//CHECK-NEXT: clad::push(_t2, out); -//CHECK-NEXT: out = out + inv_square(paramsPrime); -//CHECK-NEXT: } -//CHECK-NEXT: _d_out += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 1)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, paramsPrime) , paramsPrime = {params[0]}; +// CHECK-NEXT: clad::push(_t2, out); +// CHECK-NEXT: out = out + inv_square(paramsPrime); +// CHECK-NEXT: } +// CHECK-NEXT: _d_out += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: --i; //CHECK-NEXT: { //CHECK-NEXT: out = clad::pop(_t2); @@ -421,19 +485,27 @@ double func9(double i, double j) { //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double arr[5] = {}; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (idx = 0; idx < 5; ++idx) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: clad::push(_t1, arr[idx]); -//CHECK-NEXT: modify(arr[idx], i); -//CHECK-NEXT: } -//CHECK-NEXT: { -//CHECK-NEXT: _d_arr[0] += 1; -//CHECK-NEXT: _d_arr[1] += 1; -//CHECK-NEXT: _d_arr[2] += 1; -//CHECK-NEXT: _d_arr[3] += 1; -//CHECK-NEXT: _d_arr[4] += 1; -//CHECK-NEXT: } -//CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (idx = 0; ; ++idx) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(idx < 5)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, arr[idx]); +// CHECK-NEXT: modify(arr[idx], i); +// CHECK-NEXT: } +// CHECK-NEXT: { +// CHECK-NEXT: _d_arr[0] += 1; +// CHECK-NEXT: _d_arr[1] += 1; +// CHECK-NEXT: _d_arr[2] += 1; +// CHECK-NEXT: _d_arr[3] += 1; +// CHECK-NEXT: _d_arr[4] += 1; +// CHECK-NEXT: } +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: --idx; //CHECK-NEXT: { //CHECK-NEXT: arr[idx] = clad::back(_t1); @@ -470,14 +542,22 @@ double func10(double *arr, int n) { //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: double res = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < n; ++i) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: clad::push(_t1, res); -//CHECK-NEXT: clad::push(_t2, arr[i]); -//CHECK-NEXT: res += sq(arr[i]); -//CHECK-NEXT: } -//CHECK-NEXT: _d_res += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, res); +// CHECK-NEXT: clad::push(_t2, arr[i]); +// CHECK-NEXT: res += sq(arr[i]); +// CHECK-NEXT: } +// CHECK-NEXT: _d_res += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: --i; //CHECK-NEXT: { //CHECK-NEXT: res = clad::pop(_t1); @@ -563,13 +643,21 @@ int main() { //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double ret = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < n; i++) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: clad::push(_t1, ret); -//CHECK-NEXT: ret += arr[i]; -//CHECK-NEXT: } -//CHECK-NEXT: _d_ret += _d_y; -//CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, ret); +// CHECK-NEXT: ret += arr[i]; +// CHECK-NEXT: } +// CHECK-NEXT: _d_ret += _d_y; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: { //CHECK-NEXT: ret = clad::pop(_t1); diff --git a/test/CUDA/GradientCuda.cu b/test/CUDA/GradientCuda.cu index ea8e617f7..ae21beea3 100644 --- a/test/CUDA/GradientCuda.cu +++ b/test/CUDA/GradientCuda.cu @@ -43,7 +43,11 @@ __device__ __host__ double gauss(double* x, double* p, double sigma, int dim) { //CHECK-NEXT: double _t6; //CHECK-NEXT: double t = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < dim; i++) { +//CHECK-NEXT: for (i = 0; ; i++) { +//CHECK-NEXT: { +//CHECK-NEXT: if (!(i < dim)) +//CHECK-NEXT: break; +//CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, t); //CHECK-NEXT: t += (x[i] - p[i]) * (x[i] - p[i]); @@ -76,7 +80,11 @@ __device__ __host__ double gauss(double* x, double* p, double sigma, int dim) { //CHECK-NEXT: _d_sigma += 2 * _r0 * sigma; //CHECK-NEXT: _d_sigma += 2 * sigma * _r0; //CHECK-NEXT: } -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +//CHECK-NEXT: { +//CHECK-NEXT: if (!_t0) +//CHECK-NEXT: break; +//CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: t = clad::pop(_t1); //CHECK-NEXT: double _r_d0 = _d_t; diff --git a/test/ErrorEstimation/LoopsAndArrays.C b/test/ErrorEstimation/LoopsAndArrays.C index 6431e440a..893d6ad1b 100644 --- a/test/ErrorEstimation/LoopsAndArrays.C +++ b/test/ErrorEstimation/LoopsAndArrays.C @@ -23,13 +23,21 @@ float func(float* p, int n) { //CHECK-NEXT: unsigned {{int|long}} p_size = 0; //CHECK-NEXT: float sum = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < n; i++) { +//CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sum); //CHECK-NEXT: sum += p[i]; //CHECK-NEXT: } //CHECK-NEXT: _d_sum += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: { //CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); @@ -66,14 +74,22 @@ float func2(float x) { //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: float z; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 9; i++) { +//CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 9)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, m) , m = x * x; //CHECK-NEXT: clad::push(_t2, z); //CHECK-NEXT: z = m + m; //CHECK-NEXT: } //CHECK-NEXT: _d_z += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: { //CHECK-NEXT: _final_error += std::abs(_d_z * z * {{.+}}); @@ -163,7 +179,11 @@ float func4(float x[10], float y[10]) { //CHECK-NEXT: clad::tape _t2 = {}; //CHECK-NEXT: float sum = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 10; i++) { +//CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 10)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, x[i]); //CHECK-NEXT: x[i] += y[i]; @@ -171,7 +191,11 @@ float func4(float x[10], float y[10]) { //CHECK-NEXT: sum += x[i]; //CHECK-NEXT: } //CHECK-NEXT: _d_sum += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: { //CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); diff --git a/test/ErrorEstimation/LoopsAndArraysExec.C b/test/ErrorEstimation/LoopsAndArraysExec.C index 3c75d2cdc..d55aa0b41 100644 --- a/test/ErrorEstimation/LoopsAndArraysExec.C +++ b/test/ErrorEstimation/LoopsAndArraysExec.C @@ -24,13 +24,21 @@ double runningSum(float* f, int n) { //CHECK-NEXT: unsigned {{int|long}} f_size = 0; //CHECK-NEXT: double sum = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 1; i < n; i++) { +//CHECK-NEXT: for (i = 1; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sum); //CHECK-NEXT: sum += f[i] + f[i - 1]; //CHECK-NEXT: } //CHECK-NEXT: _d_sum += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: { //CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); @@ -71,20 +79,36 @@ double mulSum(float* a, float* b, int n) { //CHECK-NEXT: unsigned {{int|long}} b_size = 0; //CHECK-NEXT: double sum = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < n; i++) { +//CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, {{0U|0UL}}); -//CHECK-NEXT: for (clad::push(_t2, j) , j = 0; j < n; j++) { +//CHECK-NEXT: for (clad::push(_t2, j) , j = 0; ; j++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(j < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: clad::back(_t1)++; //CHECK-NEXT: clad::push(_t3, sum); //CHECK-NEXT: sum += a[i] * b[j]; //CHECK-NEXT: } //CHECK-NEXT: } //CHECK-NEXT: _d_sum += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: { -//CHECK-NEXT: for (; clad::back(_t1); clad::back(_t1)--) { +//CHECK-NEXT: for (;; clad::back(_t1)--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!clad::back(_t1)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: j--; //CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: sum = clad::pop(_t3); @@ -128,13 +152,21 @@ double divSum(float* a, float* b, int n) { //CHECK-NEXT: unsigned {{int|long}} a_size = 0; //CHECK-NEXT: double sum = 0; //CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < n; i++) { +//CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, sum); //CHECK-NEXT: sum += a[i] / b[i]; //CHECK-NEXT: } //CHECK-NEXT: _d_sum += 1; -//CHECK-NEXT: for (; _t0; _t0--) { +//CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } //CHECK-NEXT: i--; //CHECK-NEXT: { //CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); diff --git a/test/Gradient/Assignments.C b/test/Gradient/Assignments.C index 4aba01a28..67883e98e 100644 --- a/test/Gradient/Assignments.C +++ b/test/Gradient/Assignments.C @@ -819,9 +819,9 @@ double f21 (double x, double y) { //CHECK-NEXT: y = _t0; //CHECK-NEXT: double _r_d0 = *_d_y; //CHECK-NEXT: *_d_y -= _r_d0; +//CHECK-NEXT: *_d_x += _r_d0; //CHECK-NEXT: *_d_y += 0; //CHECK-NEXT: y--; -//CHECK-NEXT: *_d_x += _r_d0; //CHECK-NEXT: } //CHECK-NEXT: } diff --git a/test/Gradient/FunctionCalls.C b/test/Gradient/FunctionCalls.C index 6004d39db..eb68cda3d 100644 --- a/test/Gradient/FunctionCalls.C +++ b/test/Gradient/FunctionCalls.C @@ -166,7 +166,11 @@ double fn4(double* arr, int n) { // CHECK-NEXT: _t0 = res; // CHECK-NEXT: res += sum(arr, n); // CHECK-NEXT: _t1 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < n; ++i) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t1++; // CHECK-NEXT: clad::push(_t2, arr[i]); // CHECK-NEXT: twice(arr[i]); @@ -174,7 +178,11 @@ double fn4(double* arr, int n) { // CHECK-NEXT: res += arr[i]; // CHECK-NEXT: } // CHECK-NEXT: _d_res += 1; -// CHECK-NEXT: for (; _t1; _t1--) { +// CHECK-NEXT: for (;; _t1--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t1) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --i; // CHECK-NEXT: { // CHECK-NEXT: res = clad::pop(_t3); @@ -501,13 +509,21 @@ double fn13(double* x, const double* w) { // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double wCopy[2]; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < 2; ++i) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 2)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, wCopy[i]); // CHECK-NEXT: wCopy[i] = w[i]; // CHECK-NEXT: } // CHECK-NEXT: multiply_pullback(x, wCopy + 1, 1, _d_x, _d_wCopy + 1); -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --i; // CHECK-NEXT: { // CHECK-NEXT: wCopy[i] = clad::pop(_t1); @@ -890,7 +906,11 @@ double sq_defined_later(double x) { // CHECK-NEXT: double _t2; // CHECK-NEXT: float res = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < n; ++i) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, res); // CHECK-NEXT: res += arr[i]; @@ -903,7 +923,11 @@ double sq_defined_later(double x) { // CHECK-NEXT: double _r_d1 = _d_arr[0]; // CHECK-NEXT: _d_arr[0] += 10 * _r_d1; // CHECK-NEXT: } -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --i; // CHECK-NEXT: res = clad::pop(_t1); // CHECK-NEXT: float _r_d0 = _d_res; @@ -968,6 +992,7 @@ double sq_defined_later(double x) { // CHECK: void check_and_return_pullback(double x, char c, const char *s, double _d_y, double *_d_x, char *_d_c, char *_d_s) { // CHECK-NEXT: bool _cond0; // CHECK-NEXT: double _d_cond0; +// CHECK-NEXT: _d_cond0 = 0.; // CHECK-NEXT: bool _cond1; // CHECK-NEXT: bool _t0; // CHECK-NEXT: bool _cond2; diff --git a/test/Gradient/Gradients.C b/test/Gradient/Gradients.C index 730ca8884..79885a5ad 100644 --- a/test/Gradient/Gradients.C +++ b/test/Gradient/Gradients.C @@ -653,13 +653,21 @@ float running_sum(float* p, int n) { // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 1; i < n; i++) { +// CHECK-NEXT: for (i = 1; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, p[i]); // CHECK-NEXT: p[i] += p[i - 1]; // CHECK-NEXT: } // CHECK-NEXT: _d_p[n - 1] += 1; -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: i--; // CHECK-NEXT: { // CHECK-NEXT: p[i] = clad::pop(_t1); @@ -936,6 +944,7 @@ double fn_cond_false(double i, double j) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: bool _cond0; // CHECK-NEXT: double _d_cond0; +// CHECK-NEXT: _d_cond0 = 0.; // CHECK-NEXT: bool _cond1; // CHECK-NEXT: bool _t0; // CHECK-NEXT: bool _cond2; @@ -988,8 +997,10 @@ double fn_cond_add_assign(double i, double j) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: bool _cond0; // CHECK-NEXT: double _d_cond0; +// CHECK-NEXT: _d_cond0 = 0.; // CHECK-NEXT: bool _cond1; // CHECK-NEXT: double _d_cond1; +// CHECK-NEXT: _d_cond1 = 0.; // CHECK-NEXT: double _t0; // CHECK-NEXT: bool _cond2; // CHECK-NEXT: bool _t1; diff --git a/test/Gradient/Loops.C b/test/Gradient/Loops.C index 22ac4afcf..dd4a53b26 100644 --- a/test/Gradient/Loops.C +++ b/test/Gradient/Loops.C @@ -16,29 +16,37 @@ double f1(double x) { return t; } // == x^3 -//CHECK: void f1_grad(double x, double *_d_x) { -//CHECK-NEXT: double _d_t = 0; -//CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: clad::tape _t1 = {}; -//CHECK-NEXT: double t = 1; -//CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 3; i++) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: clad::push(_t1, t); -//CHECK-NEXT: t *= x; -//CHECK-NEXT: } -//CHECK-NEXT: _d_t += 1; -//CHECK-NEXT: for (; _t0; _t0--) { -//CHECK-NEXT: i--; -//CHECK-NEXT: t = clad::pop(_t1); -//CHECK-NEXT: double _r_d0 = _d_t; -//CHECK-NEXT: _d_t -= _r_d0; -//CHECK-NEXT: _d_t += _r_d0 * x; -//CHECK-NEXT: *_d_x += t * _r_d0; -//CHECK-NEXT: } -//CHECK-NEXT: } +// CHECK: void f1_grad(double x, double *_d_x) { +// CHECK-NEXT: double _d_t = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: double t = 1; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, t); +// CHECK-NEXT: t *= x; +// CHECK-NEXT: } +// CHECK-NEXT: _d_t += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: i--; +// CHECK-NEXT: t = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_t; +// CHECK-NEXT: _d_t -= _r_d0; +// CHECK-NEXT: _d_t += _r_d0 * x; +// CHECK-NEXT: *_d_x += t * _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: } double f2(double x) { double t = 1; @@ -48,45 +56,61 @@ double f2(double x) { return t; } // == x^9 -//CHECK: void f2_grad(double x, double *_d_x) { -//CHECK-NEXT: double _d_t = 0; -//CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: clad::tape _t1 = {}; -//CHECK-NEXT: clad::tape _t2 = {}; -//CHECK-NEXT: int _d_j = 0; -//CHECK-NEXT: int j = 0; -//CHECK-NEXT: clad::tape _t3 = {}; -//CHECK-NEXT: double t = 1; -//CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 3; i++) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: clad::push(_t1, {{0U|0UL}}); -//CHECK-NEXT: for (clad::push(_t2, j) , j = 0; j < 3; j++) { -//CHECK-NEXT: clad::back(_t1)++; -//CHECK-NEXT: clad::push(_t3, t); -//CHECK-NEXT: t *= x; -//CHECK-NEXT: } -//CHECK-NEXT: } -//CHECK-NEXT: _d_t += 1; -//CHECK-NEXT: for (; _t0; _t0--) { -//CHECK-NEXT: i--; -//CHECK-NEXT: for (; clad::back(_t1); clad::back(_t1)--) { -//CHECK-NEXT: j--; -//CHECK-NEXT: t = clad::pop(_t3); -//CHECK-NEXT: double _r_d0 = _d_t; -//CHECK-NEXT: _d_t -= _r_d0; -//CHECK-NEXT: _d_t += _r_d0 * x; -//CHECK-NEXT: *_d_x += t * _r_d0; -//CHECK-NEXT: } -//CHECK-NEXT: { -//CHECK-NEXT: _d_j = 0; -//CHECK-NEXT: j = clad::pop(_t2); -//CHECK-NEXT: } -//CHECK-NEXT: clad::pop(_t1); -//CHECK-NEXT: } -//CHECK-NEXT: } +// CHECK: void f2_grad(double x, double *_d_x) { +// CHECK-NEXT: double _d_t = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: clad::tape _t2 = {}; +// CHECK-NEXT: int _d_j = 0; +// CHECK-NEXT: int j = 0; +// CHECK-NEXT: clad::tape _t3 = {}; +// CHECK-NEXT: double t = 1; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, {{0U|0UL}}); +// CHECK-NEXT: for (clad::push(_t2, j) , j = 0; ; j++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(j < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: clad::back(_t1)++; +// CHECK-NEXT: clad::push(_t3, t); +// CHECK-NEXT: t *= x; +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: _d_t += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: i--; +// CHECK-NEXT: for (;; clad::back(_t1)--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!clad::back(_t1)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: j--; +// CHECK-NEXT: t = clad::pop(_t3); +// CHECK-NEXT: double _r_d0 = _d_t; +// CHECK-NEXT: _d_t -= _r_d0; +// CHECK-NEXT: _d_t += _r_d0 * x; +// CHECK-NEXT: *_d_x += t * _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: { +// CHECK-NEXT: _d_j = 0; +// CHECK-NEXT: j = clad::pop(_t2); +// CHECK-NEXT: } +// CHECK-NEXT: clad::pop(_t1); +// CHECK-NEXT: } +// CHECK-NEXT: } double f3(double x) { double t = 1; @@ -98,43 +122,51 @@ double f3(double x) { return t; } // == x^2 -//CHECK: void f3_grad(double x, double *_d_x) { -//CHECK-NEXT: double _d_t = 0; -//CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: clad::tape _t1 = {}; -//CHECK-NEXT: clad::tape _cond0 = {}; -//CHECK-NEXT: double t = 1; -//CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 3; i++) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: clad::push(_t1, t); -//CHECK-NEXT: t *= x; -//CHECK-NEXT: { -//CHECK-NEXT: clad::push(_cond0, i == 1); -//CHECK-NEXT: if (clad::back(_cond0)) -//CHECK-NEXT: goto _label0; -//CHECK-NEXT: } -//CHECK-NEXT: } -//CHECK-NEXT: _d_t += 1; -//CHECK-NEXT: for (; _t0; _t0--) { -//CHECK-NEXT: i--; -//CHECK-NEXT: { -//CHECK-NEXT: if (clad::back(_cond0)) -//CHECK-NEXT: _label0: -//CHECK-NEXT: _d_t += 1; -//CHECK-NEXT: clad::pop(_cond0); -//CHECK-NEXT: } -//CHECK-NEXT: { -//CHECK-NEXT: t = clad::pop(_t1); -//CHECK-NEXT: double _r_d0 = _d_t; -//CHECK-NEXT: _d_t -= _r_d0; -//CHECK-NEXT: _d_t += _r_d0 * x; -//CHECK-NEXT: *_d_x += t * _r_d0; -//CHECK-NEXT: } -//CHECK-NEXT: } -//CHECK-NEXT: } +// CHECK: void f3_grad(double x, double *_d_x) { +// CHECK-NEXT: double _d_t = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: clad::tape _cond0 = {}; +// CHECK-NEXT: double t = 1; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, t); +// CHECK-NEXT: t *= x; +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_cond0, i == 1); +// CHECK-NEXT: if (clad::back(_cond0)) +// CHECK-NEXT: goto _label0; +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: _d_t += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: i--; +// CHECK-NEXT: { +// CHECK-NEXT: if (clad::back(_cond0)) +// CHECK-NEXT: _label0: +// CHECK-NEXT: _d_t += 1; +// CHECK-NEXT: clad::pop(_cond0); +// CHECK-NEXT: } +// CHECK-NEXT: { +// CHECK-NEXT: t = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_t; +// CHECK-NEXT: _d_t -= _r_d0; +// CHECK-NEXT: _d_t += _r_d0 * x; +// CHECK-NEXT: *_d_x += t * _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } double f4(double x) { double t = 1; @@ -143,30 +175,38 @@ double f4(double x) { return t; } // == x^3 -//CHECK: void f4_grad(double x, double *_d_x) { -//CHECK-NEXT: double _d_t = 0; -//CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: clad::tape _t1 = {}; -//CHECK-NEXT: double t = 1; -//CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 3; clad::push(_t1, t) , (t *= x)) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: i++; -//CHECK-NEXT: } -//CHECK-NEXT: _d_t += 1; -//CHECK-NEXT: for (; _t0; _t0--) { -//CHECK-NEXT: { -//CHECK-NEXT: t = clad::pop(_t1); -//CHECK-NEXT: double _r_d0 = _d_t; -//CHECK-NEXT: _d_t -= _r_d0; -//CHECK-NEXT: _d_t += _r_d0 * x; -//CHECK-NEXT: *_d_x += t * _r_d0; -//CHECK-NEXT: } -//CHECK-NEXT: i--; -//CHECK-NEXT: } -//CHECK-NEXT: } +// CHECK: void f4_grad(double x, double *_d_x) { +// CHECK-NEXT: double _d_t = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: double t = 1; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (i = 0; ; clad::push(_t1, t) , (t *= x)) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: i++; +// CHECK-NEXT: } +// CHECK-NEXT: _d_t += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: { +// CHECK-NEXT: t = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_t; +// CHECK-NEXT: _d_t -= _r_d0; +// CHECK-NEXT: _d_t += _r_d0 * x; +// CHECK-NEXT: *_d_x += t * _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: i--; +// CHECK-NEXT: } +// CHECK-NEXT: } double f5(double x){ for (int i = 0; i < 10; i++) @@ -174,21 +214,29 @@ double f5(double x){ return x; } // == x + 10 -//CHECK: void f5_grad(double x, double *_d_x) { -//CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 10; i++) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: x++; -//CHECK-NEXT: } -//CHECK-NEXT: *_d_x += 1; -//CHECK-NEXT: for (; _t0; _t0--) { -//CHECK-NEXT: i--; -//CHECK-NEXT: x--; -//CHECK-NEXT: } -//CHECK-NEXT: } +// CHECK: void f5_grad(double x, double *_d_x) { +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 10)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: x++; +// CHECK-NEXT: } +// CHECK-NEXT: *_d_x += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: i--; +// CHECK-NEXT: x--; +// CHECK-NEXT: } +// CHECK-NEXT: } double f_const_local(double x) { double res = 0; @@ -199,40 +247,48 @@ double f_const_local(double x) { return res; } // == 3x^2 + 3x -//CHECK: void f_const_local_grad(double x, double *_d_x) { -//CHECK-NEXT: double _d_res = 0; -//CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: clad::tape _t1 = {}; -//CHECK-NEXT: double _d_n = 0; -//CHECK-NEXT: double n = 0; -//CHECK-NEXT: clad::tape _t2 = {}; -//CHECK-NEXT: double res = 0; -//CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < 3; ++i) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: clad::push(_t1, n) , n = x + i; -//CHECK-NEXT: clad::push(_t2, res); -//CHECK-NEXT: res += x * n; -//CHECK-NEXT: } -//CHECK-NEXT: _d_res += 1; -//CHECK-NEXT: for (; _t0; _t0--) { -//CHECK-NEXT: --i; -//CHECK-NEXT: { -//CHECK-NEXT: res = clad::pop(_t2); -//CHECK-NEXT: double _r_d0 = _d_res; -//CHECK-NEXT: *_d_x += _r_d0 * n; -//CHECK-NEXT: _d_n += x * _r_d0; -//CHECK-NEXT: } -//CHECK-NEXT: { -//CHECK-NEXT: *_d_x += _d_n; -//CHECK-NEXT: _d_i += _d_n; -//CHECK-NEXT: _d_n = 0; -//CHECK-NEXT: n = clad::pop(_t1); -//CHECK-NEXT: } -//CHECK-NEXT: } -//CHECK-NEXT:} +// CHECK: void f_const_local_grad(double x, double *_d_x) { +// CHECK-NEXT: double _d_res = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: double _d_n = 0; +// CHECK-NEXT: double n = 0; +// CHECK-NEXT: clad::tape _t2 = {}; +// CHECK-NEXT: double res = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, n) , n = x + i; +// CHECK-NEXT: clad::push(_t2, res); +// CHECK-NEXT: res += x * n; +// CHECK-NEXT: } +// CHECK-NEXT: _d_res += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: --i; +// CHECK-NEXT: { +// CHECK-NEXT: res = clad::pop(_t2); +// CHECK-NEXT: double _r_d0 = _d_res; +// CHECK-NEXT: *_d_x += _r_d0 * n; +// CHECK-NEXT: _d_n += x * _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: { +// CHECK-NEXT: *_d_x += _d_n; +// CHECK-NEXT: _d_i += _d_n; +// CHECK-NEXT: _d_n = 0; +// CHECK-NEXT: n = clad::pop(_t1); +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } double f_sum(double *p, int n) { double s = 0; @@ -241,28 +297,36 @@ double f_sum(double *p, int n) { return s; } -//CHECK: void f_sum_grad_0(double *p, int n, double *_d_p) { -//CHECK-NEXT: int _d_n = 0; -//CHECK-NEXT: double _d_s = 0; -//CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: clad::tape _t1 = {}; -//CHECK-NEXT: double s = 0; -//CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < n; i++) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: clad::push(_t1, s); -//CHECK-NEXT: s += p[i]; -//CHECK-NEXT: } -//CHECK-NEXT: _d_s += 1; -//CHECK-NEXT: for (; _t0; _t0--) { -//CHECK-NEXT: i--; -//CHECK-NEXT: s = clad::pop(_t1); -//CHECK-NEXT: double _r_d0 = _d_s; -//CHECK-NEXT: _d_p[i] += _r_d0; -//CHECK-NEXT: } -//CHECK-NEXT: } +// CHECK: void f_sum_grad_0(double *p, int n, double *_d_p) { +// CHECK-NEXT: int _d_n = 0; +// CHECK-NEXT: double _d_s = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: double s = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, s); +// CHECK-NEXT: s += p[i]; +// CHECK-NEXT: } +// CHECK-NEXT: _d_s += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: i--; +// CHECK-NEXT: s = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_s; +// CHECK-NEXT: _d_p[i] += _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: } double sq(double x) { return x * x; } //CHECK: void sq_pullback(double x, double _d_y, double *_d_x); @@ -274,30 +338,38 @@ double f_sum_squares(double *p, int n) { return s; } -//CHECK: void f_sum_squares_grad_0(double *p, int n, double *_d_p) { -//CHECK-NEXT: int _d_n = 0; -//CHECK-NEXT: double _d_s = 0; -//CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: clad::tape _t1 = {}; -//CHECK-NEXT: double s = 0; -//CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < n; i++) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: clad::push(_t1, s); -//CHECK-NEXT: s += sq(p[i]); -//CHECK-NEXT: } -//CHECK-NEXT: _d_s += 1; -//CHECK-NEXT: for (; _t0; _t0--) { -//CHECK-NEXT: i--; -//CHECK-NEXT: s = clad::pop(_t1); -//CHECK-NEXT: double _r_d0 = _d_s; -//CHECK-NEXT: double _r0 = 0; -//CHECK-NEXT: sq_pullback(p[i], _r_d0, &_r0); -//CHECK-NEXT: _d_p[i] += _r0; -//CHECK-NEXT: } -//CHECK-NEXT: } +// CHECK: void f_sum_squares_grad_0(double *p, int n, double *_d_p) { +// CHECK-NEXT: int _d_n = 0; +// CHECK-NEXT: double _d_s = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: double s = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, s); +// CHECK-NEXT: s += sq(p[i]); +// CHECK-NEXT: } +// CHECK-NEXT: _d_s += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: i--; +// CHECK-NEXT: s = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_s; +// CHECK-NEXT: double _r0 = 0; +// CHECK-NEXT: sq_pullback(p[i], _r_d0, &_r0); +// CHECK-NEXT: _d_p[i] += _r0; +// CHECK-NEXT: } +// CHECK-NEXT: } // log-likelihood of n-dimensional gaussian distribution with covariance sigma^2*I double f_log_gaus(double* x, double* p /*means*/, double n, double sigma) { @@ -308,73 +380,80 @@ double f_log_gaus(double* x, double* p /*means*/, double n, double sigma) { double gaus = 1./std::sqrt(std::pow(2*M_PI, n) * sigma) * std::exp(power); return std::log(gaus); } -//CHECK: void f_log_gaus_grad_1(double *x, double *p, double n, double sigma, double *_d_p) { -//CHECK-NEXT: double _d_n = 0; -//CHECK-NEXT: double _d_sigma = 0; -//CHECK-NEXT: double _d_power = 0; -//CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: clad::tape _t1 = {}; -//CHECK-NEXT: double _t2; -//CHECK-NEXT: double _t3; -//CHECK-NEXT: double _t4; -//CHECK-NEXT: double _t5; -//CHECK-NEXT: double _t6; -//CHECK-NEXT: double _t7; -//CHECK-NEXT: double _d_gaus = 0; -//CHECK-NEXT: double power = 0; -//CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < n; i++) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: clad::push(_t1, power); -//CHECK-NEXT: power += sq(x[i] - p[i]); -//CHECK-NEXT: } -//CHECK-NEXT: _t2 = power; -//CHECK-NEXT: _t4 = sq(sigma); -//CHECK-NEXT: _t3 = (2 * _t4); -//CHECK-NEXT: power = -power / _t3; -//CHECK-NEXT: _t7 = std::pow(2 * 3.1415926535897931, n); -//CHECK-NEXT: _t6 = std::sqrt(_t7 * sigma); -//CHECK-NEXT: _t5 = std::exp(power); -//CHECK-NEXT: double gaus = 1. / _t6 * _t5; -//CHECK-NEXT: { -//CHECK-NEXT: double _r8 = 0; -//CHECK-NEXT: _r8 += 1 * clad::custom_derivatives::log_pushforward(gaus, 1.).pushforward; -//CHECK-NEXT: _d_gaus += _r8; -//CHECK-NEXT: } -//CHECK-NEXT: { -//CHECK-NEXT: double _r3 = _d_gaus * _t5 * -(1. / (_t6 * _t6)); -//CHECK-NEXT: double _r4 = 0; -//CHECK-NEXT: _r4 += _r3 * clad::custom_derivatives::sqrt_pushforward(_t7 * sigma, 1.).pushforward; -//CHECK-NEXT: double _r5 = 0; -//CHECK-NEXT: double _r6 = 0; -//CHECK-NEXT: clad::custom_derivatives::pow_pullback(2 * 3.1415926535897931, n, _r4 * sigma, &_r5, &_r6); -//CHECK-NEXT: _d_n += _r6; -//CHECK-NEXT: _d_sigma += _t7 * _r4; -//CHECK-NEXT: double _r7 = 0; -//CHECK-NEXT: _r7 += 1. / _t6 * _d_gaus * clad::custom_derivatives::exp_pushforward(power, 1.).pushforward; -//CHECK-NEXT: _d_power += _r7; -//CHECK-NEXT: } -//CHECK-NEXT: { -//CHECK-NEXT: power = _t2; -//CHECK-NEXT: double _r_d1 = _d_power; -//CHECK-NEXT: _d_power -= _r_d1; -//CHECK-NEXT: _d_power += -_r_d1 / _t3; -//CHECK-NEXT: double _r1 = _r_d1 * -(-power / (_t3 * _t3)); -//CHECK-NEXT: double _r2 = 0; -//CHECK-NEXT: sq_pullback(sigma, 2 * _r1, &_r2); -//CHECK-NEXT: _d_sigma += _r2; -//CHECK-NEXT: } -//CHECK-NEXT: for (; _t0; _t0--) { -//CHECK-NEXT: i--; -//CHECK-NEXT: power = clad::pop(_t1); -//CHECK-NEXT: double _r_d0 = _d_power; -//CHECK-NEXT: double _r0 = 0; -//CHECK-NEXT: sq_pullback(x[i] - p[i], _r_d0, &_r0); -//CHECK-NEXT: _d_p[i] += -_r0; -//CHECK-NEXT: } -//CHECK-NEXT: } +// CHECK: void f_log_gaus_grad_1(double *x, double *p, double n, double sigma, double *_d_p) { +// CHECK-NEXT: double _d_n = 0; +// CHECK-NEXT: double _d_sigma = 0; +// CHECK-NEXT: double _d_power = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: double _t2; +// CHECK-NEXT: double _t3; +// CHECK-NEXT: double _t4; +// CHECK-NEXT: double _t5; +// CHECK-NEXT: double _t6; +// CHECK-NEXT: double _t7; +// CHECK-NEXT: double _d_gaus = 0; +// CHECK-NEXT: double power = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, power); +// CHECK-NEXT: power += sq(x[i] - p[i]); +// CHECK-NEXT: } +// CHECK-NEXT: _t2 = power; +// CHECK-NEXT: _t4 = sq(sigma); +// CHECK-NEXT: _t3 = (2 * _t4); +// CHECK-NEXT: power = -power / _t3; +// CHECK-NEXT: _t7 = std::pow(2 * 3.1415926535897931, n); +// CHECK-NEXT: _t6 = std::sqrt(_t7 * sigma); +// CHECK-NEXT: _t5 = std::exp(power); +// CHECK-NEXT: double gaus = 1. / _t6 * _t5; +// CHECK-NEXT: { +// CHECK-NEXT: double _r8 = 0; +// CHECK-NEXT: _r8 += 1 * clad::custom_derivatives::log_pushforward(gaus, 1.).pushforward; +// CHECK-NEXT: _d_gaus += _r8; +// CHECK-NEXT: } +// CHECK-NEXT: { +// CHECK-NEXT: double _r3 = _d_gaus * _t5 * -(1. / (_t6 * _t6)); +// CHECK-NEXT: double _r4 = 0; +// CHECK-NEXT: _r4 += _r3 * clad::custom_derivatives::sqrt_pushforward(_t7 * sigma, 1.).pushforward; +// CHECK-NEXT: double _r5 = 0; +// CHECK-NEXT: double _r6 = 0; +// CHECK-NEXT: clad::custom_derivatives::pow_pullback(2 * 3.1415926535897931, n, _r4 * sigma, &_r5, &_r6); +// CHECK-NEXT: _d_n += _r6; +// CHECK-NEXT: _d_sigma += _t7 * _r4; +// CHECK-NEXT: double _r7 = 0; +// CHECK-NEXT: _r7 += 1. / _t6 * _d_gaus * clad::custom_derivatives::exp_pushforward(power, 1.).pushforward; +// CHECK-NEXT: _d_power += _r7; +// CHECK-NEXT: } +// CHECK-NEXT: { +// CHECK-NEXT: power = _t2; +// CHECK-NEXT: double _r_d1 = _d_power; +// CHECK-NEXT: _d_power -= _r_d1; +// CHECK-NEXT: _d_power += -_r_d1 / _t3; +// CHECK-NEXT: double _r1 = _r_d1 * -(-power / (_t3 * _t3)); +// CHECK-NEXT: double _r2 = 0; +// CHECK-NEXT: sq_pullback(sigma, 2 * _r1, &_r2); +// CHECK-NEXT: _d_sigma += _r2; +// CHECK-NEXT: } +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: i--; +// CHECK-NEXT: power = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_power; +// CHECK-NEXT: double _r0 = 0; +// CHECK-NEXT: sq_pullback(x[i] - p[i], _r_d0, &_r0); +// CHECK-NEXT: _d_p[i] += -_r0; +// CHECK-NEXT: } double f_const(const double a, const double b) { int r = 0; @@ -386,39 +465,47 @@ double f_const(const double a, const double b) { } void f_const_grad(const double, const double, double*, double*); -//CHECK: void f_const_grad(const double a, const double b, double *_d_a, double *_d_b) { -//CHECK-NEXT: int _d_r = 0; -//CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: int i = 0; -//CHECK-NEXT: clad::tape _t1 = {}; -//CHECK-NEXT: int _d_sq = 0; -//CHECK-NEXT: int sq0 = 0; -//CHECK-NEXT: clad::tape _t2 = {}; -//CHECK-NEXT: int r = 0; -//CHECK-NEXT: _t0 = {{0U|0UL}}; -//CHECK-NEXT: for (i = 0; i < a; i++) { -//CHECK-NEXT: _t0++; -//CHECK-NEXT: clad::push(_t1, sq0) , sq0 = b * b; -//CHECK-NEXT: clad::push(_t2, r); -//CHECK-NEXT: r += sq0; -//CHECK-NEXT: } -//CHECK-NEXT: _d_r += 1; -//CHECK-NEXT: for (; _t0; _t0--) { -//CHECK-NEXT: i--; -//CHECK-NEXT: { -//CHECK-NEXT: r = clad::pop(_t2); -//CHECK-NEXT: int _r_d0 = _d_r; -//CHECK-NEXT: _d_sq += _r_d0; -//CHECK-NEXT: } -//CHECK-NEXT: { -//CHECK-NEXT: *_d_b += _d_sq * b; -//CHECK-NEXT: *_d_b += b * _d_sq; -//CHECK-NEXT: _d_sq = 0; -//CHECK-NEXT: sq0 = clad::pop(_t1); -//CHECK-NEXT: } -//CHECK-NEXT: } -//CHECK-NEXT: } +// CHECK: void f_const_grad(const double a, const double b, double *_d_a, double *_d_b) { +// CHECK-NEXT: int _d_r = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_i = 0; +// CHECK-NEXT: int i = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: int _d_sq = 0; +// CHECK-NEXT: int sq0 = 0; +// CHECK-NEXT: clad::tape _t2 = {}; +// CHECK-NEXT: int r = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < a)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, sq0) , sq0 = b * b; +// CHECK-NEXT: clad::push(_t2, r); +// CHECK-NEXT: r += sq0; +// CHECK-NEXT: } +// CHECK-NEXT: _d_r += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: i--; +// CHECK-NEXT: { +// CHECK-NEXT: r = clad::pop(_t2); +// CHECK-NEXT: int _r_d0 = _d_r; +// CHECK-NEXT: _d_sq += _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: { +// CHECK-NEXT: *_d_b += _d_sq * b; +// CHECK-NEXT: *_d_b += b * _d_sq; +// CHECK-NEXT: _d_sq = 0; +// CHECK-NEXT: sq0 = clad::pop(_t1); +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } double f6 (double i, double j) { double a = 0; @@ -446,7 +533,11 @@ double f6 (double i, double j) { // CHECK-NEXT: clad::tape _t4 = {}; // CHECK-NEXT: double a = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (counter = 0; counter < 3; ++counter) { +// CHECK-NEXT: for (counter = 0; ; ++counter) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(counter < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, b) , b = i * i; // CHECK-NEXT: clad::push(_t2, c) , c = j * j; @@ -456,7 +547,11 @@ double f6 (double i, double j) { // CHECK-NEXT: a += b + c + i; // CHECK-NEXT: } // CHECK-NEXT: _d_a += 1; -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --counter; // CHECK-NEXT: { // CHECK-NEXT: a = clad::pop(_t4); @@ -887,7 +982,11 @@ double fn13(double i, double j) { // CHECK-NEXT: double res = 0; // CHECK-NEXT: int counter = 3; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (; clad::push(_t1, k) , k = counter; clad::push(_t2, counter) , (counter -= 1)) { +// CHECK-NEXT: for (;; clad::push(_t2, counter) , (counter -= 1)) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(clad::push(_t1, k) , k = counter)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t3, k); // CHECK-NEXT: k += i + 2 * j; @@ -896,7 +995,11 @@ double fn13(double i, double j) { // CHECK-NEXT: res += temp; // CHECK-NEXT: } // CHECK-NEXT: _d_res += 1; -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: { // CHECK-NEXT: { // CHECK-NEXT: counter = clad::pop(_t2); @@ -1022,7 +1125,7 @@ double fn14(double i, double j) { // CHECK-NEXT: { // CHECK-NEXT: if (clad::back(_cond1)) { // CHECK-NEXT: case {{2U|2UL}}: -// CHECK-NEXT: ; +// CHECK-NEXT: ; // CHECK-NEXT: { // CHECK-NEXT: res = clad::pop(_t3); // CHECK-NEXT: double _r_d1 = _d_res; @@ -1209,7 +1312,11 @@ double fn16(double i, double j) { // CHECK-NEXT: int counter = 5; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (ii = 0; ii < counter; ++ii) { +// CHECK-NEXT: for (ii = 0; ; ++ii) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(ii < counter)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: { // CHECK-NEXT: clad::push(_cond0, ii == 4); @@ -1238,7 +1345,11 @@ double fn16(double i, double j) { // CHECK-NEXT: clad::push(_t2, {{3U|3UL}}); // CHECK-NEXT: } // CHECK-NEXT: _d_res += 1; -// CHECK-NEXT: for (; _t0; _t0--) +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: switch (clad::pop(_t2)) { // CHECK-NEXT: case {{3U|3UL}}: // CHECK-NEXT: ; @@ -1275,6 +1386,7 @@ double fn16(double i, double j) { // CHECK-NEXT: clad::pop(_cond0); // CHECK-NEXT: } // CHECK-NEXT: } +// CHECK-NEXT: } // CHECK-NEXT: } double fn17(double i, double j) { @@ -1316,7 +1428,11 @@ double fn17(double i, double j) { // CHECK-NEXT: int counter = 5; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (ii = 0; ii < counter; ++ii) { +// CHECK-NEXT: for (ii = 0; ; ++ii) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(ii < counter)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, jj) , jj = ii; // CHECK-NEXT: { @@ -1353,7 +1469,11 @@ double fn17(double i, double j) { // CHECK-NEXT: clad::push(_t2, {{2U|2UL}}); // CHECK-NEXT: } // CHECK-NEXT: _d_res += 1; -// CHECK-NEXT: for (; _t0; _t0--) +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: switch (clad::pop(_t2)) { // CHECK-NEXT: case {{2U|2UL}}: // CHECK-NEXT: ; @@ -1377,7 +1497,7 @@ double fn17(double i, double j) { // CHECK-NEXT: case {{1U|1UL}}: // CHECK-NEXT: ; // CHECK-NEXT: { -// CHECK-NEXT: res = clad::pop(_t4); +// CHECK-NEXT: res = clad::pop(_t4); // CHECK-NEXT: double _r_d0 = _d_res; // CHECK-NEXT: *_d_i += _r_d0 * j; // CHECK-NEXT: *_d_j += i * _r_d0; @@ -1405,6 +1525,7 @@ double fn17(double i, double j) { // CHECK-NEXT: jj = clad::pop(_t1); // CHECK-NEXT: } // CHECK-NEXT: } +// CHECK-NEXT: } // CHECK-NEXT: } double fn18(double i, double j) { @@ -1436,7 +1557,11 @@ double fn18(double i, double j) { // CHECK-NEXT: int choice = 5; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (counter = 0; counter < choice; ++counter) { +// CHECK-NEXT: for (counter = 0; ; ++counter) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(counter < choice)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: { // CHECK-NEXT: clad::push(_cond0, counter < 2); @@ -1444,24 +1569,28 @@ double fn18(double i, double j) { // CHECK-NEXT: clad::push(_t1, res); // CHECK-NEXT: res += i + j; // CHECK-NEXT: } else { -// CHECK-NEXT: clad::push(_cond1, counter < 4); -// CHECK-NEXT: if (clad::back(_cond1)) { -// CHECK-NEXT: clad::push(_t2, {{1U|1UL}}); -// CHECK-NEXT: continue; -// CHECK-NEXT: } else { -// CHECK-NEXT: clad::push(_t3, res); -// CHECK-NEXT: res += 2 * i + 2 * j; -// CHECK-NEXT: { -// CHECK-NEXT: clad::push(_t2, {{2U|2UL}}); -// CHECK-NEXT: break; -// CHECK-NEXT: } +// CHECK-NEXT: clad::push(_cond1, counter < 4); +// CHECK-NEXT: if (clad::back(_cond1)) { +// CHECK-NEXT: clad::push(_t2, {{1U|1UL}}); +// CHECK-NEXT: continue; +// CHECK-NEXT: } else { +// CHECK-NEXT: clad::push(_t3, res); +// CHECK-NEXT: res += 2 * i + 2 * j; +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_t2, {{2U|2UL}}); +// CHECK-NEXT: break; // CHECK-NEXT: } +// CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: clad::push(_t2, {{3U|3UL}}); // CHECK-NEXT: } // CHECK-NEXT: _d_res += 1; -// CHECK-NEXT: for (; _t0; _t0--) +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: switch (clad::pop(_t2)) { // CHECK-NEXT: case {{3U|3UL}}: // CHECK-NEXT: ; @@ -1489,6 +1618,7 @@ double fn18(double i, double j) { // CHECK-NEXT: } // CHECK-NEXT: clad::pop(_cond0); // CHECK-NEXT: } +// CHECK-NEXT: } // CHECK-NEXT: } double fn19(double* arr, int n) { @@ -1513,7 +1643,11 @@ double fn19(double* arr, int n) { // CHECK-NEXT: clad::tape _t3 = {}; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < n; ++i) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: _d_ref = &_d_arr[i]; // CHECK-NEXT: clad::push(_t1, _d_ref); @@ -1522,7 +1656,11 @@ double fn19(double* arr, int n) { // CHECK-NEXT: res += *ref; // CHECK-NEXT: } // CHECK-NEXT: _d_res += 1; -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --i; // CHECK-NEXT: _d_ref = clad::pop(_t1); // CHECK-NEXT: { @@ -1557,14 +1695,22 @@ double f_loop_init_var(double lower, double upper) { // CHECK-NEXT: double num_points = 10000; // CHECK-NEXT: double interval = (upper - lower) / num_points; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (x = lower; x <= upper; clad::push(_t1, x) , (x += interval)) { +// CHECK-NEXT: for (x = lower; ; clad::push(_t1, x) , (x += interval)) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(x <= upper)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t2, sum); // CHECK-NEXT: sum += x * x * interval; // CHECK-NEXT: } // CHECK-NEXT: _d_sum += 1; // CHECK-NEXT: { -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: { // CHECK-NEXT: x = clad::pop(_t1); // CHECK-NEXT: double _r_d0 = _d_x; @@ -1587,7 +1733,6 @@ double f_loop_init_var(double lower, double upper) { // CHECK-NEXT: _d_num_points += _r0; // CHECK-NEXT: } // CHECK-NEXT: } - double fn20(double *arr, int n) { double res = 0; for (int i=0; i _t2 = {}; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < n; ++i) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, res); // CHECK-NEXT: clad::push(_t2, arr[i]); // CHECK-NEXT: res += (arr[i] *= 5); // CHECK-NEXT: } // CHECK-NEXT: _d_res += 1; -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --i; // CHECK-NEXT: { // CHECK-NEXT: res = clad::pop(_t1); @@ -1648,14 +1801,22 @@ double fn21(double x) { // CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < 5; ++i) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 5)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, arr) , arr = {1, x, 2}; // CHECK-NEXT: clad::push(_t2, res); // CHECK-NEXT: res += arr[0] + arr[1]; // CHECK-NEXT: } // CHECK-NEXT: _d_res += 1; -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --i; // CHECK-NEXT: { // CHECK-NEXT: res = clad::pop(_t2); @@ -1692,31 +1853,885 @@ double fn22(double param) { // CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: clad::tape _t3 = {}; // CHECK-NEXT: double out = 0.; -// CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < 1; i++) { -// CHECK-NEXT: _t0++; -// CHECK-NEXT: clad::push(_t1, arr) , arr = {1.}; -// CHECK-NEXT: clad::push(_t2, out); -// CHECK-NEXT: clad::push(_t3, arr[0]); -// CHECK-NEXT: out += clad::back(_t3) * param; -// CHECK-NEXT: } -// CHECK-NEXT: _d_out += 1; -// CHECK-NEXT: for (; _t0; _t0--) { -// CHECK-NEXT: i--; -// CHECK-NEXT: { -// CHECK-NEXT: out = clad::pop(_t2); -// CHECK-NEXT: double _r_d0 = _d_out; -// CHECK-NEXT: _d_arr[0] += _r_d0 * param; -// CHECK-NEXT: *_d_param += clad::back(_t3) * _r_d0; -// CHECK-NEXT: clad::pop(_t3); -// CHECK-NEXT: } -// CHECK-NEXT: { -// CHECK-NEXT: clad::zero_init(_d_arr); -// CHECK-NEXT: arr = clad::pop(_t1); -// CHECK-NEXT: } -// CHECK-NEXT: } +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (i = 0; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 1)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t1, arr) , arr = {1.}; +// CHECK-NEXT: clad::push(_t2, out); +// CHECK-NEXT: clad::push(_t3, arr[0]); +// CHECK-NEXT: out += clad::back(_t3) * param; +// CHECK-NEXT: } +// CHECK-NEXT: _d_out += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: i--; +// CHECK-NEXT: { +// CHECK-NEXT: out = clad::pop(_t2); +// CHECK-NEXT: double _r_d0 = _d_out; +// CHECK-NEXT: _d_arr[0] += _r_d0 * param; +// CHECK-NEXT: *_d_param += clad::back(_t3) * _r_d0; +// CHECK-NEXT: clad::pop(_t3); +// CHECK-NEXT: } +// CHECK-NEXT: { +// CHECK-NEXT: clad::zero_init(_d_arr); +// CHECK-NEXT: arr = clad::pop(_t1); +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } + +double fn23(double i, double j) { + double res = 0; + for (int c = 0; (res = i * j); ++c) { + if (c == 1) + break; + } + return res; +} + +// CHECK: void fn23_grad(double i, double j, double *_d_i, double *_d_j) { +// CHECK-NEXT: double _d_res = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_c = 0; +// CHECK-NEXT: int c = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: clad::tape _cond0 = {}; +// CHECK-NEXT: clad::tape _t2 = {}; +// CHECK-NEXT: double res = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (c = 0; ; ++c) { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_t1, res); +// CHECK-NEXT: } +// CHECK-NEXT: if (!(res = i * j)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_cond0, c == 1); +// CHECK-NEXT: if (clad::back(_cond0)) { +// CHECK-NEXT: clad::push(_t2, {{1U|1UL}}); +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: clad::push(_t2, {{2U|2UL}}); +// CHECK-NEXT: } +// CHECK-NEXT: _d_res += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0 || (clad::back(_t2) != 1)) { +// CHECK-NEXT: res = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_res; +// CHECK-NEXT: _d_res -= _r_d0; +// CHECK-NEXT: *_d_i += _r_d0 * j; +// CHECK-NEXT: *_d_j += i * _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: switch (clad::pop(_t2)) { +// CHECK-NEXT: case {{2U|2UL}}: +// CHECK-NEXT: ; +// CHECK-NEXT: --c; +// CHECK-NEXT: { +// CHECK-NEXT: if (clad::back(_cond0)) +// CHECK-NEXT: case {{1U|1UL}}: +// CHECK-NEXT: ; +// CHECK-NEXT: clad::pop(_cond0); +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } + +double fn24(double i, double j) { + double res = 0; + for (int c = 0; (res += i * j), c<3; ++c) { + } + return res; +} + +// CHECK: void fn24_grad(double i, double j, double *_d_i, double *_d_j) { +// CHECK-NEXT: double _d_res = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_c = 0; +// CHECK-NEXT: int c = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: double res = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (c = 0; ; ++c) { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_t1, res); +// CHECK-NEXT: } +// CHECK-NEXT: if (!((res += i * j) , c < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: } +// CHECK-NEXT: _d_res += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: _d_res += 0; +// CHECK-NEXT: res = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_res; +// CHECK-NEXT: *_d_i += _r_d0 * j; +// CHECK-NEXT: *_d_j += i * _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: --c; +// CHECK-NEXT: } +// CHECK-NEXT: } + +double fn25(double i, double j) { + double res = 0; + for (int c = 0; (res += i * j), c<3; ++c) { + if (c == 1) { + res = 8 * i * j; + break; + } + } + return res; +} + +// CHECK: void fn25_grad(double i, double j, double *_d_i, double *_d_j) { +// CHECK-NEXT: double _d_res = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_c = 0; +// CHECK-NEXT: int c = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: clad::tape _cond0 = {}; +// CHECK-NEXT: clad::tape _t2 = {}; +// CHECK-NEXT: clad::tape _t3 = {}; +// CHECK-NEXT: double res = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (c = 0; ; ++c) { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_t1, res); +// CHECK-NEXT: } +// CHECK-NEXT: if (!((res += i * j) , c < 3)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_cond0, c == 1); +// CHECK-NEXT: if (clad::back(_cond0)) { +// CHECK-NEXT: clad::push(_t2, res); +// CHECK-NEXT: res = 8 * i * j; +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_t3, {{1U|1UL}}); +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: clad::push(_t3, {{2U|2UL}}); +// CHECK-NEXT: } +// CHECK-NEXT: _d_res += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0 || (clad::back(_t3) != 1)) { +// CHECK-NEXT: _d_res += 0; +// CHECK-NEXT: res = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_res; +// CHECK-NEXT: *_d_i += _r_d0 * j; +// CHECK-NEXT: *_d_j += i * _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: switch (clad::pop(_t3)) { +// CHECK-NEXT: case {{2U|2UL}}: +// CHECK-NEXT: ; +// CHECK-NEXT: --c; +// CHECK-NEXT: { +// CHECK-NEXT: if (clad::back(_cond0)) { +// CHECK-NEXT: case {{1U|1UL}}: +// CHECK-NEXT: ; +// CHECK-NEXT: { +// CHECK-NEXT: res = clad::pop(_t2); +// CHECK-NEXT: double _r_d1 = _d_res; +// CHECK-NEXT: _d_res -= _r_d1; +// CHECK-NEXT: *_d_i += 8 * _r_d1 * j; +// CHECK-NEXT: *_d_j += 8 * i * _r_d1; +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: clad::pop(_cond0); +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } + +double fn26(double i, double j) { + double res = 0; + for (int c = 0; (res += i * j); ++c, res=7*i*j) { + if(c == 0) + break; + } + return res; +} + +// CHECK: void fn26_grad(double i, double j, double *_d_i, double *_d_j) { +// CHECK-NEXT: double _d_res = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_c = 0; +// CHECK-NEXT: int c = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: clad::tape _t2 = {}; +// CHECK-NEXT: clad::tape _cond0 = {}; +// CHECK-NEXT: clad::tape _t3 = {}; +// CHECK-NEXT: double res = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (c = 0; ; clad::push(_t2, res) , (++c , res = 7 * i * j)) { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_t1, res); +// CHECK-NEXT: } +// CHECK-NEXT: if (!(res += i * j)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_cond0, c == 0); +// CHECK-NEXT: if (clad::back(_cond0)) { +// CHECK-NEXT: clad::push(_t3, {{1U|1UL}}); +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: clad::push(_t3, {{2U|2UL}}); +// CHECK-NEXT: } +// CHECK-NEXT: _d_res += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0 || (clad::back(_t3) != 1)) { +// CHECK-NEXT: res = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_res; +// CHECK-NEXT: *_d_i += _r_d0 * j; +// CHECK-NEXT: *_d_j += i * _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: switch (clad::pop(_t3)) { +// CHECK-NEXT: case {{2U|2UL}}: +// CHECK-NEXT: ; +// CHECK-NEXT: { +// CHECK-NEXT: res = clad::pop(_t2); +// CHECK-NEXT: double _r_d1 = _d_res; +// CHECK-NEXT: _d_res -= _r_d1; +// CHECK-NEXT: *_d_i += 7 * _r_d1 * j; +// CHECK-NEXT: *_d_j += 7 * i * _r_d1; +// CHECK-NEXT: _d_c += 0; +// CHECK-NEXT: --c; +// CHECK-NEXT: } +// CHECK-NEXT: { +// CHECK-NEXT: if (clad::back(_cond0)) +// CHECK-NEXT: case {{1U|1UL}}: +// CHECK-NEXT: ; +// CHECK-NEXT: clad::pop(_cond0); +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } + +double fn27(double i, double j) { + double res = 0; + for (int c = 0; (res += i * j); ++c) { + if(c == 2) + break; + + res = c * i * j; + } + return res; +} + +// CHECK: void fn27_grad(double i, double j, double *_d_i, double *_d_j) { +// CHECK-NEXT: double _d_res = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_c = 0; +// CHECK-NEXT: int c = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: clad::tape _cond0 = {}; +// CHECK-NEXT: clad::tape _t2 = {}; +// CHECK-NEXT: clad::tape _t3 = {}; +// CHECK-NEXT: double res = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (c = 0; ; ++c) { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_t1, res); +// CHECK-NEXT: } +// CHECK-NEXT: if (!(res += i * j)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_cond0, c == 2); +// CHECK-NEXT: if (clad::back(_cond0)) { +// CHECK-NEXT: clad::push(_t2, {{1U|1UL}}); +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: clad::push(_t3, res); +// CHECK-NEXT: res = c * i * j; +// CHECK-NEXT: clad::push(_t2, {{2U|2UL}}); +// CHECK-NEXT: } +// CHECK-NEXT: _d_res += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0 || (clad::back(_t2) != 1)) { +// CHECK-NEXT: res = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_res; +// CHECK-NEXT: *_d_i += _r_d0 * j; +// CHECK-NEXT: *_d_j += i * _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: switch (clad::pop(_t2)) { +// CHECK-NEXT: case {{2U|2UL}}: +// CHECK-NEXT: ; +// CHECK-NEXT: --c; +// CHECK-NEXT: { +// CHECK-NEXT: res = clad::pop(_t3); +// CHECK-NEXT: double _r_d1 = _d_res; +// CHECK-NEXT: _d_res -= _r_d1; +// CHECK-NEXT: _d_c += _r_d1 * j * i; +// CHECK-NEXT: *_d_i += c * _r_d1 * j; +// CHECK-NEXT: *_d_j += c * i * _r_d1; +// CHECK-NEXT: } +// CHECK-NEXT: { +// CHECK-NEXT: if (clad::back(_cond0)) +// CHECK-NEXT: case {{1U|1UL}}: +// CHECK-NEXT: ; +// CHECK-NEXT: clad::pop(_cond0); +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } + +double fn28(double i, double j) { + double res = 0; + for (int c = 0; (res = i * j), c < 2; ++c) { + res = 3 * i * j; + } + return res; +} + +// CHECK: void fn28_grad(double i, double j, double *_d_i, double *_d_j) { +// CHECK-NEXT: double _d_res = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_c = 0; +// CHECK-NEXT: int c = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: clad::tape _t2 = {}; +// CHECK-NEXT: double res = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (c = 0; ; ++c) { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_t1, res); +// CHECK-NEXT: } +// CHECK-NEXT: if (!((res = i * j) , c < 2)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: clad::push(_t2, res); +// CHECK-NEXT: res = 3 * i * j; +// CHECK-NEXT: } +// CHECK-NEXT: _d_res += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: _d_res += 0; +// CHECK-NEXT: res = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_res; +// CHECK-NEXT: _d_res -= _r_d0; +// CHECK-NEXT: *_d_i += _r_d0 * j; +// CHECK-NEXT: *_d_j += i * _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: --c; +// CHECK-NEXT: { +// CHECK-NEXT: res = clad::pop(_t2); +// CHECK-NEXT: double _r_d1 = _d_res; +// CHECK-NEXT: _d_res -= _r_d1; +// CHECK-NEXT: *_d_i += 3 * _r_d1 * j; +// CHECK-NEXT: *_d_j += 3 * i * _r_d1; +// CHECK-NEXT: } +// CHECK-NEXT: } // CHECK-NEXT: } +double fn29(double i, double j) { + double res = 0; + for (int c = 0; res = i * j, c<1; ++c, res=3*i*j) {} + return res; +} + +// CHECK: void fn29_grad(double i, double j, double *_d_i, double *_d_j) { +// CHECK-NEXT: double _d_res = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_c = 0; +// CHECK-NEXT: int c = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: clad::tape _t2 = {}; +// CHECK-NEXT: double res = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (c = 0; ; clad::push(_t2, res) , (++c , res = 3 * i * j)) { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_t1, res); +// CHECK-NEXT: } +// CHECK-NEXT: if (!(res = i * j , c < 1)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: } +// CHECK-NEXT: _d_res += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: _d_res += 0; +// CHECK-NEXT: res = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_res; +// CHECK-NEXT: _d_res -= _r_d0; +// CHECK-NEXT: *_d_i += _r_d0 * j; +// CHECK-NEXT: *_d_j += i * _r_d0; +// CHECK-NEXT: } +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: { +// CHECK-NEXT: res = clad::pop(_t2); +// CHECK-NEXT: double _r_d1 = _d_res; +// CHECK-NEXT: _d_res -= _r_d1; +// CHECK-NEXT: *_d_i += 3 * _r_d1 * j; +// CHECK-NEXT: *_d_j += 3 * i * _r_d1; +// CHECK-NEXT: _d_c += 0; +// CHECK-NEXT: --c; +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } + +double fn30(double i, double j) { + double res = 0; + for (int c = 0; (c==0) && (res=i*j); ++c) {} + return res; +} + +// CHECK: void fn30_grad(double i, double j, double *_d_i, double *_d_j) { +// CHECK-NEXT: double _d_res = 0; +// CHECK-NEXT: unsigned {{int|long}} _t0; +// CHECK-NEXT: int _d_c = 0; +// CHECK-NEXT: int c = 0; +// CHECK-NEXT: bool _cond0; +// CHECK-NEXT: double _d_cond0; +// CHECK-NEXT: _d_cond0 = 0.; +// CHECK-NEXT: clad::tape _cond1 = {}; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: clad::tape _t2 = {}; +// CHECK-NEXT: double res = 0; +// CHECK-NEXT: _t0 = {{0U|0UL}}; +// CHECK-NEXT: for (c = 0; ; ++c) { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: clad::push(_cond1, (c == 0)); +// CHECK-NEXT: if (clad::back(_cond1)) { +// CHECK-NEXT: clad::push(_t1, _cond0); +// CHECK-NEXT: clad::push(_t2, res); +// CHECK-NEXT: _cond0 = (res = i * j); +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: } +// CHECK-NEXT: if (!(clad::back(_cond1) && _cond0)) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: _t0++; +// CHECK-NEXT: } +// CHECK-NEXT: _d_res += 1; +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: { +// CHECK-NEXT: if (clad::back(_cond1)) { +// CHECK-NEXT: _cond0 = clad::pop(_t1); +// CHECK-NEXT: double _r_d0 = _d_cond0; +// CHECK-NEXT: _d_cond0 -= _r_d0; +// CHECK-NEXT: _d_res += _r_d0; +// CHECK-NEXT: res = clad::pop(_t2); +// CHECK-NEXT: double _r_d1 = _d_res; +// CHECK-NEXT: _d_res -= _r_d1; +// CHECK-NEXT: *_d_i += _r_d1 * j; +// CHECK-NEXT: *_d_j += i * _r_d1; +// CHECK-NEXT: } +// CHECK-NEXT: clad::pop(_cond1); +// CHECK-NEXT: } +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } +// CHECK-NEXT: --c; +// CHECK-NEXT: } +// CHECK-NEXT: } + +double fn31(double i, double j) { + double res = 0; + for (int c = 0; (res = i * j), (res=2*i*j), c < 3; ++c) {} + return res; +} + +//CHECK:void fn31_grad(double i, double j, double *_d_i, double *_d_j) { +//CHECK-NEXT: double _d_res = 0; +//CHECK-NEXT: unsigned {{int|long}} _t0; +//CHECK-NEXT: int _d_c = 0; +//CHECK-NEXT: int c = 0; +//CHECK-NEXT: clad::tape _t1 = {}; +//CHECK-NEXT: clad::tape _t2 = {}; +//CHECK-NEXT: double res = 0; +//CHECK-NEXT: _t0 = {{0U|0UL}}; +//CHECK-NEXT: for (c = 0; ; ++c) { +//CHECK-NEXT: { +//CHECK-NEXT: { +//CHECK-NEXT: clad::push(_t1, res); +//CHECK-NEXT: clad::push(_t2, res); +//CHECK-NEXT: } +//CHECK-NEXT: if (!((res = i * j) , (res = 2 * i * j) , c < 3)) +//CHECK-NEXT: break; +//CHECK-NEXT: } +//CHECK-NEXT: _t0++; +//CHECK-NEXT: } +//CHECK-NEXT: _d_res += 1; +//CHECK-NEXT: for (;; _t0--) { +//CHECK-NEXT: { +//CHECK-NEXT: { +//CHECK-NEXT: _d_res += 0; +//CHECK-NEXT: res = clad::pop(_t1); +//CHECK-NEXT: double _r_d0 = _d_res; +//CHECK-NEXT: _d_res -= _r_d0; +//CHECK-NEXT: *_d_i += 2 * _r_d0 * j; +//CHECK-NEXT: *_d_j += 2 * i * _r_d0; +//CHECK-NEXT: _d_res += 0; +//CHECK-NEXT: res = clad::pop(_t2); +//CHECK-NEXT: double _r_d1 = _d_res; +//CHECK-NEXT: _d_res -= _r_d1; +//CHECK-NEXT: *_d_i += _r_d1 * j; +//CHECK-NEXT: *_d_j += i * _r_d1; +//CHECK-NEXT: } +//CHECK-NEXT: if (!_t0) +//CHECK-NEXT: break; +//CHECK-NEXT: } +//CHECK-NEXT: --c; +//CHECK-NEXT: } +//CHECK-NEXT:} + +double fn32(double i, double j) { + double res = 0; + for (int c = 0; (res += i * j); ++c) { + for (int d = 0; (res += i* j); ++d) { + if (d == 1) { + res += i*j; + break; + } + } + if (c == 1) { + res += i * j; + break; + } + } + return res; +} + +//CHECK:void fn32_grad(double i, double j, double *_d_i, double *_d_j) { +//CHECK-NEXT: double _d_res = 0; +//CHECK-NEXT: unsigned {{int|long}} _t0; +//CHECK-NEXT: int _d_c = 0; +//CHECK-NEXT: int c = 0; +//CHECK-NEXT: clad::tape _t1 = {}; +//CHECK-NEXT: clad::tape _t2 = {}; +//CHECK-NEXT: clad::tape _t3 = {}; +//CHECK-NEXT: int _d_d = 0; +//CHECK-NEXT: int d = 0; +//CHECK-NEXT: clad::tape _t4 = {}; +//CHECK-NEXT: clad::tape _cond0 = {}; +//CHECK-NEXT: clad::tape _t5 = {}; +//CHECK-NEXT: clad::tape _t6 = {}; +//CHECK-NEXT: clad::tape _cond1 = {}; +//CHECK-NEXT: clad::tape _t7 = {}; +//CHECK-NEXT: clad::tape _t8 = {}; +//CHECK-NEXT: double res = 0; +//CHECK-NEXT: _t0 = {{0U|0UL}}; +//CHECK-NEXT: for (c = 0; ; ++c) { +//CHECK-NEXT: { +//CHECK-NEXT: { +//CHECK-NEXT: clad::push(_t1, res); +//CHECK-NEXT: } +//CHECK-NEXT: if (!(res += i * j)) +//CHECK-NEXT: break; +//CHECK-NEXT: } +//CHECK-NEXT: _t0++; +//CHECK-NEXT: clad::push(_t2, {{0U|0UL}}); +//CHECK-NEXT: for (clad::push(_t3, d) , d = 0; ; ++d) { +//CHECK-NEXT: { +//CHECK-NEXT: { +//CHECK-NEXT: clad::push(_t4, res); +//CHECK-NEXT: } +//CHECK-NEXT: if (!(res += i * j)) +//CHECK-NEXT: break; +//CHECK-NEXT: } +//CHECK-NEXT: clad::back(_t2)++; +//CHECK-NEXT: { +//CHECK-NEXT: clad::push(_cond0, d == 1); +//CHECK-NEXT: if (clad::back(_cond0)) { +//CHECK-NEXT: clad::push(_t5, res); +//CHECK-NEXT: res += i * j; +//CHECK-NEXT: { +//CHECK-NEXT: clad::push(_t6, {{1U|1UL}}); +//CHECK-NEXT: break; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: clad::push(_t6, {{2U|2UL}}); +//CHECK-NEXT: } +//CHECK-NEXT: { +//CHECK-NEXT: clad::push(_cond1, c == 1); +//CHECK-NEXT: if (clad::back(_cond1)) { +//CHECK-NEXT: clad::push(_t7, res); +//CHECK-NEXT: res += i * j; +//CHECK-NEXT: { +//CHECK-NEXT: clad::push(_t8, {{1U|1UL}}); +//CHECK-NEXT: break; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: clad::push(_t8, {{2U|2UL}}); +//CHECK-NEXT: } +//CHECK-NEXT: _d_res += 1; +//CHECK-NEXT: for (;; _t0--) { +//CHECK-NEXT: { +//CHECK-NEXT: if (!_t0 || (clad::back(_t8) != 1)) { +//CHECK-NEXT: res = clad::pop(_t1); +//CHECK-NEXT: double _r_d0 = _d_res; +//CHECK-NEXT: *_d_i += _r_d0 * j; +//CHECK-NEXT: *_d_j += i * _r_d0; +//CHECK-NEXT: } +//CHECK-NEXT: if (!_t0) +//CHECK-NEXT: break; +//CHECK-NEXT: } +//CHECK-NEXT: switch (clad::pop(_t8)) { +//CHECK-NEXT: case {{2U|2UL}}: +//CHECK-NEXT: ; +//CHECK-NEXT: --c; +//CHECK-NEXT: { +//CHECK-NEXT: if (clad::back(_cond1)) { +//CHECK-NEXT: case {{1U|1UL}}: +//CHECK-NEXT: ; +//CHECK-NEXT: { +//CHECK-NEXT: res = clad::pop(_t7); +//CHECK-NEXT: double _r_d3 = _d_res; +//CHECK-NEXT: *_d_i += _r_d3 * j; +//CHECK-NEXT: *_d_j += i * _r_d3; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: clad::pop(_cond1); +//CHECK-NEXT: } +//CHECK-NEXT: { +//CHECK-NEXT: for (;; clad::back(_t2)--) { +//CHECK-NEXT: { +//CHECK-NEXT: if (!clad::back(_t2) || (clad::back(_t6) != 1)) { +//CHECK-NEXT: res = clad::pop(_t4); +//CHECK-NEXT: double _r_d1 = _d_res; +//CHECK-NEXT: *_d_i += _r_d1 * j; +//CHECK-NEXT: *_d_j += i * _r_d1; +//CHECK-NEXT: } +//CHECK-NEXT: if (!clad::back(_t2)) +//CHECK-NEXT: break; +//CHECK-NEXT: } +//CHECK-NEXT: switch (clad::pop(_t6)) { +//CHECK-NEXT: case {{2U|2UL}}: +//CHECK-NEXT: ; +//CHECK-NEXT: --d; +//CHECK-NEXT: { +//CHECK-NEXT: if (clad::back(_cond0)) { +//CHECK-NEXT: case {{1U|1UL}}: +//CHECK-NEXT: ; +//CHECK-NEXT: { +//CHECK-NEXT: res = clad::pop(_t5); +//CHECK-NEXT: double _r_d2 = _d_res; +//CHECK-NEXT: *_d_i += _r_d2 * j; +//CHECK-NEXT: *_d_j += i * _r_d2; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: clad::pop(_cond0); +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: { +//CHECK-NEXT: _d_d = 0; +//CHECK-NEXT: d = clad::pop(_t3); +//CHECK-NEXT: } +//CHECK-NEXT: clad::pop(_t2); +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT:} + +double fn33(double i, double j) { + double res = 0; + for (int c = 0; (res=i*j); ++c) { + if ( (res +=i*j) && (c == 1)) { + break; + } + if ((c == 0) && (res+=i*j)) { + break; + } + } + return res; +} + +//CHECK: void fn33_grad(double i, double j, double *_d_i, double *_d_j) { +//CHECK-NEXT: double _d_res = 0; +//CHECK-NEXT: unsigned {{int|long}} _t0; +//CHECK-NEXT: int _d_c = 0; +//CHECK-NEXT: int c = 0; +//CHECK-NEXT: clad::tape _t1 = {}; +//CHECK-NEXT: bool _cond0; +//CHECK-NEXT: double _d_cond0; +//CHECK-NEXT: _d_cond0 = 0.; +//CHECK-NEXT: clad::tape _t2 = {}; +//CHECK-NEXT: clad::tape _cond1 = {}; +//CHECK-NEXT: clad::tape _t3 = {}; +//CHECK-NEXT: clad::tape _cond2 = {}; +//CHECK-NEXT: clad::tape _t4 = {}; +//CHECK-NEXT: bool _cond3; +//CHECK-NEXT: double _d_cond3; +//CHECK-NEXT: _d_cond3 = 0.; +//CHECK-NEXT: clad::tape _cond4 = {}; +//CHECK-NEXT: clad::tape _t5 = {}; +//CHECK-NEXT: clad::tape _t6 = {}; +//CHECK-NEXT: clad::tape _cond5 = {}; +//CHECK-NEXT: double res = 0; +//CHECK-NEXT: _t0 = {{0U|0UL}}; +//CHECK-NEXT: for (c = 0; ; ++c) { +//CHECK-NEXT: { +//CHECK-NEXT: { +//CHECK-NEXT: clad::push(_t1, res); +//CHECK-NEXT: } +//CHECK-NEXT: if (!(res = i * j)) +//CHECK-NEXT: break; +//CHECK-NEXT: } +//CHECK-NEXT: _t0++; +//CHECK-NEXT: { +//CHECK-NEXT: { +//CHECK-NEXT: clad::push(_t2, res); +//CHECK-NEXT: clad::push(_cond1, (res += i * j)); +//CHECK-NEXT: if (clad::back(_cond1)) { +//CHECK-NEXT: clad::push(_t3, _cond0); +//CHECK-NEXT: _cond0 = (c == 1); +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: clad::push(_cond2, clad::back(_cond1) && _cond0); +//CHECK-NEXT: if (clad::back(_cond2)) { +//CHECK-NEXT: { +//CHECK-NEXT: clad::push(_t4, {{1U|1UL}}); +//CHECK-NEXT: break; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: { +//CHECK-NEXT: { +//CHECK-NEXT: clad::push(_cond4, (c == 0)); +//CHECK-NEXT: if (clad::back(_cond4)) { +//CHECK-NEXT: clad::push(_t5, _cond3); +//CHECK-NEXT: clad::push(_t6, res); +//CHECK-NEXT: _cond3 = (res += i * j); +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: clad::push(_cond5, clad::back(_cond4) && _cond3); +//CHECK-NEXT: if (clad::back(_cond5)) { +//CHECK-NEXT: { +//CHECK-NEXT: clad::push(_t4, {{2U|2UL}}); +//CHECK-NEXT: break; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: clad::push(_t4, {{3U|3UL}}); +//CHECK-NEXT: } +//CHECK-NEXT: _d_res += 1; +//CHECK-NEXT: for (;; _t0--) { +//CHECK-NEXT: { +//CHECK-NEXT: if (!_t0 || (clad::back(_t4) != 1 && clad::back(_t4) != 2)) { +//CHECK-NEXT: res = clad::pop(_t1); +//CHECK-NEXT: double _r_d0 = _d_res; +//CHECK-NEXT: _d_res -= _r_d0; +//CHECK-NEXT: *_d_i += _r_d0 * j; +//CHECK-NEXT: *_d_j += i * _r_d0; +//CHECK-NEXT: } +//CHECK-NEXT: if (!_t0) +//CHECK-NEXT: break; +//CHECK-NEXT: } +//CHECK-NEXT: switch (clad::pop(_t4)) { +//CHECK-NEXT: case {{3U|3UL}}: +//CHECK-NEXT: ; +//CHECK-NEXT: --c; +//CHECK-NEXT: { +//CHECK-NEXT: if (clad::back(_cond5)) { +//CHECK-NEXT: case {{2U|2UL}}: +//CHECK-NEXT: ; +//CHECK-NEXT: } +//CHECK-NEXT: clad::pop(_cond5); +//CHECK-NEXT: { +//CHECK-NEXT: { +//CHECK-NEXT: if (clad::back(_cond4)) { +//CHECK-NEXT: _cond3 = clad::pop(_t5); +//CHECK-NEXT: double _r_d3 = _d_cond3; +//CHECK-NEXT: _d_cond3 -= _r_d3; +//CHECK-NEXT: _d_res += _r_d3; +//CHECK-NEXT: res = clad::pop(_t6); +//CHECK-NEXT: double _r_d4 = _d_res; +//CHECK-NEXT: *_d_i += _r_d4 * j; +//CHECK-NEXT: *_d_j += i * _r_d4; +//CHECK-NEXT: } +//CHECK-NEXT: clad::pop(_cond4); +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: { +//CHECK-NEXT: if (clad::back(_cond2)) { +//CHECK-NEXT: case {{1U|1UL}}: +//CHECK-NEXT: ; +//CHECK-NEXT: } +//CHECK-NEXT: clad::pop(_cond2); +//CHECK-NEXT: { +//CHECK-NEXT: { +//CHECK-NEXT: if (clad::back(_cond1)) { +//CHECK-NEXT: _cond0 = clad::pop(_t3); +//CHECK-NEXT: double _r_d2 = _d_cond0; +//CHECK-NEXT: _d_cond0 -= _r_d2; +//CHECK-NEXT: } +//CHECK-NEXT: clad::pop(_cond1); +//CHECK-NEXT: { +//CHECK-NEXT: res = clad::pop(_t2); +//CHECK-NEXT: double _r_d1 = _d_res; +//CHECK-NEXT: *_d_i += _r_d1 * j; +//CHECK-NEXT: *_d_j += i * _r_d1; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT:} + #define TEST(F, x) { \ result[0] = 0; \ auto F##grad = clad::gradient(F);\ @@ -1786,9 +2801,21 @@ int main() { auto d_fn20 = clad::gradient(fn20, "arr"); d_fn20.execute(x, 5, result); printf("{%.2f, %.2f, %.2f, %.2f, %.2f}\n", result[0], result[1], result[2], result[3], result[4]); // CHECK-EXEC: {5.00, 5.00, 5.00, 5.00, 5.00} - + TEST(fn21, 5); // CHECK-EXEC: {5.00} TEST(fn22, 5); // CHECK-EXEC: {1.00} + TEST_2(fn23, 3, 5); // CHECK-EXEC: {5.00, 3.00} + TEST_2(fn24, 3, 5); // CHECK-EXEC: {20.00, 12.00} + TEST_2(fn25, 3, 5); // CHECK-EXEC: {40.00, 24.00} + TEST_2(fn26, 3, 5); // CHECK-EXEC: {5.00, 3.00} + TEST_2(fn27, 3, 5); // CHECK-EXEC: {10.00, 6.00} + TEST_2(fn28, 3, 5); // CHECK-EXEC: {5.00, 3.00} + TEST_2(fn29, 3, 5); // CHECK-EXEC: {5.00, 3.00} + TEST_2(fn30, 3, 5); // CHECK-EXEC: {5.00, 3.00} + TEST_2(fn31, 3, 5); // CHECK-EXEC: {10.00, 6.00} + TEST_2(fn32, 3, 5); // CHECK-EXEC: {45.00, 27.00} + TEST_2(fn33, 3, 5); // CHECK-EXEC: {15.00, 9.00} + } //CHECK: void sq_pullback(double x, double _d_y, double *_d_x) { diff --git a/test/Gradient/Pointers.C b/test/Gradient/Pointers.C index 748811d08..f57fddf6a 100644 --- a/test/Gradient/Pointers.C +++ b/test/Gradient/Pointers.C @@ -176,7 +176,11 @@ double pointerParam(const double* arr, size_t n) { // CHECK-NEXT: clad::tape _t6 = {}; // CHECK-NEXT: double sum = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < n; ++i) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < n)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: _d_j = &_d_i; // CHECK-NEXT: clad::push(_t1, _d_j); @@ -189,7 +193,11 @@ double pointerParam(const double* arr, size_t n) { // CHECK-NEXT: arr = arr + 1; // CHECK-NEXT: } // CHECK-NEXT: _d_sum += 1; -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --i; // CHECK-NEXT: size_t *_t2 = clad::pop(_t1); // CHECK-NEXT: { diff --git a/test/Gradient/Switch.C b/test/Gradient/Switch.C index 45c4b0a2c..53484165d 100644 --- a/test/Gradient/Switch.C +++ b/test/Gradient/Switch.C @@ -594,7 +594,11 @@ double fn7(double u, double v) { // CHECK-NEXT: clad::tape _t3 = {}; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < 5; ++i) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 5)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: { // CHECK-NEXT: clad::push(_cond0, i) @@ -631,7 +635,11 @@ double fn7(double u, double v) { // CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: _d_res += 1; -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --i; // CHECK-NEXT: { // CHECK-NEXT: switch (clad::pop(_t2)) { diff --git a/test/Gradient/TestTypeConversion.C b/test/Gradient/TestTypeConversion.C index 30cf2dfc8..144f2cf09 100644 --- a/test/Gradient/TestTypeConversion.C +++ b/test/Gradient/TestTypeConversion.C @@ -24,13 +24,21 @@ void fn_type_conversion_grad(float z, int a, float *_d_z, int *_d_a); // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 1; i < a; i++) { +// CHECK-NEXT: for (i = 1; ; i++) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < a)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, z); // CHECK-NEXT: z = z * a; // CHECK-NEXT: } // CHECK-NEXT: *_d_z += 1; -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: i--; // CHECK-NEXT: { // CHECK-NEXT: z = clad::pop(_t1); diff --git a/test/Gradient/UserDefinedTypes.C b/test/Gradient/UserDefinedTypes.C index df18c43c8..cf86521f0 100644 --- a/test/Gradient/UserDefinedTypes.C +++ b/test/Gradient/UserDefinedTypes.C @@ -314,7 +314,11 @@ double fn9(Tangent t, dcomplex c) { // CHECK-NEXT: Tangent _t6; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < 5; ++i) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 5)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, res); // CHECK-NEXT: clad::push(_t2, c); @@ -331,7 +335,11 @@ double fn9(Tangent t, dcomplex c) { // CHECK-NEXT: t = _t6; // CHECK-NEXT: sum_pullback(_t6, _r_d1, &(*_d_t)); // CHECK-NEXT: } -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --i; // CHECK-NEXT: { // CHECK-NEXT: res = clad::pop(_t1); @@ -392,13 +400,21 @@ int main() { // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < 5; ++i) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 5)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, res); // CHECK-NEXT: res += t.data[i]; // CHECK-NEXT: } // CHECK-NEXT: _d_res += _d_y; -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --i; // CHECK-NEXT: res = clad::pop(_t1); // CHECK-NEXT: double _r_d0 = _d_res; @@ -414,13 +430,21 @@ int main() { // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double res = 0; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < 5; ++i) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 5)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, res); // CHECK-NEXT: res += data[i]; // CHECK-NEXT: } // CHECK-NEXT: _d_res += _d_y; -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --i; // CHECK-NEXT: res = clad::pop(_t1); // CHECK-NEXT: double _r_d0 = _d_res; @@ -464,12 +488,20 @@ int main() { // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: _t0 = {{0U|0UL}}; -// CHECK-NEXT: for (i = 0; i < 5; ++i) { +// CHECK-NEXT: for (i = 0; ; ++i) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!(i < 5)) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, this->data[i]); // CHECK-NEXT: this->data[i] = d; // CHECK-NEXT: } -// CHECK-NEXT: for (; _t0; _t0--) { +// CHECK-NEXT: for (;; _t0--) { +// CHECK-NEXT: { +// CHECK-NEXT: if (!_t0) +// CHECK-NEXT: break; +// CHECK-NEXT: } // CHECK-NEXT: --i; // CHECK-NEXT: this->data[i] = clad::pop(_t1); // CHECK-NEXT: double _r_d0 = (*_d_this).data[i]; diff --git a/test/Misc/RunDemos.C b/test/Misc/RunDemos.C index f3d29694f..99d2aaa62 100644 --- a/test/Misc/RunDemos.C +++ b/test/Misc/RunDemos.C @@ -107,33 +107,41 @@ //CHECK_FLOAT_SUM-NOT: {{.*error|warning|note:.*}} //CHECK_FLOAT_SUM: void vanillaSum_grad(float x, unsigned int n, float *_d_x, unsigned int *_d_n, double &_final_error) { -//CHECK_FLOAT_SUM: float _d_sum = 0; -//CHECK_FLOAT_SUM: unsigned {{int|long}} _t0; -//CHECK_FLOAT_SUM: unsigned int _d_i = 0; -//CHECK_FLOAT_SUM: unsigned int i = 0; -//CHECK_FLOAT_SUM: clad::tape _t1 = {}; -//CHECK_FLOAT_SUM: float sum = 0.; -//CHECK_FLOAT_SUM: _t0 = {{0U|0UL}}; -//CHECK_FLOAT_SUM: for (i = 0; i < n; i++) { -//CHECK_FLOAT_SUM: _t0++; -//CHECK_FLOAT_SUM: clad::push(_t1, sum); -//CHECK_FLOAT_SUM: sum = sum + x; -//CHECK_FLOAT_SUM: } -//CHECK_FLOAT_SUM: _d_sum += 1; -//CHECK_FLOAT_SUM: for (; _t0; _t0--) { -//CHECK_FLOAT_SUM: i--; -//CHECK_FLOAT_SUM: { -//CHECK_FLOAT_SUM: _final_error += std::abs(_d_sum * sum * 1.1920928955078125E-7); -//CHECK_FLOAT_SUM: sum = clad::pop(_t1); -//CHECK_FLOAT_SUM: float _r_d0 = _d_sum; -//CHECK_FLOAT_SUM: _d_sum -= _r_d0; -//CHECK_FLOAT_SUM: _d_sum += _r_d0; -//CHECK_FLOAT_SUM: *_d_x += _r_d0; -//CHECK_FLOAT_SUM: } -//CHECK_FLOAT_SUM: } -//CHECK_FLOAT_SUM: _final_error += std::abs(_d_sum * sum * 1.1920928955078125E-7); -//CHECK_FLOAT_SUM: _final_error += std::abs(*_d_x * x * 1.1920928955078125E-7); -//CHECK_FLOAT_SUM: } +//CHECK_FLOAT_SUM: float _d_sum = 0; +//CHECK_FLOAT_SUM: unsigned {{int|long}} _t0; +//CHECK_FLOAT_SUM: unsigned int _d_i = 0; +//CHECK_FLOAT_SUM: unsigned int i = 0; +//CHECK_FLOAT_SUM: clad::tape _t1 = {}; +//CHECK_FLOAT_SUM: float sum = 0.; +//CHECK_FLOAT_SUM: _t0 = {{0U|0UL}}; +//CHECK_FLOAT_SUM: for (i = 0; ; i++) { +//CHECK_FLOAT_SUM: { +//CHECK_FLOAT_SUM: if (!(i < n)) +//CHECK_FLOAT_SUM: break; +//CHECK_FLOAT_SUM: } +//CHECK_FLOAT_SUM: _t0++; +//CHECK_FLOAT_SUM: clad::push(_t1, sum); +//CHECK_FLOAT_SUM: sum = sum + x; +//CHECK_FLOAT_SUM: } +//CHECK_FLOAT_SUM: _d_sum += 1; +//CHECK_FLOAT_SUM: for (;; _t0--) { +//CHECK_FLOAT_SUM: { +//CHECK_FLOAT_SUM: if (!_t0) +//CHECK_FLOAT_SUM: break; +//CHECK_FLOAT_SUM: } +//CHECK_FLOAT_SUM: i--; +//CHECK_FLOAT_SUM: { +//CHECK_FLOAT_SUM: _final_error += std::abs(_d_sum * sum * 1.1920928955078125E-7); +//CHECK_FLOAT_SUM: sum = clad::pop(_t1); +//CHECK_FLOAT_SUM: float _r_d0 = _d_sum; +//CHECK_FLOAT_SUM: _d_sum -= _r_d0; +//CHECK_FLOAT_SUM: _d_sum += _r_d0; +//CHECK_FLOAT_SUM: *_d_x += _r_d0; +//CHECK_FLOAT_SUM: } +//CHECK_FLOAT_SUM: } +//CHECK_FLOAT_SUM: _final_error += std::abs(_d_sum * sum * 1.1920928955078125E-7); +//CHECK_FLOAT_SUM: _final_error += std::abs(*_d_x * x * 1.1920928955078125E-7); +//CHECK_FLOAT_SUM:} //-----------------------------------------------------------------------------/ // Demo: Custom Error Estimation Plugin