From 2864c56af907f35357731ecb85e360a64dd0b33d Mon Sep 17 00:00:00 2001 From: "petro.zarytskyi" Date: Tue, 23 Apr 2024 13:14:14 +0300 Subject: [PATCH] Make integral type variables non-differentiable in the forward mode --- .../clad/Differentiator/BuiltinDerivatives.h | 15 +- lib/Differentiator/BaseForwardModeVisitor.cpp | 29 ++- lib/Differentiator/VisitorBase.cpp | 63 +++-- test/Arrays/ArrayInputsForwardMode.C | 30 +-- test/Arrays/Arrays.C | 27 +-- test/FirstDerivative/BasicArithmeticAddSub.C | 122 +++++----- test/FirstDerivative/BasicArithmeticAll.C | 34 +-- test/FirstDerivative/BasicArithmeticMulDiv.C | 177 +++++++------- test/FirstDerivative/BuiltinDerivatives.C | 3 +- test/FirstDerivative/ClassMethodCall.C | 36 +-- test/FirstDerivative/CodeGenSimple.C | 19 +- test/FirstDerivative/DiffInterface.C | 50 ++-- test/FirstDerivative/FunctionCalls.C | 28 +-- .../FunctionCallsWithResults.C | 37 ++- test/FirstDerivative/FunctionsInNamespaces.C | 32 +-- test/FirstDerivative/FunctionsOneVariable.C | 6 +- test/FirstDerivative/Loops.C | 140 ++++-------- test/FirstDerivative/NonContinuous.C | 31 ++- test/FirstDerivative/Overloads.C | 5 +- test/FirstDerivative/Recursive.C | 41 ++-- test/FirstDerivative/StructMethodCall.C | 72 +++--- test/FirstDerivative/Switch.C | 5 - test/FirstDerivative/SwitchInit.C | 2 - test/FirstDerivative/TemplateFunction.C | 17 +- test/FirstDerivative/UnsupportedOpsWarn.C | 23 +- test/ForwardMode/FunctorErrors.C | 4 +- test/ForwardMode/Functors.C | 36 +-- test/ForwardMode/Pointer.C | 7 +- test/ForwardMode/UserDefinedTypes.C | 215 +++++++----------- test/ForwardMode/VectorMode.C | 14 +- test/NthDerivative/CustomDerivatives.C | 20 +- 31 files changed, 590 insertions(+), 750 deletions(-) diff --git a/include/clad/Differentiator/BuiltinDerivatives.h b/include/clad/Differentiator/BuiltinDerivatives.h index b2c5875d8..c1ffc546a 100644 --- a/include/clad/Differentiator/BuiltinDerivatives.h +++ b/include/clad/Differentiator/BuiltinDerivatives.h @@ -25,15 +25,15 @@ namespace custom_derivatives { #ifdef __CUDACC__ template ValueAndPushforward -cudaMalloc_pushforward(T** devPtr, size_t sz, T** d_devPtr, size_t d_sz) +cudaMalloc_pushforward(T** devPtr, size_t sz, T** d_devPtr) __attribute__((host)) { return {cudaMalloc(devPtr, sz), cudaMalloc(d_devPtr, sz)}; } ValueAndPushforward cudaMemcpy_pushforward(void* destPtr, void* srcPtr, size_t count, - cudaMemcpyKind kind, void* d_destPtr, void* d_srcPtr, - size_t d_count) __attribute__((host)) { + cudaMemcpyKind kind, void* d_destPtr, void* d_srcPtr) + __attribute__((host)) { return {cudaMemcpy(destPtr, srcPtr, count, kind), cudaMemcpy(d_destPtr, d_srcPtr, count, kind)}; } @@ -199,18 +199,17 @@ CUDA_HOST_DEVICE void clamp_pullback(const T& v, const T& lo, const T& hi, // NOLINTBEGIN(cppcoreguidelines-no-malloc) // NOLINTBEGIN(cppcoreguidelines-owning-memory) -inline ValueAndPushforward malloc_pushforward(size_t sz, - size_t d_sz) { +inline ValueAndPushforward malloc_pushforward(size_t sz) { return {malloc(sz), malloc(sz)}; } -inline ValueAndPushforward -calloc_pushforward(size_t n, size_t sz, size_t d_n, size_t d_sz) { +inline ValueAndPushforward calloc_pushforward(size_t n, + size_t sz) { return {calloc(n, sz), calloc(n, sz)}; } inline ValueAndPushforward -realloc_pushforward(void* ptr, size_t sz, void* d_ptr, size_t d_sz) { +realloc_pushforward(void* ptr, size_t sz, void* d_ptr) { return {realloc(ptr, sz), realloc(d_ptr, sz)}; } diff --git a/lib/Differentiator/BaseForwardModeVisitor.cpp b/lib/Differentiator/BaseForwardModeVisitor.cpp index 6f2dd6962..cc2966eb4 100644 --- a/lib/Differentiator/BaseForwardModeVisitor.cpp +++ b/lib/Differentiator/BaseForwardModeVisitor.cpp @@ -1167,7 +1167,6 @@ StmtDiff BaseForwardModeVisitor::VisitCallExpr(const CallExpr* CE) { } } } - // If clad failed to derive it, try finding its derivative using // numerical diff. if (!callDiff) { @@ -1293,9 +1292,12 @@ BaseForwardModeVisitor::VisitBinaryOperator(const BinaryOperator* BinOp) { opDiff = BuildOp(opCode, derivedL, derivedR); } else if (BinOp->isAssignmentOp()) { if (Ldiff.getExpr_dx()->isModifiableLvalue(m_Context) != Expr::MLV_Valid) { - diag(DiagnosticsEngine::Warning, BinOp->getEndLoc(), - "derivative of an assignment attempts to assign to unassignable " - "expr, assignment ignored"); + // If the LHS has a non-differentiable type, Ldiff.getExpr_dx() will be 0. + // Don't create a warning then. + if (IsDifferentiableType(BinOp->getLHS()->getType())) + diag(DiagnosticsEngine::Warning, BinOp->getEndLoc(), + "derivative of an assignment attempts to assign to unassignable " + "expr, assignment ignored"); opDiff = ConstantFolder::synthesizeLiteral(m_Context.IntTy, m_Context, 0); } else if (opCode == BO_Assign || opCode == BO_AddAssign || opCode == BO_SubAssign) { @@ -1372,10 +1374,13 @@ BaseForwardModeVisitor::DifferentiateVarDecl(const VarDecl* VD) { BuildVarDecl(VD->getType(), VD->getNameAsString(), initDiff.getExpr(), VD->isDirectInit(), nullptr, VD->getInitStyle()); // FIXME: Create unique identifier for derivative. - VarDecl* VDDerived = BuildVarDecl( - VD->getType(), "_d_" + VD->getNameAsString(), initDiff.getExpr_dx(), - VD->isDirectInit(), nullptr, VD->getInitStyle()); - m_Variables.emplace(VDClone, BuildDeclRef(VDDerived)); + VarDecl* VDDerived = nullptr; + if (IsDifferentiableType(VD->getType())) { + VDDerived = BuildVarDecl(VD->getType(), "_d_" + VD->getNameAsString(), + initDiff.getExpr_dx(), VD->isDirectInit(), nullptr, + VD->getInitStyle()); + m_Variables.emplace(VDClone, BuildDeclRef(VDDerived)); + } return DeclDiff(VDClone, VDDerived); } @@ -1437,7 +1442,8 @@ StmtDiff BaseForwardModeVisitor::VisitDeclStmt(const DeclStmt* DS) { if (VDDiff.getDecl()->getDeclName() != VD->getDeclName()) m_DeclReplacements[VD] = VDDiff.getDecl(); decls.push_back(VDDiff.getDecl()); - declsDiff.push_back(VDDiff.getDecl_dx()); + if (VDDiff.getDecl_dx()) + declsDiff.push_back(VDDiff.getDecl_dx()); } else if (auto* SAD = dyn_cast(D)) { DeclDiff SADDiff = DifferentiateStaticAssertDecl(SAD); if (SADDiff.getDecl()) @@ -1576,7 +1582,7 @@ StmtDiff BaseForwardModeVisitor::VisitWhileStmt(const WhileStmt* WS) { // ... // ... // } - if (condVarClone) { + if (condVarRes.getDecl_dx()) { bodyResult = utils::PrependAndCreateCompoundStmt( m_Sema.getASTContext(), cast(bodyResult), BuildDeclStmt(condVarRes.getDecl_dx())); @@ -1655,7 +1661,8 @@ StmtDiff BaseForwardModeVisitor::VisitSwitchStmt(const SwitchStmt* SS) { if (condVarDecl) { DeclDiff condVarDeclDiff = DifferentiateVarDecl(condVarDecl); condVarClone = condVarDeclDiff.getDecl(); - addToCurrentBlock(BuildDeclStmt(condVarDeclDiff.getDecl_dx())); + if (condVarDeclDiff.getDecl_dx()) + addToCurrentBlock(BuildDeclStmt(condVarDeclDiff.getDecl_dx())); } StmtDiff initVarRes = (SS->getInit() ? Visit(SS->getInit()) : StmtDiff()); diff --git a/lib/Differentiator/VisitorBase.cpp b/lib/Differentiator/VisitorBase.cpp index 0390a7dda..a47e94b32 100644 --- a/lib/Differentiator/VisitorBase.cpp +++ b/lib/Differentiator/VisitorBase.cpp @@ -892,30 +892,45 @@ namespace clad { Expr* UnresolvedLookup = m_Sema.BuildDeclarationNameExpr(SS, R, /*ADL*/ false).get(); - llvm::SmallVector ExtendedCallArgs(CallArgs.begin(), - CallArgs.end()); + llvm::SmallVector ExtendedCallArgs; llvm::SmallVector DeclStmts; - // FIXME: for now, integer types are considered differentiable in the - // forward mode. - if (m_Mode != DiffMode::forward && - m_Mode != DiffMode::vector_forward_mode && - m_Mode != DiffMode::experimental_pushforward) - for (size_t i = 0, e = originalFD->getNumParams(); i < e; ++i) { - QualType paramTy = originalFD->getParamDecl(i)->getType(); - if (!IsDifferentiableType(paramTy)) { - QualType argTy = utils::getNonConstType(paramTy, m_Context, m_Sema); - VarDecl* argDecl = BuildVarDecl(argTy, "_r", getZeroInit(argTy)); - Expr* arg = BuildDeclRef(argDecl); - if (!utils::isArrayOrPointerType(argTy)) - arg = BuildOp(UO_AddrOf, arg); - ExtendedCallArgs.insert(ExtendedCallArgs.begin() + e + i + 1, arg); - DeclStmts.push_back(BuildDeclStmt(argDecl)); + auto MARargs = llvm::MutableArrayRef(CallArgs); + if (noOverloadExists(UnresolvedLookup, MARargs)) { + bool isMethodCall = isa(originalFD); + ExtendedCallArgs = + llvm::SmallVector(CallArgs.begin(), CallArgs.end()); + if (m_Mode != DiffMode::forward && + m_Mode != DiffMode::vector_forward_mode && + m_Mode != DiffMode::experimental_pushforward) + for (size_t i = 0, e = originalFD->getNumParams(); i < e; ++i) { + QualType paramTy = originalFD->getParamDecl(i)->getType(); + if (!IsDifferentiableType(paramTy)) { + QualType argTy = + utils::getNonConstType(paramTy, m_Context, m_Sema); + VarDecl* argDecl = BuildVarDecl(argTy, "_r", getZeroInit(argTy)); + Expr* arg = BuildDeclRef(argDecl); + if (!utils::isArrayOrPointerType(argTy)) + arg = BuildOp(UO_AddrOf, arg); + ExtendedCallArgs.insert( + ExtendedCallArgs.begin() + e + i + 1 + 2 * isMethodCall, arg); + DeclStmts.push_back(BuildDeclStmt(argDecl)); + } } - } - auto MARargs = llvm::MutableArrayRef(ExtendedCallArgs); - - if (noOverloadExists(UnresolvedLookup, MARargs)) - return nullptr; + else + for (size_t i = 0, e = originalFD->getNumParams(); i < e; ++i) { + QualType paramTy = originalFD->getParamDecl(i)->getType(); + if (!IsDifferentiableType(paramTy)) { + QualType argTy = + utils::getNonConstType(paramTy, m_Context, m_Sema); + Expr* zero = getZeroInit(argTy); + ExtendedCallArgs.insert( + ExtendedCallArgs.begin() + e + i + 2 * isMethodCall, zero); + } + } + MARargs = llvm::MutableArrayRef(ExtendedCallArgs); + if (noOverloadExists(UnresolvedLookup, MARargs)) + return nullptr; + } OverloadedFn = m_Sema.ActOnCallExpr(S, UnresolvedLookup, noLoc, MARargs, noLoc) @@ -958,6 +973,10 @@ namespace clad { return true; } } + return false; + } else if (const auto* DRE = dyn_cast(UnresolvedLookup)) { + const auto* FD = cast(DRE->getDecl()); + return FD->getNumParams() != ARargs.size(); } return false; } diff --git a/test/Arrays/ArrayInputsForwardMode.C b/test/Arrays/ArrayInputsForwardMode.C index a7fdcac77..d69db8853 100644 --- a/test/Arrays/ArrayInputsForwardMode.C +++ b/test/Arrays/ArrayInputsForwardMode.C @@ -30,15 +30,11 @@ double addArr(const double *arr, int n) { } //CHECK: double addArr_darg0_1(const double *arr, int n) { -//CHECK-NEXT: int _d_n = 0; //CHECK-NEXT: double _d_ret = 0; //CHECK-NEXT: double ret = 0; -//CHECK-NEXT: { -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: for (int i = 0; i < n; i++) { -//CHECK-NEXT: _d_ret += (i == 1.); -//CHECK-NEXT: ret += arr[i]; -//CHECK-NEXT: } +//CHECK-NEXT: for (int i = 0; i < n; i++) { +//CHECK-NEXT: _d_ret += (i == 1.); +//CHECK-NEXT: ret += arr[i]; //CHECK-NEXT: } //CHECK-NEXT: return _d_ret; //CHECK-NEXT: } @@ -59,25 +55,17 @@ double numMultIndex(double* arr, size_t n, double x) { } // CHECK: double numMultIndex_darg2(double *arr, size_t n, double x) { -// CHECK-NEXT: size_t _d_n = 0; // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: bool _d_flag = 0; // CHECK-NEXT: bool flag = false; -// CHECK-NEXT: size_t _d_idx = 0; // CHECK-NEXT: size_t idx = 0; -// CHECK-NEXT: { -// CHECK-NEXT: size_t _d_i = 0; -// CHECK-NEXT: for (size_t i = 0; i < n; ++i) { -// CHECK-NEXT: if (arr[i] == x) { -// CHECK-NEXT: _d_flag = 0; -// CHECK-NEXT: flag = true; -// CHECK-NEXT: _d_idx = _d_i; -// CHECK-NEXT: idx = i; -// CHECK-NEXT: break; -// CHECK-NEXT: } +// CHECK-NEXT: for (size_t i = 0; i < n; ++i) { +// CHECK-NEXT: if (arr[i] == x) { +// CHECK-NEXT: flag = true; +// CHECK-NEXT: idx = i; +// CHECK-NEXT: break; // CHECK-NEXT: } // CHECK-NEXT: } -// CHECK-NEXT: return flag ? _d_idx * x + idx * _d_x : 0; +// CHECK-NEXT: return flag ? 0 * x + idx * _d_x : 0; // CHECK-NEXT: } int main() { diff --git a/test/Arrays/Arrays.C b/test/Arrays/Arrays.C index 7dc35a336..fd31d50a0 100644 --- a/test/Arrays/Arrays.C +++ b/test/Arrays/Arrays.C @@ -26,12 +26,9 @@ double sum(double x, double y, double z) { //CHECK-NEXT: double vars[3] = {x, y, z}; //CHECK-NEXT: double _d_s = 0; //CHECK-NEXT: double s = 0; -//CHECK-NEXT: { -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: for (int i = 0; i < 3; i++) { -//CHECK-NEXT: _d_s = _d_s + _d_vars[i]; -//CHECK-NEXT: s = s + vars[i]; -//CHECK-NEXT: } +//CHECK-NEXT: for (int i = 0; i < 3; i++) { +//CHECK-NEXT: _d_s = _d_s + _d_vars[i]; +//CHECK-NEXT: s = s + vars[i]; //CHECK-NEXT: } //CHECK-NEXT: return _d_s; //CHECK-NEXT: } @@ -55,21 +52,15 @@ double sum_squares(double x, double y, double z) { //CHECK-NEXT: double vars[3] = {x, y, z}; //CHECK-NEXT: double _d_squares[3]; //CHECK-NEXT: double squares[3]; -//CHECK-NEXT: { -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: for (int i = 0; i < 3; i++) { -//CHECK-NEXT: _d_squares[i] = _d_vars[i] * vars[i] + vars[i] * _d_vars[i]; -//CHECK-NEXT: squares[i] = vars[i] * vars[i]; -//CHECK-NEXT: } +//CHECK-NEXT: for (int i = 0; i < 3; i++) { +//CHECK-NEXT: _d_squares[i] = _d_vars[i] * vars[i] + vars[i] * _d_vars[i]; +//CHECK-NEXT: squares[i] = vars[i] * vars[i]; //CHECK-NEXT: } //CHECK-NEXT: double _d_s = 0; //CHECK-NEXT: double s = 0; -//CHECK-NEXT: { -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: for (int i = 0; i < 3; i++) { -//CHECK-NEXT: _d_s = _d_s + _d_squares[i]; -//CHECK-NEXT: s = s + squares[i]; -//CHECK-NEXT: } +//CHECK-NEXT: for (int i = 0; i < 3; i++) { +//CHECK-NEXT: _d_s = _d_s + _d_squares[i]; +//CHECK-NEXT: s = s + squares[i]; //CHECK-NEXT: } //CHECK-NEXT: return _d_s; //CHECK-NEXT: } diff --git a/test/FirstDerivative/BasicArithmeticAddSub.C b/test/FirstDerivative/BasicArithmeticAddSub.C index a69483586..aa5dda314 100644 --- a/test/FirstDerivative/BasicArithmeticAddSub.C +++ b/test/FirstDerivative/BasicArithmeticAddSub.C @@ -7,90 +7,90 @@ extern "C" int printf(const char* fmt, ...); -int a_1(int x) { - int y = 4; +float a_1(float x) { + float y = 4; return y + y; // == 0 } -// CHECK: int a_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float a_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return _d_y + _d_y; // CHECK-NEXT: } -int a_2(int x) { +float a_2(float x) { return 1 + 1; // == 0 } -// CHECK: int a_2_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float a_2_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return 0 + 0; // CHECK-NEXT: } -int a_3(int x) { +float a_3(float x) { return x + x; // == 2 } -// CHECK: int a_3_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float a_3_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return _d_x + _d_x; // CHECK-NEXT: } -int a_4(int x) { - int y = 4; +float a_4(float x) { + float y = 4; return x + y + x + 3 + x; // == 3x } -// CHECK: int a_4_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float a_4_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return _d_x + _d_y + _d_x + 0 + _d_x; // CHECK-NEXT: } -int s_1(int x) { - int y = 4; +float s_1(float x) { + float y = 4; return y - y; // == 0 } -// CHECK: int s_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float s_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return _d_y - _d_y; // CHECK-NEXT: } -int s_2(int x) { +float s_2(float x) { return 1 - 1; // == 0 } -// CHECK: int s_2_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float s_2_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return 0 - 0; // CHECK-NEXT: } -int s_3(int x) { +float s_3(float x) { return x - x; // == 0 } -// CHECK: int s_3_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float s_3_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return _d_x - _d_x; // CHECK-NEXT: } -int s_4(int x) { - int y = 4; +float s_4(float x) { + float y = 4; return x - y - x - 3 - x; // == -1 } -// CHECK: int s_4_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float s_4_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return _d_x - _d_y - _d_x - 0 - _d_x; // CHECK-NEXT: } -int as_1(int x) { - int y = 4; +float as_1(float x) { + float y = 4; return x + x - x + y - y + 3 - 3; // == 1 } -// CHECK: int as_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float as_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return _d_x + _d_x - _d_x + _d_y - _d_y + 0 - 0; // CHECK-NEXT: } @@ -103,45 +103,45 @@ float IntegerLiteralToFloatLiteral(float x, float y) { // CHECK-NEXT: return _d_x * x + x * _d_x - _d_y; // CHECK-NEXT: } -int a_1_darg0(int x); -int a_2_darg0(int x); -int a_3_darg0(int x); -int a_4_darg0(int x); -int s_1_darg0(int x); -int s_2_darg0(int x); -int s_3_darg0(int x); -int s_4_darg0(int x); -int as_1_darg0(int x); +float a_1_darg0(float x); +float a_2_darg0(float x); +float a_3_darg0(float x); +float a_4_darg0(float x); +float s_1_darg0(float x); +float s_2_darg0(float x); +float s_3_darg0(float x); +float s_4_darg0(float x); +float as_1_darg0(float x); float IntegerLiteralToFloatLiteral_darg0(float x, float y); int main () { // expected-no-diagnostics - int x = 4; + float x = 4; clad::differentiate(a_1, 0); - printf("Result is = %d\n", a_1_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %f\n", a_1_darg0(1)); // CHECK-EXEC: Result is = 0 clad::differentiate(a_2, 0); - printf("Result is = %d\n", a_2_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %f\n", a_2_darg0(1)); // CHECK-EXEC: Result is = 0 clad::differentiate(a_3, 0); - printf("Result is = %d\n", a_3_darg0(1)); // CHECK-EXEC: Result is = 2 + printf("Result is = %f\n", a_3_darg0(1)); // CHECK-EXEC: Result is = 2 clad::differentiate(a_4, 0); - printf("Result is = %d\n", a_4_darg0(1)); // CHECK-EXEC: Result is = 3 + printf("Result is = %f\n", a_4_darg0(1)); // CHECK-EXEC: Result is = 3 clad::differentiate(s_1, 0); - printf("Result is = %d\n", s_1_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %f\n", s_1_darg0(1)); // CHECK-EXEC: Result is = 0 clad::differentiate(s_2, 0); - printf("Result is = %d\n", s_2_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %f\n", s_2_darg0(1)); // CHECK-EXEC: Result is = 0 clad::differentiate(s_3, 0); - printf("Result is = %d\n", s_3_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %f\n", s_3_darg0(1)); // CHECK-EXEC: Result is = 0 clad::differentiate(s_4, 0); - printf("Result is = %d\n", s_4_darg0(1)); // CHECK-EXEC: Result is = -1 + printf("Result is = %f\n", s_4_darg0(1)); // CHECK-EXEC: Result is = -1 clad::differentiate(as_1, 0); - printf("Result is = %d\n", as_1_darg0(1)); // CHECK-EXEC: Result is = 1 + printf("Result is = %f\n", as_1_darg0(1)); // CHECK-EXEC: Result is = 1 clad::differentiate(IntegerLiteralToFloatLiteral, 0); printf("Result is = %f\n", IntegerLiteralToFloatLiteral_darg0(5., 0.)); // CHECK-EXEC: Result is = 10 diff --git a/test/FirstDerivative/BasicArithmeticAll.C b/test/FirstDerivative/BasicArithmeticAll.C index 0ac24212d..18c8b4bb3 100644 --- a/test/FirstDerivative/BasicArithmeticAll.C +++ b/test/FirstDerivative/BasicArithmeticAll.C @@ -7,27 +7,27 @@ extern "C" int printf(const char* fmt, ...); -float basic_1(int x) { - int y = 4; - int z = 3; +float basic_1(float x) { + float y = 4; + float z = 3; return (y + x) / (x - z) * ((x * y * z) / 5); // == y * z * (x * x - 2 * x * z - y * z) / (5 * (x - z) * (x - z)) } -// CHECK: float basic_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; -// CHECK-NEXT: int _d_z = 0; -// CHECK-NEXT: int z = 3; -// CHECK-NEXT: int _t0 = (y + x); -// CHECK-NEXT: int _t1 = (x - z); -// CHECK-NEXT: int _t2 = x * y; -// CHECK-NEXT: int _t3 = (_t2 * z); -// CHECK-NEXT: int _t4 = _t0 / _t1; -// CHECK-NEXT: int _t5 = (_t3 / 5); +// CHECK: float basic_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; +// CHECK-NEXT: float _d_z = 0; +// CHECK-NEXT: float z = 3; +// CHECK-NEXT: float _t0 = (y + x); +// CHECK-NEXT: float _t1 = (x - z); +// CHECK-NEXT: float _t2 = x * y; +// CHECK-NEXT: float _t3 = (_t2 * z); +// CHECK-NEXT: float _t4 = _t0 / _t1; +// CHECK-NEXT: float _t5 = (_t3 / 5); // CHECK-NEXT: return (((_d_y + _d_x) * _t1 - _t0 * (_d_x - _d_z)) / (_t1 * _t1)) * _t5 + _t4 * ((((_d_x * y + x * _d_y) * z + _t2 * _d_z) * 5 - _t3 * 0) / (5 * 5)); // CHECK-NEXT: } -float basic_1_darg0(int x); +float basic_1_darg0(float x); double fn1(double i, double j) { double t = 1; @@ -98,7 +98,7 @@ double fn3(double i, double j) { int main () { clad::differentiate(basic_1, 0); - printf("Result is = %f\n", basic_1_darg0(1)); // CHECK-EXEC: Result is = -6 + printf("Result is = %.2f\n", basic_1_darg0(1)); // CHECK-EXEC: Result is = -10.20 INIT(fn1, "i"); INIT(fn2, "i"); INIT(fn3, "i"); diff --git a/test/FirstDerivative/BasicArithmeticMulDiv.C b/test/FirstDerivative/BasicArithmeticMulDiv.C index b02506b36..baf80d4ed 100644 --- a/test/FirstDerivative/BasicArithmeticMulDiv.C +++ b/test/FirstDerivative/BasicArithmeticMulDiv.C @@ -7,60 +7,60 @@ extern "C" int printf(const char* fmt, ...); -int m_1(int x) { - int y = 4; +float m_1(float x) { + float y = 4; return y * y; // == 0 } -// CHECK: int m_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float m_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return _d_y * y + y * _d_y; // CHECK-NEXT: } -int m_2(int x) { +float m_2(float x) { return 1 * 1; // == 0 } -// CHECK: int m_2_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float m_2_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return 0 * 1 + 1 * 0; // CHECK-NEXT: } -int m_3(int x) { +float m_3(float x) { return x * x; // == 2 * x } -// CHECK: int m_3_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float m_3_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return _d_x * x + x * _d_x; // CHECK-NEXT: } -int m_4(int x) { - int y = 4; +float m_4(float x) { + float y = 4; return x * y * x * 3 * x; // == 9 * x * x * y } -// CHECK: int m_4_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; -// CHECK-NEXT: int _t0 = x * y; -// CHECK-NEXT: int _t1 = _t0 * x; -// CHECK-NEXT: int _t2 = _t1 * 3; +// CHECK: float m_4_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; +// CHECK-NEXT: float _t0 = x * y; +// CHECK-NEXT: float _t1 = _t0 * x; +// CHECK-NEXT: float _t2 = _t1 * 3; // CHECK-NEXT: return (((_d_x * y + x * _d_y) * x + _t0 * _d_x) * 3 + _t1 * 0) * x + _t2 * _d_x; // CHECK-NEXT: } -double m_5(int x) { +double m_5(float x) { return 3.14 * x; } -// CHECK: double m_5_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: double m_5_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return 0. * x + 3.1400000000000001 * _d_x; // CHECK-NEXT: } -float m_6(int x) { +float m_6(float x) { return 3.f * x; } -// CHECK: float m_6_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float m_6_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return 0.F * x + 3.F * _d_x; // CHECK-NEXT: } @@ -100,7 +100,6 @@ double m_10(double x, bool flag) { } // CHECK: double m_10_darg0(double x, bool flag) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: bool _d_flag = 0; // CHECK-NEXT: return flag ? (((_d_x = _d_x * 2 + x * 0) , (x *= 2)) , (_d_x * x + x * _d_x)) : (((_d_x += 0) , (x += 1)) , (_d_x * x + x * _d_x)); // CHECK-NEXT: } @@ -113,52 +112,50 @@ double m_11(double x) { // CHECK: double m_11_darg0(double x) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: const size_t _d_maxN = 0; // CHECK-NEXT: const size_t maxN = 53; // CHECK-NEXT: bool _t0 = maxN < {{64U|64UL}}; -// CHECK-NEXT: const size_t _d_m = _t0 ? _d_maxN : {{0U|0UL}}; // CHECK-NEXT: const size_t m = _t0 ? maxN : {{64U|64UL}}; -// CHECK-NEXT: return _d_x * m + x * _d_m; +// CHECK-NEXT: return _d_x * m + x * 0; // CHECK-NEXT: } -int d_1(int x) { - int y = 4; +float d_1(float x) { + float y = 4; return y / y; // == 0 } -// CHECK: int d_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; +// CHECK: float d_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; // CHECK-NEXT: return (_d_y * y - y * _d_y) / (y * y); // CHECK-NEXT: } -int d_2(int x) { +float d_2(float x) { return 1 / 1; // == 0 } -// CHECK: int d_2_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float d_2_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return (0 * 1 - 1 * 0) / (1 * 1); // CHECK-NEXT: } -int d_3(int x) { +float d_3(float x) { return x / x; // == 0 } -// CHECK: int d_3_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float d_3_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return (_d_x * x - x * _d_x) / (x * x); // CHECK-NEXT: } -int d_4(int x) { - int y = 4; +float d_4(float x) { + float y = 4; return x / y / x / 3 / x; // == -1 / 3 / x / x / y } -// CHECK: int d_4_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; -// CHECK-NEXT: int _t0 = x / y; -// CHECK-NEXT: int _t1 = _t0 / x; -// CHECK-NEXT: int _t2 = _t1 / 3; +// CHECK: float d_4_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; +// CHECK-NEXT: float _t0 = x / y; +// CHECK-NEXT: float _t1 = _t0 / x; +// CHECK-NEXT: float _t2 = _t1 / 3; // CHECK-NEXT: return (((((((_d_x * y - x * _d_y) / (y * y)) * x - _t0 * _d_x) / (x * x)) * 3 - _t1 * 0) / (3 * 3)) * x - _t2 * _d_x) / (x * x); // CHECK-NEXT: } @@ -180,94 +177,94 @@ double issue25(double x, double y) { // return 1.; // } -int md_1(int x) { - int y = 4; +float md_1(float x) { + float y = 4; return x * x / x * y / y * 3 / 3; // == 1 } -// CHECK: int md_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: int y = 4; -// CHECK-NEXT: int _t0 = x * x; -// CHECK-NEXT: int _t1 = _t0 / x; -// CHECK-NEXT: int _t2 = _t1 * y; -// CHECK-NEXT: int _t3 = _t2 / y; -// CHECK-NEXT: int _t4 = _t3 * 3; +// CHECK: float md_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: float _d_y = 0; +// CHECK-NEXT: float y = 4; +// CHECK-NEXT: float _t0 = x * x; +// CHECK-NEXT: float _t1 = _t0 / x; +// CHECK-NEXT: float _t2 = _t1 * y; +// CHECK-NEXT: float _t3 = _t2 / y; +// CHECK-NEXT: float _t4 = _t3 * 3; // CHECK-NEXT: return ((((((((_d_x * x + x * _d_x) * x - _t0 * _d_x) / (x * x)) * y + _t1 * _d_y) * y - _t2 * _d_y) / (y * y)) * 3 + _t3 * 0) * 3 - _t4 * 0) / (3 * 3); // CHECK-NEXT: } -int m_1_darg0(int x); -int m_2_darg0(int x); -int m_3_darg0(int x); -int m_4_darg0(int x); -double m_5_darg0(int x); -float m_6_darg0(int x); +float m_1_darg0(float x); +float m_2_darg0(float x); +float m_3_darg0(float x); +float m_4_darg0(float x); +double m_5_darg0(float x); +float m_6_darg0(float x); double m_7_darg0(double x); double m_8_darg0(double x); double m_9_darg0(double x); double m_10_darg0(double x, bool flag); double m_11_darg0(double x); -int d_1_darg0(int x); -int d_2_darg0(int x); -int d_3_darg0(int x); -int d_4_darg0(int x); +float d_1_darg0(float x); +float d_2_darg0(float x); +float d_3_darg0(float x); +float d_4_darg0(float x); double issue25_darg0(double x, double y); -int md_1_darg0(int x); +float md_1_darg0(float x); int main () { - int x = 4; + float x = 4; clad::differentiate(m_1, 0); - printf("Result is = %d\n", m_1_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", m_1_darg0(1)); // CHECK-EXEC: Result is = 0.00 clad::differentiate(m_2, 0); - printf("Result is = %d\n", m_2_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", m_2_darg0(1)); // CHECK-EXEC: Result is = 0.00 clad::differentiate(m_3, 0); - printf("Result is = %d\n", m_3_darg0(1)); // CHECK-EXEC: Result is = 2 + printf("Result is = %.2f\n", m_3_darg0(1)); // CHECK-EXEC: Result is = 2.00 clad::differentiate(m_4, 0); - printf("Result is = %d\n", m_4_darg0(1)); // CHECK-EXEC: Result is = 36 + printf("Result is = %.2f\n", m_4_darg0(1)); // CHECK-EXEC: Result is = 36.00 clad::differentiate(m_5, 0); printf("Result is = %f\n", m_5_darg0(1)); // CHECK-EXEC: Result is = 3.14 clad::differentiate(m_6, 0); - printf("Result is = %f\n", m_6_darg0(1)); // CHECK-EXEC: Result is = 3 + printf("Result is = %f\n", m_6_darg0(1)); // CHECK-EXEC: Result is = 3.00 clad::differentiate(m_7, 0); - printf("Result is = %f\n", m_7_darg0(1)); // CHECK-EXEC: Result is = 4 + printf("Result is = %f\n", m_7_darg0(1)); // CHECK-EXEC: Result is = 4.00 clad::differentiate(m_8, 0); - printf("Result is = %f\n", m_8_darg0(1)); // CHECK-EXEC: Result is = 4 + printf("Result is = %f\n", m_8_darg0(1)); // CHECK-EXEC: Result is = 4.00 clad::differentiate(m_9, 0); - printf("Result is = %f\n", m_9_darg0(1)); // CHECK-EXEC: Result is = 8 + printf("Result is = %f\n", m_9_darg0(1)); // CHECK-EXEC: Result is = 8.00 clad::differentiate(m_10, 0); - printf("Result is = %f\n", m_10_darg0(1, true)); // CHECK-EXEC: Result is = 8 - printf("Result is = %f\n", m_10_darg0(1, false)); // CHECK-EXEC: Result is = 4 + printf("Result is = %f\n", m_10_darg0(1, true)); // CHECK-EXEC: Result is = 8.00 + printf("Result is = %f\n", m_10_darg0(1, false)); // CHECK-EXEC: Result is = 4.00 clad::differentiate(m_11<64>, 0); printf("Result is = %f\n", m_11_darg0(1)); // CHECK-EXEC: Result is = 53 clad::differentiate(d_1, 0); - printf("Result is = %d\n", d_1_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", d_1_darg0(1)); // CHECK-EXEC: Result is = 0.00 clad::differentiate(d_2, 0); - printf("Result is = %d\n", d_2_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", d_2_darg0(1)); // CHECK-EXEC: Result is = 0.00 clad::differentiate(d_3, 0); - printf("Result is = %d\n", d_3_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", d_3_darg0(1)); // CHECK-EXEC: Result is = 0.00 clad::differentiate(d_4, 0); - printf("Result is = %d\n", d_4_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", d_4_darg0(1)); // CHECK-EXEC: Result is = -0.08 //clad::differentiate(issue25, 0); //printf("Result is = %f\n", issue25_darg0(1.4, 2.3)); Result is = 1 clad::differentiate(md_1, 0); - printf("Result is = %d\n", md_1_darg0(1)); // CHECK-EXEC: Result is = 1 + printf("Result is = %.2f\n", md_1_darg0(1)); // CHECK-EXEC: Result is = 1.00 return 0; } diff --git a/test/FirstDerivative/BuiltinDerivatives.C b/test/FirstDerivative/BuiltinDerivatives.C index c154d0ce3..eb441cc51 100644 --- a/test/FirstDerivative/BuiltinDerivatives.C +++ b/test/FirstDerivative/BuiltinDerivatives.C @@ -166,8 +166,7 @@ double f10(float x, int y) { // CHECK: double f10_darg0(float x, int y) { // CHECK-NEXT: float _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: {{(clad::)?}}ValueAndPushforward _t0 = clad::custom_derivatives{{(::std)?}}::pow_pushforward(x, y, _d_x, _d_y); +// CHECK-NEXT: {{(clad::)?}}ValueAndPushforward _t0 = clad::custom_derivatives{{(::std)?}}::pow_pushforward(x, y, _d_x, 0); // CHECK-NEXT: return _t0.pushforward; // CHECK-NEXT: } diff --git a/test/FirstDerivative/ClassMethodCall.C b/test/FirstDerivative/ClassMethodCall.C index 33dd28263..56e0c01d2 100644 --- a/test/FirstDerivative/ClassMethodCall.C +++ b/test/FirstDerivative/ClassMethodCall.C @@ -13,60 +13,60 @@ public: virtual ~A() {} A() {} - __attribute__((always_inline)) int f(int x) { + __attribute__((always_inline)) float f(float x) { return x; } - //CHECK:{{[__attribute__((always_inline)) ]*}}int f_darg0(int x){{[ __attribute__((always_inline))]*}} { - //CHECK-NEXT: int _d_x = 1; + //CHECK:{{[__attribute__((always_inline)) ]*}}float f_darg0(float x){{[ __attribute__((always_inline))]*}} { + //CHECK-NEXT: float _d_x = 1; //CHECK-NEXT: A _d_this_obj; //CHECK-NEXT: A *_d_this = &_d_this_obj; //CHECK-NEXT: return _d_x; //CHECK-NEXT: } - int g_1(int x, int y) { + float g_1(float x, float y) { return x*x + y; } - //CHECK: int g_1_darg0(int x, int y) { - //CHECK-NEXT: int _d_x = 1; - //CHECK-NEXT: int _d_y = 0; + //CHECK: float g_1_darg0(float x, float y) { + //CHECK-NEXT: float _d_x = 1; + //CHECK-NEXT: float _d_y = 0; //CHECK-NEXT: A _d_this_obj; //CHECK-NEXT: A *_d_this = &_d_this_obj; //CHECK-NEXT: return _d_x * x + x * _d_x + _d_y; //CHECK-NEXT: } - //CHECK: int g_1_darg1(int x, int y) { - //CHECK-NEXT: int _d_x = 0; - //CHECK-NEXT: int _d_y = 1; + //CHECK: float g_1_darg1(float x, float y) { + //CHECK-NEXT: float _d_x = 0; + //CHECK-NEXT: float _d_y = 1; //CHECK-NEXT: A _d_this_obj; //CHECK-NEXT: A *_d_this = &_d_this_obj; //CHECK-NEXT: return _d_x * x + x * _d_x + _d_y; //CHECK-NEXT: } - int g_2(int x, int y) { + float g_2(float x, float y) { return x + y*y; } - //CHECK: int g_2_darg0(int x, int y) { - //CHECK-NEXT: int _d_x = 1; - //CHECK-NEXT: int _d_y = 0; + //CHECK: float g_2_darg0(float x, float y) { + //CHECK-NEXT: float _d_x = 1; + //CHECK-NEXT: float _d_y = 0; //CHECK-NEXT: A _d_this_obj; //CHECK-NEXT: A *_d_this = &_d_this_obj; //CHECK-NEXT: return _d_x + _d_y * y + y * _d_y; //CHECK-NEXT: } - //CHECK: int g_2_darg1(int x, int y) { - //CHECK-NEXT: int _d_x = 0; - //CHECK-NEXT: int _d_y = 1; + //CHECK: float g_2_darg1(float x, float y) { + //CHECK-NEXT: float _d_x = 0; + //CHECK-NEXT: float _d_y = 1; //CHECK-NEXT: A _d_this_obj; //CHECK-NEXT: A *_d_this = &_d_this_obj; //CHECK-NEXT: return _d_x + _d_y * y + y * _d_y; //CHECK-NEXT: } - int m(int x, int y) { + float m(float x, float y) { return f(x) + g_1(x, y); } diff --git a/test/FirstDerivative/CodeGenSimple.C b/test/FirstDerivative/CodeGenSimple.C index 4ff77e806..7513b58de 100644 --- a/test/FirstDerivative/CodeGenSimple.C +++ b/test/FirstDerivative/CodeGenSimple.C @@ -6,41 +6,40 @@ #include "clad/Differentiator/Differentiator.h" extern "C" int printf(const char* fmt, ...); -int f_1(int x) { +float f_1(float x) { printf("I am being run!\n"); return x * x; } -// CHECK: int f_1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float f_1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: printf("I am being run!\n"); // CHECK-NEXT: return _d_x * x + x * _d_x; // CHECK-NEXT: } -int f_2(int x) { +float f_2(float x) { return (1 * x + x * 1); } -int f_3(int x) { +float f_3(float x) { return 1 * x; } -int f_4(int x) { +float f_4(float x) { return (0 * x + 1 * 1); } extern "C" int printf(const char* fmt, ...); -int f_1_darg0(int x); +float f_1_darg0(float x); double sq_defined_later(double); int main() { - int x = 4; clad::differentiate(f_1, 0); auto df = clad::differentiate(sq_defined_later, "x"); - printf("Result is = %d\n", f_1_darg0(1)); // CHECK-EXEC: Result is = 2 - printf("Result is = %f\n", df.execute(3)); // CHECK-EXEC: Result is = 6 + printf("Result is = %.2f\n", f_1_darg0(1)); // CHECK-EXEC: Result is = 2.00 + printf("Result is = %.2f\n", df.execute(3)); // CHECK-EXEC: Result is = 6.00 return 0; } diff --git a/test/FirstDerivative/DiffInterface.C b/test/FirstDerivative/DiffInterface.C index dda26f136..5a10674bb 100644 --- a/test/FirstDerivative/DiffInterface.C +++ b/test/FirstDerivative/DiffInterface.C @@ -6,69 +6,69 @@ extern "C" int printf(const char* fmt, ...); -int f_1(float y) { - int x = 1, z = 3; +float f_1(float y) { + float x = 1, z = 3; return x * y * z; // x * z } -// CHECK: int f_1_darg0(float y) { +// CHECK: float f_1_darg0(float y) { // CHECK-NEXT: float _d_y = 1; -// CHECK-NEXT: int _d_x = 0, _d_z = 0; -// CHECK-NEXT: int x = 1, z = 3; +// CHECK-NEXT: float _d_x = 0, _d_z = 0; +// CHECK-NEXT: float x = 1, z = 3; // CHECK-NEXT: float _t0 = x * y; // CHECK-NEXT: return (_d_x * y + x * _d_y) * z + _t0 * _d_z; // CHECK-NEXT: } -int f_2(int x, float y, int z) { +float f_2(float x, float y, float z) { return x * y * z; // y * z; } -// CHECK: int f_2_darg0(int x, float y, int z) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float f_2_darg0(float x, float y, float z) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: float _d_y = 0; -// CHECK-NEXT: int _d_z = 0; +// CHECK-NEXT: float _d_z = 0; // CHECK-NEXT: float _t0 = x * y; // CHECK-NEXT: return (_d_x * y + x * _d_y) * z + _t0 * _d_z; // CHECK-NEXT: } // x * z -// CHECK: int f_2_darg1(int x, float y, int z) { -// CHECK-NEXT: int _d_x = 0; +// CHECK: float f_2_darg1(float x, float y, float z) { +// CHECK-NEXT: float _d_x = 0; // CHECK-NEXT: float _d_y = 1; -// CHECK-NEXT: int _d_z = 0; +// CHECK-NEXT: float _d_z = 0; // CHECK-NEXT: float _t0 = x * y; // CHECK-NEXT: return (_d_x * y + x * _d_y) * z + _t0 * _d_z; // CHECK-NEXT: } // x * y -// CHECK: int f_2_darg2(int x, float y, int z) { -// CHECK-NEXT: int _d_x = 0; +// CHECK: float f_2_darg2(float x, float y, float z) { +// CHECK-NEXT: float _d_x = 0; // CHECK-NEXT: float _d_y = 0; -// CHECK-NEXT: int _d_z = 1; +// CHECK-NEXT: float _d_z = 1; // CHECK-NEXT: float _t0 = x * y; // CHECK-NEXT: return (_d_x * y + x * _d_y) * z + _t0 * _d_z; // CHECK-NEXT: } -int f_3() { - int x = 1, z = 3; +float f_3() { + float x = 1, z = 3; float y = 2; return x * y * z; // should not be differentiated } -int f_no_definition(int x); +float f_no_definition(float x); -int f_redeclared(int x) { +float f_redeclared(float x) { return x; } -int f_redeclared(int x); +float f_redeclared(float x); -// CHECK: int f_redeclared_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float f_redeclared_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return _d_x; // CHECK: } -int f_try_catch(int x) +float f_try_catch(float x) try { // expected-warning {{attempted to differentiate unsupported statement, no changes applied}} return x; } @@ -79,8 +79,8 @@ int f_try_catch(int x) return 1; } -// CHECK: int f_try_catch_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float f_try_catch_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: try { // CHECK-NEXT: return x; // CHECK-NEXT: } catch (int) { diff --git a/test/FirstDerivative/FunctionCalls.C b/test/FirstDerivative/FunctionCalls.C index 79e5a6b8f..0fd6e308b 100644 --- a/test/FirstDerivative/FunctionCalls.C +++ b/test/FirstDerivative/FunctionCalls.C @@ -8,7 +8,7 @@ #include int printf(const char* fmt, ...); -int no_body(int x); +int no_body(float x); int custom_fn(int x); float custom_fn(float x); int custom_fn(); @@ -83,21 +83,21 @@ float test_3() { // CHECK-NOT: float test_3_darg0() { -float test_4(int x) { +float test_4(float x) { return overloaded(); } -// CHECK: float test_4_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float test_4_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return 0; // CHECK-NEXT: } -float test_5(int x) { +float test_5(float x) { return no_body(x); } -// CHECK: float test_5_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float test_5_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: {{(clad::)?}}ValueAndPushforward _t0 = clad::custom_derivatives::no_body_pushforward(x, _d_x); // CHECK-NEXT: return _t0.pushforward; // CHECK-NEXT: } @@ -125,19 +125,16 @@ double test_7(double i, double j) { return res; } -// CHECK: void increment_pushforward(int &i, int &_d_i); +// CHECK: void increment_pushforward(int &i); // CHECK: double test_7_darg0(double i, double j) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: double res = 0; -// CHECK-NEXT: { -// CHECK-NEXT: int _d_i0 = 0; -// CHECK-NEXT: for (int i0 = 0; i0 < 5; increment_pushforward(i0, _d_i0)) { -// CHECK-NEXT: _d_res += _d_i0 * j + i0 * _d_j; -// CHECK-NEXT: res += i0 * j; -// CHECK-NEXT: } +// CHECK-NEXT: for (int i0 = 0; i0 < 5; increment_pushforward(i0)) { +// CHECK-NEXT: _d_res += 0 * j + i0 * _d_j; +// CHECK-NEXT: res += i0 * j; // CHECK-NEXT: } // CHECK-NEXT: return _d_res; // CHECK-NEXT: } @@ -156,7 +153,6 @@ double test_8(double x) { // CHECK: double test_8_darg0(double x) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: E _d_e; // CHECK-NEXT: E e; // CHECK-NEXT: {{(clad::)?}}ValueAndPushforward _t0 = func_with_enum_pushforward(x, e, _d_x); // CHECK-NEXT: return _t0.pushforward; @@ -175,7 +171,7 @@ int main () { clad::differentiate(test_8); // expected-error {{Both enable and disable TBR options are specified.}} return 0; -// CHECK: void increment_pushforward(int &i, int &_d_i) { +// CHECK: void increment_pushforward(int &i) { // CHECK-NEXT: ++i; // CHECK-NEXT: } diff --git a/test/FirstDerivative/FunctionCallsWithResults.C b/test/FirstDerivative/FunctionCallsWithResults.C index 4549e4d85..58d73f02b 100644 --- a/test/FirstDerivative/FunctionCallsWithResults.C +++ b/test/FirstDerivative/FunctionCallsWithResults.C @@ -232,7 +232,7 @@ void modifyArr(double* arr, int n, double val) { arr[i] = val; } -// CHECK: void modifyArr_pushforward(double *arr, int n, double val, double *_d_arr, int _d_n, double _d_val); +// CHECK: void modifyArr_pushforward(double *arr, int n, double val, double *_d_arr, double _d_val); double sum(double* arr, int n) { double val = 0; @@ -241,14 +241,14 @@ double sum(double* arr, int n) { return val; } -// CHECK: clad::ValueAndPushforward sum_pushforward(double *arr, int n, double *_d_arr, int _d_n); +// CHECK: clad::ValueAndPushforward sum_pushforward(double *arr, int n, double *_d_arr); double check_and_return(double x, char c) { if (c == 'a') return x; return 1; } -// CHECK: clad::ValueAndPushforward check_and_return_pushforward(double x, char c, double _d_x, char _d_c); +// CHECK: clad::ValueAndPushforward check_and_return_pushforward(double x, char c, double _d_x); double fn8(double i, double j) { double arr[5] = {}; @@ -261,9 +261,9 @@ double fn8(double i, double j) { // CHECK-NEXT: double _d_j = 0; // CHECK-NEXT: double _d_arr[5] = {}; // CHECK-NEXT: double arr[5] = {}; -// CHECK-NEXT: modifyArr_pushforward(arr, 5, i * j, _d_arr, 0, _d_i * j + i * _d_j); -// CHECK-NEXT: clad::ValueAndPushforward _t0 = sum_pushforward(arr, 5, _d_arr, 0); -// CHECK-NEXT: clad::ValueAndPushforward _t1 = check_and_return_pushforward(_t0.value, 'a', _t0.pushforward, 0); +// CHECK-NEXT: modifyArr_pushforward(arr, 5, i * j, _d_arr, _d_i * j + i * _d_j); +// CHECK-NEXT: clad::ValueAndPushforward _t0 = sum_pushforward(arr, 5, _d_arr); +// CHECK-NEXT: clad::ValueAndPushforward _t1 = check_and_return_pushforward(_t0.value, 'a', _t0.pushforward); // CHECK-NEXT: double &_t2 = _t1.value; // CHECK-NEXT: double _t3 = std::tanh(1.); // CHECK-NEXT: return _t1.pushforward * _t3 + _t2 * 0; @@ -281,7 +281,6 @@ double fn9 (double i, double j) { // CHECK: double fn9_darg0(double i, double j) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: const int _d_k = 0; // CHECK-NEXT: const int k = 1; // CHECK-NEXT: clad::ValueAndPushforward _t0 = g_pushforward(i, _d_i); // CHECK-NEXT: clad::ValueAndPushforward _t1 = g_pushforward(j, _d_j); @@ -394,30 +393,24 @@ int main () { // CHECK-NEXT: return {i + j, _d_i + _d_j}; // CHECK-NEXT: } -// CHECK: void modifyArr_pushforward(double *arr, int n, double val, double *_d_arr, int _d_n, double _d_val) { -// CHECK-NEXT: { -// CHECK-NEXT: int _d_i = 0; -// CHECK-NEXT: for (int i = 0; i < n; ++i) { -// CHECK-NEXT: _d_arr[i] = _d_val; -// CHECK-NEXT: arr[i] = val; -// CHECK-NEXT: } +// CHECK: void modifyArr_pushforward(double *arr, int n, double val, double *_d_arr, double _d_val) { +// CHECK-NEXT: for (int i = 0; i < n; ++i) { +// CHECK-NEXT: _d_arr[i] = _d_val; +// CHECK-NEXT: arr[i] = val; // CHECK-NEXT: } // CHECK-NEXT: } -// CHECK: clad::ValueAndPushforward sum_pushforward(double *arr, int n, double *_d_arr, int _d_n) { +// CHECK: clad::ValueAndPushforward sum_pushforward(double *arr, int n, double *_d_arr) { // CHECK-NEXT: double _d_val = 0; // CHECK-NEXT: double val = 0; -// CHECK-NEXT: { -// CHECK-NEXT: int _d_i = 0; -// CHECK-NEXT: for (int i = 0; i < n; ++i) { -// CHECK-NEXT: _d_val += _d_arr[i]; -// CHECK-NEXT: val += arr[i]; -// CHECK-NEXT: } +// CHECK-NEXT: for (int i = 0; i < n; ++i) { +// CHECK-NEXT: _d_val += _d_arr[i]; +// CHECK-NEXT: val += arr[i]; // CHECK-NEXT: } // CHECK-NEXT: return {val, _d_val}; // CHECK-NEXT: } -// CHECK: clad::ValueAndPushforward check_and_return_pushforward(double x, char c, double _d_x, char _d_c) { +// CHECK: clad::ValueAndPushforward check_and_return_pushforward(double x, char c, double _d_x) { // CHECK-NEXT: if (c == 'a') // CHECK-NEXT: return {x, _d_x}; // CHECK-NEXT: return {1, 0}; diff --git a/test/FirstDerivative/FunctionsInNamespaces.C b/test/FirstDerivative/FunctionsInNamespaces.C index 18ef5a817..a7cee6624 100644 --- a/test/FirstDerivative/FunctionsInNamespaces.C +++ b/test/FirstDerivative/FunctionsInNamespaces.C @@ -7,20 +7,20 @@ #include "../TestUtils.h" namespace function_namespace10 { - int func1(int x) { + float func1(float x) { return x*x*x + x*x; } - int func2(int x) { + float func2(float x) { return x*x + x; } namespace function_namespace11 { - int func3(int x, int y) { + float func3(float x, float y) { return x*x*x + y*y; } - int func4(int x, int y) { + float func4(float x, float y) { return x*x + y; } } @@ -35,21 +35,21 @@ namespace function_namespace2 { return x*x + x; } - int func3(int x, int y) { + float func3(float x, float y) { return function_namespace10::function_namespace11::func4(x, y); } } -int test_1(int x, int y) { +float test_1(float x, float y) { return function_namespace2::func3(x, y); } -// CHECK: clad::ValueAndPushforward func3_pushforward(int x, int y, int _d_x, int _d_y); +// CHECK: clad::ValueAndPushforward func3_pushforward(float x, float y, float _d_x, float _d_y); -// CHECK: int test_1_darg1(int x, int y) { -// CHECK-NEXT: int _d_x = 0; -// CHECK-NEXT: int _d_y = 1; -// CHECK-NEXT: clad::ValueAndPushforward _t0 = func3_pushforward(x, y, _d_x, _d_y); +// CHECK: float test_1_darg1(float x, float y) { +// CHECK-NEXT: float _d_x = 0; +// CHECK-NEXT: float _d_y = 1; +// CHECK-NEXT: clad::ValueAndPushforward _t0 = func3_pushforward(x, y, _d_x, _d_y); // CHECK-NEXT: return _t0.pushforward; // CHECK-NEXT: } @@ -92,14 +92,14 @@ int main () { INIT_DIFFERENTIATE(test_1, 1); INIT_DIFFERENTIATE(fn1, "j"); - TEST_DIFFERENTIATE(test_1, 3, 5); // CHECK-EXEC: {1} + TEST_DIFFERENTIATE(test_1, 3, 5); // CHECK-EXEC: {1.00} TEST_DIFFERENTIATE(fn1, 3, 5); // CHECK-EXEC: {2.00} - // CHECK: clad::ValueAndPushforward func4_pushforward(int x, int y, int _d_x, int _d_y); + // CHECK: clad::ValueAndPushforward func4_pushforward(float x, float y, float _d_x, float _d_y); - // CHECK: clad::ValueAndPushforward func3_pushforward(int x, int y, int _d_x, int _d_y) { - // CHECK-NEXT: clad::ValueAndPushforward _t0 = func4_pushforward(x, y, _d_x, _d_y); + // CHECK: clad::ValueAndPushforward func3_pushforward(float x, float y, float _d_x, float _d_y) { + // CHECK-NEXT: clad::ValueAndPushforward _t0 = func4_pushforward(x, y, _d_x, _d_y); // CHECK-NEXT: return {_t0.value, _t0.pushforward}; // CHECK-NEXT: } @@ -110,7 +110,7 @@ int main () { // CHECK-NEXT: return {3, 0}; // CHECK-NEXT: } - // CHECK: clad::ValueAndPushforward func4_pushforward(int x, int y, int _d_x, int _d_y) { + // CHECK: clad::ValueAndPushforward func4_pushforward(float x, float y, float _d_x, float _d_y) { // CHECK-NEXT: return {x * x + y, _d_x * x + x * _d_x + _d_y}; // CHECK-NEXT: } diff --git a/test/FirstDerivative/FunctionsOneVariable.C b/test/FirstDerivative/FunctionsOneVariable.C index 33783d7a0..6b617874b 100644 --- a/test/FirstDerivative/FunctionsOneVariable.C +++ b/test/FirstDerivative/FunctionsOneVariable.C @@ -34,12 +34,12 @@ float f_simple(float x) { //CHECK-NEXT: return _d__d__d_x * x + _d__d_x0 * _d_x + _d__d_x00 * _d_x0 + _d_x00 * _d__d_x + _d__d_x * _d_x00 + _d_x0 * _d__d_x00 + _d_x * _d__d_x0 + x * _d__d__d_x; //CHECK-NEXT: } -int f_simple_negative(int x) { +float f_simple_negative(float x) { // printf("This is f(x).\n"); return -x*x; } -// CHECK: int f_simple_negative_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float f_simple_negative_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: return -_d_x * x + -x * _d_x; // CHECK-NEXT: } diff --git a/test/FirstDerivative/Loops.C b/test/FirstDerivative/Loops.C index 03257ff34..a4cdaef0d 100644 --- a/test/FirstDerivative/Loops.C +++ b/test/FirstDerivative/Loops.C @@ -15,15 +15,11 @@ double f1(double x, int y) { double f1_darg0(double x, int y); // CHECK: double f1_darg0(double x, int y) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: int _d_y = 0; // CHECK-NEXT: double _d_r = 0.; // CHECK-NEXT: double r = 1.; -// CHECK-NEXT: { -// CHECK-NEXT: int _d_i = 0; -// CHECK-NEXT: for (int i = 0; i < y; (_d_i = _d_i + 0) , (i = i + 1)) { -// CHECK-NEXT: _d_r = _d_r * x + r * _d_x; -// CHECK-NEXT: r = r * x; -// CHECK-NEXT: } +// CHECK-NEXT: for (int i = 0; i < y; i = i + 1) { +// CHECK-NEXT: _d_r = _d_r * x + r * _d_x; +// CHECK-NEXT: r = r * x; // CHECK-NEXT: } // CHECK-NEXT: return _d_r; // CHECK-NEXT: } @@ -43,15 +39,11 @@ double f1_inc(double x, int y) { double f1_inc_darg0(double x, int y); //CHECK: double f1_inc_darg0(double x, int y) { //CHECK-NEXT: double _d_x = 1; -//CHECK-NEXT: int _d_y = 0; //CHECK-NEXT: double _d_r = 0.; //CHECK-NEXT: double r = 1.; -//CHECK-NEXT: { -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: for (int i = 0; i < y; i++) { -//CHECK-NEXT: _d_r = _d_r * x + r * _d_x; -//CHECK-NEXT: r *= x; -//CHECK-NEXT: } +//CHECK-NEXT: for (int i = 0; i < y; i++) { +//CHECK-NEXT: _d_r = _d_r * x + r * _d_x; +//CHECK-NEXT: r *= x; //CHECK-NEXT: } //CHECK-NEXT: return _d_r; //CHECK-NEXT: } @@ -66,14 +58,10 @@ double f2(double x, int y) { double f2_darg0(double x, int y); // CHECK: double f2_darg0(double x, int y) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: int _d_y = 0; -// CHECK-NEXT: { -// CHECK-NEXT: int _d_i = 0; -// CHECK-NEXT: for (int i = 0; i < y; (_d_i = _d_i + 0) , (i = i + 1)) { -// CHECK-NEXT: _d_x = _d_x * x + x * _d_x; -// CHECK-NEXT: x = x * x; -// CHECK-NEXT: } -// CHECK-NEXT: } +// CHECK-NEXT: for (int i = 0; i < y; i = i + 1) { +// CHECK-NEXT: _d_x = _d_x * x + x * _d_x; +// CHECK-NEXT: x = x * x; +// CHECK-NEXT: } // CHECK-NEXT: return _d_x; // CHECK-NEXT: } // _d_x(i) = 2 * _d_x(i - 1) * x(i - 1) @@ -92,13 +80,9 @@ double f2_inc(double x, int y) { double f2_inc_darg0(double x, int y); //CHECK: double f2_inc_darg0(double x, int y) { //CHECK-NEXT: double _d_x = 1; -//CHECK-NEXT: int _d_y = 0; -//CHECK-NEXT: { -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: for (int i = 0; i < y; i++) { -//CHECK-NEXT: _d_x = _d_x * x + x * _d_x; -//CHECK-NEXT: x *= x; -//CHECK-NEXT: } +//CHECK-NEXT: for (int i = 0; i < y; i++) { +//CHECK-NEXT: _d_x = _d_x * x + x * _d_x; +//CHECK-NEXT: x *= x; //CHECK-NEXT: } //CHECK-NEXT: return _d_x; //CHECK-NEXT: } @@ -114,16 +98,10 @@ double f3(double x, int y) { double f3_darg0(double x, int y); // CHECK: double f3_darg0(double x, int y) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: int _d_y = 0; // CHECK-NEXT: double _d_r = 0.; // CHECK-NEXT: double r = 1.; -// CHECK-NEXT: { -// CHECK-NEXT: int _d_i = 0; -// CHECK-NEXT: for (int i = 0; i < y; (_d_r = _d_r * x + r * _d_x) , (r = r * x)) { -// CHECK-NEXT: _d_i = _d_i + 0; -// CHECK-NEXT: i = i + 1; -// CHECK-NEXT: } -// CHECK-NEXT: } +// CHECK-NEXT: for (int i = 0; i < y; (_d_r = _d_r * x + r * _d_x) , (r = r * x)) +// CHECK-NEXT: i = i + 1; // CHECK-NEXT: return _d_r; // CHECK-NEXT: } // = y * pow(x, y-1) @@ -138,14 +116,10 @@ double f3_inc(double x, int y) { double f3_inc_darg0(double x, int y); //CHECK: double f3_inc_darg0(double x, int y) { //CHECK-NEXT: double _d_x = 1; -//CHECK-NEXT: int _d_y = 0; //CHECK-NEXT: double _d_r = 0.; //CHECK-NEXT: double r = 1.; -//CHECK-NEXT: { -//CHECK-NEXT: int _d_i = 0; -//CHECK-NEXT: for (int i = 0; i < y; (_d_r = _d_r * x + r * _d_x) , (r *= x)) -//CHECK-NEXT: i++; -//CHECK-NEXT: } +//CHECK-NEXT: for (int i = 0; i < y; (_d_r = _d_r * x + r * _d_x) , (r *= x)) +//CHECK-NEXT: i++; //CHECK-NEXT: return _d_r; //CHECK-NEXT: } @@ -161,26 +135,19 @@ double f4(double x, int y) { double f4_darg0(double x, int y); // CHECK: double f4_darg0(double x, int y) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: int _d_y = 0; // CHECK-NEXT: double _d_r = 0; // CHECK-NEXT: double r = 1; -// CHECK-NEXT: int _d_i; // CHECK-NEXT: int i; -// CHECK-NEXT: { -// CHECK-NEXT: _d_i = 0; -// CHECK-NEXT: for (i = 0; i < y; [&] { -// CHECK-NEXT: ValueAndPushforward _t2 = clad::custom_derivatives::sin_pushforward(x, _d_x); -// CHECK-NEXT: double &_t3 = _t2.value; -// CHECK-NEXT: _d_r = _d_r * _t3 + r * _t2.pushforward; -// CHECK-NEXT: r = r * _t3; +// CHECK-NEXT: for (i = 0; i < y; [&] { +// CHECK-NEXT: ValueAndPushforward _t2 = clad::custom_derivatives::sin_pushforward(x, _d_x); +// CHECK-NEXT: double &_t3 = _t2.value; +// CHECK-NEXT: _d_r = _d_r * _t3 + r * _t2.pushforward; +// CHECK-NEXT: r = r * _t3; // CHECK: } -// CHECK: ()) { -// CHECK-NEXT: _d_i = _d_i + 0; -// CHECK-NEXT: i = i + 1; -// CHECK-NEXT: } -// CHECK-NEXT: } -// CHECK-NEXT: return _d_r; -// CHECK-NEXT: } +// CHECK: ()) +// CHECK-NEXT: i = i + 1; +// CHECK-NEXT: return _d_r; +// CHECK-NEXT: } // = y * cos(x) * pow(sin(x), y-1) = y/2.0 * sin(2*x) * pow(sin(x), y-2) double f4_inc(double x, int y) { @@ -194,23 +161,18 @@ double f4_inc(double x, int y) { double f4_inc_darg0(double x, int y); //CHECK: double f4_inc_darg0(double x, int y) { //CHECK-NEXT: double _d_x = 1; -//CHECK-NEXT: int _d_y = 0; //CHECK-NEXT: double _d_r = 0; //CHECK-NEXT: double r = 1; -//CHECK-NEXT: int _d_i; //CHECK-NEXT: int i; -//CHECK-NEXT: { -//CHECK-NEXT: _d_i = 0; -//CHECK-NEXT: for (i = 0; i < y; [&] { -//CHECK-NEXT: ValueAndPushforward _t3 = clad::custom_derivatives::sin_pushforward(x, _d_x); -//CHECK-NEXT: double &_t4 = _t3.pushforward; -//CHECK-NEXT: double &_t5 = _t3.value; -//CHECK-NEXT: _d_r = _d_r * _t5 + r * _t4; -//CHECK-NEXT: r *= _t5; +//CHECK-NEXT: for (i = 0; i < y; [&] { +//CHECK-NEXT: ValueAndPushforward _t3 = clad::custom_derivatives::sin_pushforward(x, _d_x); +//CHECK-NEXT: double &_t4 = _t3.pushforward; +//CHECK-NEXT: double &_t5 = _t3.value; +//CHECK-NEXT: _d_r = _d_r * _t5 + r * _t4; +//CHECK-NEXT: r *= _t5; //CHECK: } //CHECK: ()) -//CHECK-NEXT: i++; -//CHECK-NEXT: } +//CHECK-NEXT: i++; //CHECK-NEXT: return _d_r; //CHECK-NEXT: } @@ -227,7 +189,6 @@ double fn5(double i, double j) { // CHECK: double fn5_darg0(double i, double j) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_b = 0; // CHECK-NEXT: int b = 3; // CHECK-NEXT: double _d_a = 0; // CHECK-NEXT: double a = 0; @@ -235,7 +196,6 @@ double fn5(double i, double j) { // CHECK-NEXT: { // CHECK-NEXT: _d_a += _d_i; // CHECK-NEXT: a += i; -// CHECK-NEXT: _d_b -= 0; // CHECK-NEXT: b -= 1; // CHECK-NEXT: } // CHECK-NEXT: return _d_a; @@ -254,14 +214,12 @@ double fn6(double i, double j) { // CHECK: double fn6_darg0(double i, double j) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_b = 0; // CHECK-NEXT: int b = 3; // CHECK-NEXT: double _d_a = 0; // CHECK-NEXT: double a = 0; // CHECK-NEXT: do { // CHECK-NEXT: _d_a += _d_i; // CHECK-NEXT: a += i; -// CHECK-NEXT: _d_b -= 0; // CHECK-NEXT: b -= 1; // CHECK-NEXT: } while (b); // CHECK-NEXT: return _d_a; @@ -284,25 +242,21 @@ double fn7(double i, double j) { // CHECK: double fn7_darg0(double i, double j) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_b = 0; // CHECK-NEXT: int b = 3; // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: double res = 0; // CHECK-NEXT: while (double a = b) // CHECK-NEXT: { -// CHECK-NEXT: double _d_a = _d_b; +// CHECK-NEXT: double _d_a = 0; // CHECK-NEXT: _d_a += _d_i; // CHECK-NEXT: a += i; // CHECK-NEXT: _d_res += _d_a; // CHECK-NEXT: res += a; -// CHECK-NEXT: _d_b -= 0; // CHECK-NEXT: b -= 1; // CHECK-NEXT: } -// CHECK-NEXT: _d_b = 0; // CHECK-NEXT: b = 1; // CHECK-NEXT: while (b) // CHECK-NEXT: { -// CHECK-NEXT: _d_b -= 0; // CHECK-NEXT: b -= 1; // CHECK-NEXT: } // CHECK-NEXT: return _d_res; @@ -339,14 +293,11 @@ double fn9(double i, double j) { // CHECK: double fn9_darg0(double i, double j) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: int counter = 4; // CHECK-NEXT: double _d_a = _d_i * j + i * _d_j; // CHECK-NEXT: double a = i * j; // CHECK-NEXT: while (int num = counter) // CHECK-NEXT: { -// CHECK-NEXT: int _d_num = _d_counter; -// CHECK-NEXT: _d_counter -= 0; // CHECK-NEXT: counter -= 1; // CHECK-NEXT: if (num == 2) // CHECK-NEXT: continue; @@ -372,23 +323,18 @@ double fn10(double x, size_t n) { double fn10_darg0(double x, size_t n); // CHECK: double fn10_darg0(double x, size_t n) { // CHECK-NEXT: double _d_x = 1; -// CHECK-NEXT: size_t _d_n = 0; // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: double res = 0; -// CHECK-NEXT: { -// CHECK-NEXT: size_t _d_count = 0; -// CHECK-NEXT: size_t _d_max_count = _d_n; -// CHECK-NEXT: for (size_t count = 0; {{.*}}max_count{{.*}}; ++count) { -// CHECK-NEXT: if (count >= max_count) -// CHECK-NEXT: break; -// CHECK-NEXT: { -// CHECK-NEXT: double _d_y = _d_x; -// CHECK-NEXT: if (double y = x) { -// CHECK-NEXT: _d_res += _d_y * y + y * _d_y; -// CHECK-NEXT: res += y * y; -// CHECK-NEXT: } -// CHECK-NEXT: } +// CHECK-NEXT: for (size_t count = 0; {{.*}}max_count{{.*}}; ++count) { +// CHECK-NEXT: if (count >= max_count) +// CHECK-NEXT: break; +// CHECK-NEXT: { +// CHECK-NEXT: double _d_y = _d_x; +// CHECK-NEXT: if (double y = x) { +// CHECK-NEXT: _d_res += _d_y * y + y * _d_y; +// CHECK-NEXT: res += y * y; // CHECK-NEXT: } +// CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: return _d_res; // CHECK-NEXT: } diff --git a/test/FirstDerivative/NonContinuous.C b/test/FirstDerivative/NonContinuous.C index b9359dfe8..75039193b 100644 --- a/test/FirstDerivative/NonContinuous.C +++ b/test/FirstDerivative/NonContinuous.C @@ -10,27 +10,27 @@ // // f'(x)= | 2*x, x >= 0 // | -2*x, x < 0 -int f(int x) { +float f(float x) { if (x < 0) return -x*x; return x*x; } -// CHECK: int f_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float f_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: if (x < 0) // CHECK-NEXT: return -_d_x * x + -x * _d_x; // CHECK-NEXT: return _d_x * x + x * _d_x; // CHECK-NEXT: } // Semantically equivallent to f(x), but implemented differently. -int f1(int x) { +float f1(float x) { if (x < 0) return -x*x; else return x*x; } -// CHECK: int f1_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float f1_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: if (x < 0) // CHECK-NEXT: return -_d_x * x + -x * _d_x; // CHECK-NEXT: else @@ -42,33 +42,32 @@ int f1(int x) { // // g'(y)= 0 -int g(long y) { +float g(double y) { if (y) return 1; else return 2; } -// CHECK: int g_darg0(long y) { -// CHECK-NEXT: long _d_y = 1; +// CHECK: float g_darg0(double y) { +// CHECK-NEXT: double _d_y = 1; // CHECK-NEXT: if (y) // CHECK-NEXT: return 0; // CHECK-NEXT: else // CHECK-NEXT: return 0; // CHECK-NEXT: } -int f_darg0(int x); -int f1_darg0(int x); -int g_darg0(long y); +float f_darg0(float x); +float f1_darg0(float x); +float g_darg0(double y); int main () { - int x = 4; clad::differentiate(f, 0); // expected-no-diagnostics - printf("Result is = %d\n", f_darg0(1)); // CHECK-EXEC: Result is = 2 + printf("Result is = %.2f\n", f_darg0(1)); // CHECK-EXEC: Result is = 2 clad::differentiate(f1, 0); - printf("Result is = %d\n", f1_darg0(1)); // CHECK-EXEC: Result is = 2 + printf("Result is = %.2f\n", f1_darg0(1)); // CHECK-EXEC: Result is = 2 clad::differentiate(g, 0); - printf("Result is = %d\n", g_darg0(1)); // CHECK-EXEC: Result is = 0 + printf("Result is = %.2f\n", g_darg0(1)); // CHECK-EXEC: Result is = 0 return 0; } diff --git a/test/FirstDerivative/Overloads.C b/test/FirstDerivative/Overloads.C index 025fd7e0b..3f56e945c 100644 --- a/test/FirstDerivative/Overloads.C +++ b/test/FirstDerivative/Overloads.C @@ -95,10 +95,9 @@ int main () { //CHECK-NEXT: } auto f1_darg0_int_B = clad::differentiate((int(B::*)(int))&B::f1, 0); //CHECK: int f1_darg0(int x) { -//CHECK-NEXT: int _d_x = 1; // CHECK-NEXT: B _d_this_obj; // CHECK-NEXT: B *_d_this = &_d_this_obj; -//CHECK-NEXT: return _d_x; +//CHECK-NEXT: return 0; //CHECK-NEXT: } // resolve to float(B::*)(float) //auto f1_darg0_double_B = clad::differentiate((double(B::*)(double))&B::f1, 0); // ?EXPECTED-ERROR {{address of overloaded function 'f1' does not match required type 'double (double)'}} @@ -115,7 +114,7 @@ int main () { printf("Result is = %f\n", f1_darg0_float_A.execute(a, 2.0)); // CHECK-EXEC: Result is = 3.0000 printf("Result is = %f\n", f1_darg0_double_A.execute(a, 2.0)); // CHECK-EXEC: Result is = 4.0000 printf("Result is = %f\n", f1_darg0_float_B.execute(b, 2.0)); // CHECK-EXEC: Result is = 5.0000 - printf("Result is = %i\n", f1_darg0_int_B.execute(b, 2)); // CHECK-EXEC: Result is = 1 + printf("Result is = %i\n", f1_darg0_int_B.execute(b, 2)); // CHECK-EXEC: Result is = 0 //printf("Result is %s\n", f1_darg0_double_B.execute(b, 2.0)<1 ? "float" : "other"); // -CHECK-EXEC: Result is float printf("Result is %s\n", f1_darg0_float_B1.execute(b1, 2.0f)<1 ? "double" : "other"); // CHECK-EXEC: Result is double printf("Result is = %f\n", f1_darg0_double_B1.execute(b1, 2.0)); // CHECK-EXEC: Result is = 6.0000 diff --git a/test/FirstDerivative/Recursive.C b/test/FirstDerivative/Recursive.C index dd103aafd..ae951f860 100644 --- a/test/FirstDerivative/Recursive.C +++ b/test/FirstDerivative/Recursive.C @@ -7,71 +7,70 @@ extern "C" int printf(const char* fmt, ...); -int f_dec(int arg) { +float f_dec(float arg) { if (arg == 0) return arg; else return f_dec(arg-1); } -// CHECK: clad::ValueAndPushforward f_dec_pushforward(int arg, int _d_arg); +// CHECK: clad::ValueAndPushforward f_dec_pushforward(float arg, float _d_arg); -// CHECK: int f_dec_darg0(int arg) { -// CHECK-NEXT: int _d_arg = 1; +// CHECK: float f_dec_darg0(float arg) { +// CHECK-NEXT: float _d_arg = 1; // CHECK-NEXT: if (arg == 0) // CHECK-NEXT: return _d_arg; // CHECK-NEXT: else { -// CHECK-NEXT: clad::ValueAndPushforward _t0 = f_dec_pushforward(arg - 1, _d_arg - 0); +// CHECK-NEXT: clad::ValueAndPushforward _t0 = f_dec_pushforward(arg - 1, _d_arg - 0); // CHECK-NEXT: return _t0.pushforward; // CHECK-NEXT: } // CHECK-NEXT: } -int f_dec_darg0(int arg); +float f_dec_darg0(float arg); -int f_pow(int arg, int p) { +float f_pow(float arg, int p) { if (p == 0) return 1; else return arg * f_pow(arg, p - 1); } -// CHECK: clad::ValueAndPushforward f_pow_pushforward(int arg, int p, int _d_arg, int _d_p); +// CHECK: clad::ValueAndPushforward f_pow_pushforward(float arg, int p, float _d_arg); -// CHECK: int f_pow_darg0(int arg, int p) { -// CHECK-NEXT: int _d_arg = 1; -// CHECK-NEXT: int _d_p = 0; +// CHECK: float f_pow_darg0(float arg, int p) { +// CHECK-NEXT: float _d_arg = 1; // CHECK-NEXT: if (p == 0) // CHECK-NEXT: return 0; // CHECK-NEXT: else { -// CHECK-NEXT: clad::ValueAndPushforward _t0 = f_pow_pushforward(arg, p - 1, _d_arg, _d_p - 0); -// CHECK-NEXT: int &_t1 = _t0.value; +// CHECK-NEXT: clad::ValueAndPushforward _t0 = f_pow_pushforward(arg, p - 1, _d_arg); +// CHECK-NEXT: float &_t1 = _t0.value; // CHECK-NEXT: return _d_arg * _t1 + arg * _t0.pushforward; // CHECK-NEXT: } // CHECK-NEXT: } -int f_pow_darg0(int arg, int p); +float f_pow_darg0(float arg, int p); int main() { clad::differentiate(f_dec, 0); - printf("Result is = %d\n", f_dec_darg0(2)); // CHECK-EXEC: Result is = 1 + printf("Result is = %.2f\n", f_dec_darg0(2)); // CHECK-EXEC: Result is = 1.00 clad::differentiate(f_pow, 0); - printf("Result is = %d\n", f_pow_darg0(10, 2)); //CHECK-EXEC: Result is = 20 + printf("Result is = %.2f\n", f_pow_darg0(10, 2)); //CHECK-EXEC: Result is = 20.00 -// CHECK: clad::ValueAndPushforward f_dec_pushforward(int arg, int _d_arg) { +// CHECK: clad::ValueAndPushforward f_dec_pushforward(float arg, float _d_arg) { // CHECK-NEXT: if (arg == 0) // CHECK-NEXT: return {arg, _d_arg}; // CHECK-NEXT: else { -// CHECK-NEXT: clad::ValueAndPushforward _t0 = f_dec_pushforward(arg - 1, _d_arg - 0); +// CHECK-NEXT: clad::ValueAndPushforward _t0 = f_dec_pushforward(arg - 1, _d_arg - 0); // CHECK-NEXT: return {_t0.value, _t0.pushforward}; // CHECK-NEXT: } // CHECK-NEXT: } -// CHECK: clad::ValueAndPushforward f_pow_pushforward(int arg, int p, int _d_arg, int _d_p) { +// CHECK: clad::ValueAndPushforward f_pow_pushforward(float arg, int p, float _d_arg) { // CHECK-NEXT: if (p == 0) // CHECK-NEXT: return {1, 0}; // CHECK-NEXT: else { -// CHECK-NEXT: clad::ValueAndPushforward _t0 = f_pow_pushforward(arg, p - 1, _d_arg, _d_p - 0); -// CHECK-NEXT: int &_t1 = _t0.value; +// CHECK-NEXT: clad::ValueAndPushforward _t0 = f_pow_pushforward(arg, p - 1, _d_arg); +// CHECK-NEXT: float &_t1 = _t0.value; // CHECK-NEXT: return {arg * _t1, _d_arg * _t1 + arg * _t0.pushforward}; // CHECK-NEXT: } // CHECK-NEXT: } diff --git a/test/FirstDerivative/StructMethodCall.C b/test/FirstDerivative/StructMethodCall.C index d00701afd..af184ae05 100644 --- a/test/FirstDerivative/StructMethodCall.C +++ b/test/FirstDerivative/StructMethodCall.C @@ -8,83 +8,83 @@ extern "C" int printf(const char* fmt, ...); struct A { public: - int f(int x) { + float f(float x) { return x; } - // CHECK: int f_darg0(int x) { - // CHECK-NEXT: int _d_x = 1; + // CHECK: float f_darg0(float x) { + // CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: A _d_this_obj; // CHECK-NEXT: A *_d_this = &_d_this_obj; // CHECK-NEXT: return _d_x; // CHECK-NEXT: } - int g_1(int x, int y) { + float g_1(float x, float y) { return x*x + y; } - // CHECK: int g_1_darg0(int x, int y) { - // CHECK-NEXT: int _d_x = 1; - // CHECK-NEXT: int _d_y = 0; + // CHECK: float g_1_darg0(float x, float y) { + // CHECK-NEXT: float _d_x = 1; + // CHECK-NEXT: float _d_y = 0; // CHECK-NEXT: A _d_this_obj; // CHECK-NEXT: A *_d_this = &_d_this_obj; // CHECK-NEXT: return _d_x * x + x * _d_x + _d_y; // CHECK-NEXT: } - // CHECK: int g_1_darg1(int x, int y) { - // CHECK-NEXT: int _d_x = 0; - // CHECK-NEXT: int _d_y = 1; + // CHECK: float g_1_darg1(float x, float y) { + // CHECK-NEXT: float _d_x = 0; + // CHECK-NEXT: float _d_y = 1; // CHECK-NEXT: A _d_this_obj; // CHECK-NEXT: A *_d_this = &_d_this_obj; // CHECK-NEXT: return _d_x * x + x * _d_x + _d_y; // CHECK-NEXT: } - int g_2(int x, int y) { + float g_2(float x, float y) { return x + y*y; } - // CHECK: int g_2_darg0(int x, int y) { - // CHECK-NEXT: int _d_x = 1; - // CHECK-NEXT: int _d_y = 0; + // CHECK: float g_2_darg0(float x, float y) { + // CHECK-NEXT: float _d_x = 1; + // CHECK-NEXT: float _d_y = 0; // CHECK-NEXT: A _d_this_obj; // CHECK-NEXT: A *_d_this = &_d_this_obj; // CHECK-NEXT: return _d_x + _d_y * y + y * _d_y; // CHECK-NEXT: } - // CHECK: int g_2_darg1(int x, int y) { - // CHECK-NEXT: int _d_x = 0; - // CHECK-NEXT: int _d_y = 1; + // CHECK: float g_2_darg1(float x, float y) { + // CHECK-NEXT: float _d_x = 0; + // CHECK-NEXT: float _d_y = 1; // CHECK-NEXT: A _d_this_obj; // CHECK-NEXT: A *_d_this = &_d_this_obj; // CHECK-NEXT: return _d_x + _d_y * y + y * _d_y; // CHECK-NEXT: } - int m(int x, int y) { + float m(float x, float y) { return f(x) + g_1(x, y); } - // CHECK: clad::ValueAndPushforward f_pushforward(int x, A *_d_this, int _d_x); + // CHECK: clad::ValueAndPushforward f_pushforward(float x, A *_d_this, float _d_x); - // CHECK: clad::ValueAndPushforward g_1_pushforward(int x, int y, A *_d_this, int _d_x, int _d_y); + // CHECK: clad::ValueAndPushforward g_1_pushforward(float x, float y, A *_d_this, float _d_x, float _d_y); - // CHECK: int m_darg0(int x, int y) { - // CHECK-NEXT: int _d_x = 1; - // CHECK-NEXT: int _d_y = 0; + // CHECK: float m_darg0(float x, float y) { + // CHECK-NEXT: float _d_x = 1; + // CHECK-NEXT: float _d_y = 0; // CHECK-NEXT: A _d_this_obj; // CHECK-NEXT: A *_d_this = &_d_this_obj; - // CHECK-NEXT: clad::ValueAndPushforward _t0 = this->f_pushforward(x, _d_this, _d_x); - // CHECK-NEXT: clad::ValueAndPushforward _t1 = this->g_1_pushforward(x, y, _d_this, _d_x, _d_y); + // CHECK-NEXT: clad::ValueAndPushforward _t0 = this->f_pushforward(x, _d_this, _d_x); + // CHECK-NEXT: clad::ValueAndPushforward _t1 = this->g_1_pushforward(x, y, _d_this, _d_x, _d_y); // CHECK-NEXT: return _t0.pushforward + _t1.pushforward; // CHECK-NEXT: } - // CHECK: int m_darg1(int x, int y) { - // CHECK-NEXT: int _d_x = 0; - // CHECK-NEXT: int _d_y = 1; + // CHECK: float m_darg1(float x, float y) { + // CHECK-NEXT: float _d_x = 0; + // CHECK-NEXT: float _d_y = 1; // CHECK-NEXT: A _d_this_obj; // CHECK-NEXT: A *_d_this = &_d_this_obj; - // CHECK-NEXT: clad::ValueAndPushforward _t0 = this->f_pushforward(x, _d_this, _d_x); - // CHECK-NEXT: clad::ValueAndPushforward _t1 = this->g_1_pushforward(x, y, _d_this, _d_x, _d_y); + // CHECK-NEXT: clad::ValueAndPushforward _t0 = this->f_pushforward(x, _d_this, _d_x); + // CHECK-NEXT: clad::ValueAndPushforward _t1 = this->g_1_pushforward(x, y, _d_this, _d_x, _d_y); // CHECK-NEXT: return _t0.pushforward + _t1.pushforward; // CHECK-NEXT: } }; @@ -92,26 +92,26 @@ public: int main () { A a; auto f_dx = clad::differentiate(&A::f, 0); - printf("Result is = %d\n", f_dx.execute(a, 1)); // CHECK-EXEC: Result is = 1 + printf("Result is = %.2f\n", f_dx.execute(a, 1)); // CHECK-EXEC: Result is = 1.00 auto g_1_dx = clad::differentiate(&A::g_1, 0); auto g_1_dy = clad::differentiate(&A::g_1, 1); - printf("Result is = {%d, %d}\n", g_1_dx.execute(a, 1, 2), g_1_dy.execute(a, 1, 2)); // CHECK-EXEC: Result is = {2, 1} + printf("Result is = {%.2f, %.2f}\n", g_1_dx.execute(a, 1, 2), g_1_dy.execute(a, 1, 2)); // CHECK-EXEC: Result is = {2.00, 1.00} auto g_2_dx = clad::differentiate(&A::g_2, 0); auto g_2_dy = clad::differentiate(&A::g_2, 1); - printf("Result is = {%d, %d}\n", g_2_dx.execute(a, 1, 2), g_2_dy.execute(a, 1, 2)); // CHECK-EXEC: Result is = {1, 4} + printf("Result is = {%.2f, %.2f}\n", g_2_dx.execute(a, 1, 2), g_2_dy.execute(a, 1, 2)); // CHECK-EXEC: Result is = {1.00, 4.00} auto m_dx = clad::differentiate(&A::m, 0); auto m_dy = clad::differentiate(&A::m, 1); - printf("Result is = {%d, %d}\n", m_dx.execute(a, 1, 2), m_dy.execute(a, 1, 2)); // CHECK-EXEC: Result is = {3, 1} + printf("Result is = {%.2f, %.2f}\n", m_dx.execute(a, 1, 2), m_dy.execute(a, 1, 2)); // CHECK-EXEC: Result is = {3.00, 1.00} return 0; - // CHECK: clad::ValueAndPushforward f_pushforward(int x, A *_d_this, int _d_x) { + // CHECK: clad::ValueAndPushforward f_pushforward(float x, A *_d_this, float _d_x) { // CHECK-NEXT: return {x, _d_x}; // CHECK-NEXT: } - // CHECK: clad::ValueAndPushforward g_1_pushforward(int x, int y, A *_d_this, int _d_x, int _d_y) { + // CHECK: clad::ValueAndPushforward g_1_pushforward(float x, float y, A *_d_this, float _d_x, float _d_y) { // CHECK-NEXT: return {x * x + y, _d_x * x + x * _d_x + _d_y}; // CHECK-NEXT: } } diff --git a/test/FirstDerivative/Switch.C b/test/FirstDerivative/Switch.C index 7e24133c6..1584a2f49 100644 --- a/test/FirstDerivative/Switch.C +++ b/test/FirstDerivative/Switch.C @@ -31,7 +31,6 @@ double fn1 (double i, double j, int choice) { // CHECK: double fn1_darg0(double i, double j, int choice) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_choice = 0; // CHECK-NEXT: double _d_a = 0, _d_b = 0; // CHECK-NEXT: double a = 0, b = 0; // CHECK-NEXT: double _d_c = _d_i + _d_j; @@ -105,13 +104,11 @@ double fn2 (double i, double j, int choice) { // CHECK: double fn2_darg0(double i, double j, int choice) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_choice = 0; // CHECK-NEXT: double _d_a = 0, _d_b = 0; // CHECK-NEXT: double a = 0, b = 0; // CHECK-NEXT: double _d_c = _d_i + _d_j; // CHECK-NEXT: double c = i + j; // CHECK-NEXT: { -// CHECK-NEXT: int _d_diff_choice = _d_choice + 0; // CHECK-NEXT: switch (int diff_choice = choice + 1) { // CHECK-NEXT: case 1: // CHECK-NEXT: { @@ -167,7 +164,6 @@ double fn3 (double i, double j, int choice) { // CHECK: double fn3_darg0(double i, double j, int choice) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_choice = 0; // CHECK-NEXT: double _d_a = 0; // CHECK-NEXT: double a = 0; // CHECK-NEXT: { @@ -222,7 +218,6 @@ double fn4(double i, double j, int choice) { // CHECK: double fn4_darg0(double i, double j, int choice) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_choice = 0; // CHECK-NEXT: double _d_a = 0, _d_b = 0; // CHECK-NEXT: double a = 0, b = 0; // CHECK-NEXT: { diff --git a/test/FirstDerivative/SwitchInit.C b/test/FirstDerivative/SwitchInit.C index a95c2be27..620173e4b 100644 --- a/test/FirstDerivative/SwitchInit.C +++ b/test/FirstDerivative/SwitchInit.C @@ -19,11 +19,9 @@ double fn1(double i, double j, int choice) { // CHECK: double fn1_darg0(double i, double j, int choice) { // CHECK-NEXT: double _d_i = 1; // CHECK-NEXT: double _d_j = 0; -// CHECK-NEXT: int _d_choice = 0; // CHECK-NEXT: double _d_a = 0; // CHECK-NEXT: double a = 0; // CHECK-NEXT: { -// CHECK-NEXT: short _d_effective_choice = _d_choice + 0, _d_another_choice = _d_choice + 0; // CHECK-NEXT: switch ({{(short effective_choice = choice \+ 1, another_choice = choice \+ 2; )?}}effective_choice) { // CHECK-NEXT: case 1: // CHECK-NEXT: { diff --git a/test/FirstDerivative/TemplateFunction.C b/test/FirstDerivative/TemplateFunction.C index f808d5da5..95ce83a63 100644 --- a/test/FirstDerivative/TemplateFunction.C +++ b/test/FirstDerivative/TemplateFunction.C @@ -19,13 +19,8 @@ T multiplication(T x) { } int main () { - int x; - clad::differentiate(simple_return, 0); - // CHECK: int simple_return_darg0(int x) { - // CHECK-NEXT: int _d_x = 1; - // CHECK-NEXT: return _d_x; - // CHECK-NEXT: } + // no derivarive clad::differentiate(simple_return, 0); // CHECK: float simple_return_darg0(float x) { @@ -40,10 +35,7 @@ int main () { // CHECK-NEXT: } clad::differentiate(addition, 0); - // CHECK: int addition_darg0(int x) { - // CHECK-NEXT: int _d_x = 1; - // CHECK-NEXT: return _d_x + _d_x; - // CHECK-NEXT: } + // no derivarive clad::differentiate(addition, 0); // CHECK: float addition_darg0(float x) { @@ -58,10 +50,7 @@ int main () { // CHECK-NEXT: } clad::differentiate(multiplication, 0); - // CHECK: int multiplication_darg0(int x) { - // CHECK-NEXT: int _d_x = 1; - // CHECK-NEXT: return _d_x * x + x * _d_x; - // CHECK-NEXT: } + // no derivarive clad::differentiate(multiplication, 0); // CHECK: float multiplication_darg0(float x) { diff --git a/test/FirstDerivative/UnsupportedOpsWarn.C b/test/FirstDerivative/UnsupportedOpsWarn.C index 687ea4e3c..4ff55837e 100644 --- a/test/FirstDerivative/UnsupportedOpsWarn.C +++ b/test/FirstDerivative/UnsupportedOpsWarn.C @@ -5,17 +5,19 @@ //CHECK-NOT: {{.*error|warning|note:.*}} -int binOpWarn_0(int x){ - return x << 1; // expected-warning {{attempt to differentiate unsupported operator, derivative set to 0}} +float binOpWarn_0(float x){ + int n = 3; + return n << 1; // expected-warning {{attempt to differentiate unsupported operator, derivative set to 0}} } -// CHECK: int binOpWarn_0_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float binOpWarn_0_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: int n = 3; // CHECK-NEXT: return 0; // CHECK-NEXT: } -int binOpWarn_1(int x, double y){ +float binOpWarn_1(int x, double y){ return x ^ 1; // expected-warning {{attempt to differentiate unsupported operator, ignored.}} } @@ -25,17 +27,18 @@ int binOpWarn_1(int x, double y){ // CHECK-NEXT: ; // CHECK-NEXT: } -int unOpWarn_0(int x){ - return ~x; // expected-warning {{attempt to differentiate unsupported operator, derivative set to 0}} +float unOpWarn_0(float x){ + int n = 3; + return ~n; // expected-warning {{attempt to differentiate unsupported operator, derivative set to 0}} } -// CHECK: int unOpWarn_0_darg0(int x) { -// CHECK-NEXT: int _d_x = 1; +// CHECK: float unOpWarn_0_darg0(float x) { +// CHECK-NEXT: float _d_x = 1; +// CHECK-NEXT: int n = 3; // CHECK-NEXT: return 0; // CHECK-NEXT: } int main(){ - clad::differentiate(binOpWarn_0, 0); clad::gradient(binOpWarn_1); clad::differentiate(unOpWarn_0, 0); diff --git a/test/ForwardMode/FunctorErrors.C b/test/ForwardMode/FunctorErrors.C index d0fec67e6..0b0d813f1 100644 --- a/test/ForwardMode/FunctorErrors.C +++ b/test/ForwardMode/FunctorErrors.C @@ -33,14 +33,14 @@ struct ExperimentProtectedCallOperator { struct Widget { double i, j; - const char* char_arr[10]; + const float* float_arr[10]; char** p2p_char; Widget() : i(0), j(0) {} Widget(double p_i, double p_j) : i(p_i), j(p_j) {} double operator()() { char **p; p = p2p_char; - char_arr[0] = char_arr[1]; // expected-warning {{derivative of an assignment attempts to assign to unassignable expr, assignment ignored}} + float_arr[0] = float_arr[1]; // expected-warning {{derivative of an assignment attempts to assign to unassignable expr, assignment ignored}} return i*i + j; } }; diff --git a/test/ForwardMode/Functors.C b/test/ForwardMode/Functors.C index f7e54b054..91c171d20 100644 --- a/test/ForwardMode/Functors.C +++ b/test/ForwardMode/Functors.C @@ -236,12 +236,9 @@ struct WidgetArr { // CHECK-NEXT: double _d_arr[10] = {0, 0, 0, 1, 0, 0, 0, 0, 0, 0}; // CHECK-NEXT: double _d_temp = 0; // CHECK-NEXT: double temp = 0; - // CHECK-NEXT: { - // CHECK-NEXT: int _d_k = 0; - // CHECK-NEXT: for (int k = 0; k < 10; ++k) { - // CHECK-NEXT: _d_temp += _d_arr[k]; - // CHECK-NEXT: temp += this->arr[k]; - // CHECK-NEXT: } + // CHECK-NEXT: for (int k = 0; k < 10; ++k) { + // CHECK-NEXT: _d_temp += _d_arr[k]; + // CHECK-NEXT: temp += this->arr[k]; // CHECK-NEXT: } // CHECK-NEXT: double &_t0 = this->i; // CHECK-NEXT: double &_t1 = this->arr[3]; @@ -262,12 +259,9 @@ struct WidgetArr { // CHECK-NEXT: double _d_arr[10] = {0, 0, 0, 0, 0, 1, 0, 0, 0, 0}; // CHECK-NEXT: double _d_temp = 0; // CHECK-NEXT: double temp = 0; - // CHECK-NEXT: { - // CHECK-NEXT: int _d_k = 0; - // CHECK-NEXT: for (int k = 0; k < 10; ++k) { - // CHECK-NEXT: _d_temp += _d_arr[k]; - // CHECK-NEXT: temp += this->arr[k]; - // CHECK-NEXT: } + // CHECK-NEXT: for (int k = 0; k < 10; ++k) { + // CHECK-NEXT: _d_temp += _d_arr[k]; + // CHECK-NEXT: temp += this->arr[k]; // CHECK-NEXT: } // CHECK-NEXT: double &_t0 = this->i; // CHECK-NEXT: double &_t1 = this->arr[3]; @@ -321,12 +315,9 @@ struct WidgetPointer { // CHECK-NEXT: double *_d_arr = nullptr; // CHECK-NEXT: double _d_temp = 0; // CHECK-NEXT: double temp = 0; - // CHECK-NEXT: { - // CHECK-NEXT: int _d_k = 0; - // CHECK-NEXT: for (int k = 0; k < 10; ++k) { - // CHECK-NEXT: _d_temp += (k == 3.); - // CHECK-NEXT: temp += this->arr[k]; - // CHECK-NEXT: } + // CHECK-NEXT: for (int k = 0; k < 10; ++k) { + // CHECK-NEXT: _d_temp += (k == 3.); + // CHECK-NEXT: temp += this->arr[k]; // CHECK-NEXT: } // CHECK-NEXT: double &_t0 = this->arr[3]; // CHECK-NEXT: double &_t1 = this->arr[3]; @@ -353,12 +344,9 @@ struct WidgetPointer { // CHECK-NEXT: double *_d_arr = nullptr; // CHECK-NEXT: double _d_temp = 0; // CHECK-NEXT: double temp = 0; - // CHECK-NEXT: { - // CHECK-NEXT: int _d_k = 0; - // CHECK-NEXT: for (int k = 0; k < 10; ++k) { - // CHECK-NEXT: _d_temp += (k == 5.); - // CHECK-NEXT: temp += this->arr[k]; - // CHECK-NEXT: } + // CHECK-NEXT: for (int k = 0; k < 10; ++k) { + // CHECK-NEXT: _d_temp += (k == 5.); + // CHECK-NEXT: temp += this->arr[k]; // CHECK-NEXT: } // CHECK-NEXT: double &_t0 = this->arr[3]; // CHECK-NEXT: double &_t1 = this->arr[3]; diff --git a/test/ForwardMode/Pointer.C b/test/ForwardMode/Pointer.C index bb1edfdde..236062d7d 100644 --- a/test/ForwardMode/Pointer.C +++ b/test/ForwardMode/Pointer.C @@ -95,7 +95,6 @@ double fn5(double i, double j) { // CHECK-NEXT: double arr[2] = {7 * i, 9 * i}; // CHECK-NEXT: *(_d_arr + 1) += 0 * i + 11 * _d_i; // CHECK-NEXT: *(arr + 1) += 11 * i; -// CHECK-NEXT: int _d_idx1 = 0, _d_idx2 = 0; // CHECK-NEXT: int idx1 = 0, idx2 = 1; // CHECK-NEXT: double *_d_p = _d_arr; // CHECK-NEXT: double *p = arr; @@ -149,12 +148,12 @@ double fn7(double i) { // CHECK: double fn7_darg0(double i) { // CHECK-NEXT: double _d_i = 1; -// CHECK-NEXT: {{(clad::)?}}ValueAndPushforward _t0 = clad::custom_derivatives::malloc_pushforward(8UL, 0UL); +// CHECK-NEXT: {{(clad::)?}}ValueAndPushforward _t0 = clad::custom_derivatives::malloc_pushforward(8UL); // CHECK-NEXT: double *_d_p = (double *)_t0.pushforward; // CHECK-NEXT: double *p = (double *)_t0.value; // CHECK-NEXT: *_d_p = _d_i; // CHECK-NEXT: *p = i; -// CHECK-NEXT: {{(clad::)?}}ValueAndPushforward _t1 = clad::custom_derivatives::calloc_pushforward(1, sizeof(T), 0, sizeof(T)); +// CHECK-NEXT: {{(clad::)?}}ValueAndPushforward _t1 = clad::custom_derivatives::calloc_pushforward(1, sizeof(T)); // CHECK-NEXT: T *_d_t = (T *)_t1.pushforward; // CHECK-NEXT: T *t = (T *)_t1.value; // CHECK-NEXT: _d_t->i = _d_i; @@ -162,7 +161,7 @@ double fn7(double i) { // CHECK-NEXT: double _d_res = *_d_p + _d_t->i; // CHECK-NEXT: double res = *p + t->i; // CHECK-NEXT: unsigned {{(int|long)}} _t2 = sizeof(double); -// CHECK-NEXT: {{(clad::)?}}ValueAndPushforward _t3 = clad::custom_derivatives::realloc_pushforward(p, 2 * _t2, _d_p, 0 * _t2 + 2 * sizeof(double)); +// CHECK-NEXT: {{(clad::)?}}ValueAndPushforward _t3 = clad::custom_derivatives::realloc_pushforward(p, 2 * _t2, _d_p); // CHECK-NEXT: _d_p = (double *)_t3.pushforward; // CHECK-NEXT: p = (double *)_t3.value; // CHECK-NEXT: _d_p[1] = 0 * i + 2 * _d_i; diff --git a/test/ForwardMode/UserDefinedTypes.C b/test/ForwardMode/UserDefinedTypes.C index 39b3353c7..67c0000c5 100644 --- a/test/ForwardMode/UserDefinedTypes.C +++ b/test/ForwardMode/UserDefinedTypes.C @@ -425,13 +425,10 @@ Tensor fn5(double i, double j) { // CHECK-NEXT: double _d_j = 0; // CHECK-NEXT: Tensor _d_T; // CHECK-NEXT: Tensor T; -// CHECK-NEXT: { -// CHECK-NEXT: int _d_l = 0; -// CHECK-NEXT: for (int l = 0; l < 5; ++l) { -// CHECK-NEXT: int _t0 = (l + 1); -// CHECK-NEXT: _d_T.data[l] = (_d_l + 0) * i + _t0 * _d_i; -// CHECK-NEXT: T.data[l] = _t0 * i; -// CHECK-NEXT: } +// CHECK-NEXT: for (int l = 0; l < 5; ++l) { +// CHECK-NEXT: int _t0 = (l + 1); +// CHECK-NEXT: _d_T.data[l] = (0 + 0) * i + _t0 * _d_i; +// CHECK-NEXT: T.data[l] = _t0 * i; // CHECK-NEXT: } // CHECK-NEXT: return _d_T; // CHECK-NEXT: } @@ -595,7 +592,7 @@ TensorD5 fn11(double i, double j) { // CHECK: void operator_call_pushforward(double val, Tensor *_d_this, double _d_val); -// CHECK: clad::ValueAndPushforward operator_subscript_pushforward(std::size_t idx, Tensor *_d_this, std::size_t _d_idx); +// CHECK: clad::ValueAndPushforward operator_subscript_pushforward(std::size_t idx, Tensor *_d_this); // CHECK: clad::ValueAndPushforward, Tensor > operator_plus_pushforward(const Tensor &a, const Tensor &b, const Tensor &_d_a, const Tensor &_d_b); @@ -619,7 +616,7 @@ TensorD5 fn11(double i, double j) { // CHECK: clad::ValueAndPushforward &, Tensor &> operator_minus_minus_pushforward(Tensor *_d_this); -// CHECK: clad::ValueAndPushforward, Tensor > operator_plus_plus_pushforward(int param, Tensor *_d_this, int _d_param); +// CHECK: clad::ValueAndPushforward, Tensor > operator_plus_plus_pushforward(int param, Tensor *_d_this); // CHECK: TensorD5 fn11_darg0(double i, double j) { // CHECK-NEXT: double _d_i = 1; @@ -628,10 +625,10 @@ TensorD5 fn11(double i, double j) { // CHECK-NEXT: TensorD5 a, b; // CHECK-NEXT: a.operator_call_pushforward(7 * i, & _d_a, 0 * i + 7 * _d_i); // CHECK-NEXT: b.operator_call_pushforward(9 * i, & _d_b, 0 * i + 9 * _d_i); -// CHECK-NEXT: clad::ValueAndPushforward _t0 = a.operator_subscript_pushforward(0, & _d_a, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t0 = a.operator_subscript_pushforward(0, & _d_a); // CHECK-NEXT: _t0.pushforward += 0 * i + 11 * _d_i; // CHECK-NEXT: _t0.value += 11 * i; -// CHECK-NEXT: clad::ValueAndPushforward _t1 = b.operator_subscript_pushforward(0, & _d_b, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t1 = b.operator_subscript_pushforward(0, & _d_b); // CHECK-NEXT: _t1.pushforward += 0 * i + 13 * _d_i; // CHECK-NEXT: _t1.value += 13 * i; // CHECK-NEXT: TensorD5 _d_res1, _d_res2; @@ -658,8 +655,8 @@ TensorD5 fn11(double i, double j) { // CHECK-NEXT: clad::ValueAndPushforward &, Tensor &> _t18 = res2.operator_plus_plus_pushforward(& _d_res2); // CHECK-NEXT: clad::ValueAndPushforward &, Tensor &> _t19 = res1.operator_minus_minus_pushforward(& _d_res1); // CHECK-NEXT: clad::ValueAndPushforward &, Tensor &> _t20 = res2.operator_minus_minus_pushforward(& _d_res2); -// CHECK-NEXT: clad::ValueAndPushforward, Tensor > _t21 = res1.operator_plus_plus_pushforward(0, & _d_res1, 0); -// CHECK-NEXT: clad::ValueAndPushforward, Tensor > _t22 = res2.operator_plus_plus_pushforward(0, & _d_res2, 0); +// CHECK-NEXT: clad::ValueAndPushforward, Tensor > _t21 = res1.operator_plus_plus_pushforward(0, & _d_res1); +// CHECK-NEXT: clad::ValueAndPushforward, Tensor > _t22 = res2.operator_plus_plus_pushforward(0, & _d_res2); // CHECK-NEXT: return _d_res1; // CHECK-NEXT: } @@ -697,10 +694,10 @@ TensorD5 fn12(double i, double j) { // CHECK-NEXT: TensorD5 a, b; // CHECK-NEXT: a.operator_call_pushforward(7 * i, & _d_a, 0 * i + 7 * _d_i); // CHECK-NEXT: b.operator_call_pushforward(9 * i, & _d_b, 0 * i + 9 * _d_i); -// CHECK-NEXT: clad::ValueAndPushforward _t0 = a.operator_subscript_pushforward(0, & _d_a, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t0 = a.operator_subscript_pushforward(0, & _d_a); // CHECK-NEXT: _t0.pushforward += 0 * i + 11 * _d_i; // CHECK-NEXT: _t0.value += 11 * i; -// CHECK-NEXT: clad::ValueAndPushforward _t1 = b.operator_subscript_pushforward(0, & _d_b, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t1 = b.operator_subscript_pushforward(0, & _d_b); // CHECK-NEXT: _t1.pushforward += 0 * i + 13 * _d_i; // CHECK-NEXT: _t1.value += 13 * i; // CHECK-NEXT: TensorD5 _d_res1; @@ -716,7 +713,7 @@ TensorD5 fn12(double i, double j) { // CHECK-NEXT: clad::ValueAndPushforward, Tensor > _t6 = operator_star_pushforward(a, a, _d_a, _d_a); // CHECK-NEXT: clad::ValueAndPushforward, Tensor > _t7 = operator_slash_pushforward(_t6.value, a, _t6.pushforward, _d_a); // CHECK-NEXT: clad::ValueAndPushforward &, Tensor &> _t8 = operator_plus_equal_pushforward(res1, _t7.value, _d_res1, _t7.pushforward); -// CHECK-NEXT: clad::ValueAndPushforward _t9 = res1.operator_subscript_pushforward(1, & _d_res1, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t9 = res1.operator_subscript_pushforward(1, & _d_res1); // CHECK-NEXT: _t9.pushforward += 0 * i + 17 * _d_i; // CHECK-NEXT: _t9.value += 17 * i; // CHECK-NEXT: clad::ValueAndPushforward &, Tensor &> _t10 = operator_caret_equal_pushforward(res1, one, _d_res1, _d_one); @@ -802,23 +799,23 @@ TensorD5 fn13(double i, double j) { // CHECK-NEXT: double _d_j = 0; // CHECK-NEXT: TensorD5 _d_a, _d_b; // CHECK-NEXT: TensorD5 a, b; -// CHECK-NEXT: clad::ValueAndPushforward _t0 = a.operator_subscript_pushforward(0, & _d_a, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t0 = a.operator_subscript_pushforward(0, & _d_a); // CHECK-NEXT: _t0.pushforward = _d_i * j + i * _d_j; // CHECK-NEXT: _t0.value = i * j; -// CHECK-NEXT: clad::ValueAndPushforward _t1 = b.operator_subscript_pushforward(0, & _d_b, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t1 = b.operator_subscript_pushforward(0, & _d_b); // CHECK-NEXT: _t1.pushforward = _d_i * i + i * _d_i; // CHECK-NEXT: _t1.value = i * i; -// CHECK-NEXT: clad::ValueAndPushforward _t2 = a.operator_subscript_pushforward(0, & _d_a, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t2 = a.operator_subscript_pushforward(0, & _d_a); // CHECK-NEXT: clad::ValueAndPushforward _t3 = operator_less_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: clad::ValueAndPushforward _t4 = operator_greater_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: _t2.pushforward += _t3.pushforward + _t4.pushforward; // CHECK-NEXT: _t2.value += _t3.value + _t4.value; -// CHECK-NEXT: clad::ValueAndPushforward _t5 = b.operator_subscript_pushforward(0, & _d_b, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t5 = b.operator_subscript_pushforward(0, & _d_b); // CHECK-NEXT: clad::ValueAndPushforward _t6 = operator_less_equal_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: clad::ValueAndPushforward _t7 = operator_greater_equal_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: _t5.pushforward += _t6.pushforward + _t7.pushforward; // CHECK-NEXT: _t5.value += _t6.value + _t7.value; -// CHECK-NEXT: clad::ValueAndPushforward _t8 = a.operator_subscript_pushforward(0, & _d_a, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t8 = a.operator_subscript_pushforward(0, & _d_a); // CHECK-NEXT: clad::ValueAndPushforward _t9 = operator_equal_equal_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: clad::ValueAndPushforward _t10 = operator_exclaim_equal_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: _t8.pushforward += _t9.pushforward + _t10.pushforward; @@ -839,19 +836,19 @@ TensorD5 fn13(double i, double j) { // CHECK-NEXT: clad::ValueAndPushforward &, Tensor &> _t14 = a.operator_equal_pushforward(_t13.value, & _d_a, _t13.pushforward); // CHECK-NEXT: clad::ValueAndPushforward &, Tensor &> _t15 = operator_percent_equal_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: operator_tilde_pushforward(a, _d_a); -// CHECK-NEXT: clad::ValueAndPushforward _t16 = a.operator_subscript_pushforward(2, & _d_a, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t16 = a.operator_subscript_pushforward(2, & _d_a); // CHECK-NEXT: clad::ValueAndPushforward _t17 = operator_less_less_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: clad::ValueAndPushforward _t18 = operator_greater_greater_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: _t16.pushforward = _t17.pushforward + _t18.pushforward; // CHECK-NEXT: _t16.value = _t17.value + _t18.value; -// CHECK-NEXT: clad::ValueAndPushforward _t19 = b.operator_subscript_pushforward(2, & _d_b, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t19 = b.operator_subscript_pushforward(2, & _d_b); // CHECK-NEXT: clad::ValueAndPushforward _t20 = operator_AmpAmp_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: clad::ValueAndPushforward _t21 = operator_pipe_pipe_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: _t19.pushforward = _t20.pushforward + _t21.pushforward; // CHECK-NEXT: _t19.value = _t20.value + _t21.value; // CHECK-NEXT: clad::ValueAndPushforward _t22 = operator_less_less_equal_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: clad::ValueAndPushforward _t23 = operator_greater_greater_equal_pushforward(b, a, _d_b, _d_a); -// CHECK-NEXT: clad::ValueAndPushforward _t24 = a.operator_subscript_pushforward(3, & _d_a, 0); +// CHECK-NEXT: clad::ValueAndPushforward _t24 = a.operator_subscript_pushforward(3, & _d_a); // CHECK-NEXT: clad::ValueAndPushforward _t25 = operator_amp_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: clad::ValueAndPushforward _t26 = operator_pipe_pushforward(a, b, _d_a, _d_b); // CHECK-NEXT: _t24.pushforward = _t25.pushforward + _t26.pushforward; @@ -881,10 +878,10 @@ double fn14(double i, double j) { // CHECK-NEXT: vectorD _d_v; // CHECK-NEXT: vectorD v; // CHECK-NEXT: clad::custom_derivatives::class_functions::resize_pushforward(&v, 5, 0, &_d_v, 0, 0); -// CHECK-NEXT: clad::ValueAndPushforward<{{.*}}, {{.*}}> _t0 = v.operator_subscript_pushforward(0, &_d_v, 0); +// CHECK-NEXT: clad::ValueAndPushforward<{{.*}}, {{.*}}> _t0 = v.operator_subscript_pushforward(0, &_d_v); // CHECK-NEXT: _t0.pushforward = 0 * i + 9 * _d_i; // CHECK-NEXT: _t0.value = 9 * i; -// CHECK-NEXT: clad::ValueAndPushforward<{{.*}}, {{.*}}> _t1 = v.operator_subscript_pushforward(1, &_d_v, 0); +// CHECK-NEXT: clad::ValueAndPushforward<{{.*}}, {{.*}}> _t1 = v.operator_subscript_pushforward(1, &_d_v); // CHECK-NEXT: _t1.pushforward = 0 * i + 11 * _d_i; // CHECK-NEXT: _t1.value = 11 * i; // CHECK-NEXT: clad::ValueAndPushforward _t2 = begin_pushforward(v, _d_v); @@ -1003,35 +1000,26 @@ int main() { // CHECK: clad::ValueAndPushforward sum_pushforward(Tensor *_d_this) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: double res = 0; -// CHECK-NEXT: { -// CHECK-NEXT: int _d_i = 0; -// CHECK-NEXT: for (int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_res += _d_this->data[i]; -// CHECK-NEXT: res += this->data[i]; -// CHECK-NEXT: } +// CHECK-NEXT: for (int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_res += _d_this->data[i]; +// CHECK-NEXT: res += this->data[i]; // CHECK-NEXT: } // CHECK-NEXT: return {res, _d_res}; // CHECK-NEXT: } // CHECK: void updateTo_pushforward(double val, Tensor *_d_this, double _d_val) { -// CHECK-NEXT: { -// CHECK-NEXT: int _d_i = 0; -// CHECK-NEXT: for (int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_this->data[i] = _d_val; -// CHECK-NEXT: this->data[i] = val; -// CHECK-NEXT: } +// CHECK-NEXT: for (int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_this->data[i] = _d_val; +// CHECK-NEXT: this->data[i] = val; // CHECK-NEXT: } // CHECK-NEXT: } // CHECK: clad::ValueAndPushforward sum_pushforward(Tensor &t, Tensor &_d_t) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: double res = 0; -// CHECK-NEXT: { -// CHECK-NEXT: int _d_i = 0; -// CHECK-NEXT: for (int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_res += _d_t.data[i]; -// CHECK-NEXT: res += t.data[i]; -// CHECK-NEXT: } +// CHECK-NEXT: for (int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_res += _d_t.data[i]; +// CHECK-NEXT: res += t.data[i]; // CHECK-NEXT: } // CHECK-NEXT: return {res, _d_res}; // CHECK-NEXT: } @@ -1055,28 +1043,22 @@ int main() { // CHECK-NEXT: } // CHECK: void operator_call_pushforward(double val, Tensor *_d_this, double _d_val) { -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_this->data[i] = _d_val; -// CHECK-NEXT: this->data[i] = val; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_this->data[i] = _d_val; +// CHECK-NEXT: this->data[i] = val; // CHECK-NEXT: } // CHECK-NEXT: } -// CHECK: clad::ValueAndPushforward operator_subscript_pushforward(std::size_t idx, Tensor *_d_this, std::size_t _d_idx) { +// CHECK: clad::ValueAndPushforward operator_subscript_pushforward(std::size_t idx, Tensor *_d_this) { // CHECK-NEXT: return {this->data[idx], _d_this->data[idx]}; // CHECK-NEXT: } // CHECK: clad::ValueAndPushforward, Tensor > operator_plus_pushforward(const Tensor &a, const Tensor &b, const Tensor &_d_a, const Tensor &_d_b) { // CHECK-NEXT: Tensor _d_res; // CHECK-NEXT: Tensor res; -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_res.data[i] = _d_a.data[i] + _d_b.data[i]; -// CHECK-NEXT: res.data[i] = a.data[i] + b.data[i]; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_res.data[i] = _d_a.data[i] + _d_b.data[i]; +// CHECK-NEXT: res.data[i] = a.data[i] + b.data[i]; // CHECK-NEXT: } // CHECK-NEXT: return {res, _d_res}; // CHECK-NEXT: } @@ -1084,14 +1066,11 @@ int main() { // CHECK: clad::ValueAndPushforward, Tensor > operator_star_pushforward(const Tensor &a, const Tensor &b, const Tensor &_d_a, const Tensor &_d_b) { // CHECK-NEXT: Tensor _d_res; // CHECK-NEXT: Tensor res; -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: const double _t0 = a.data[i]; -// CHECK-NEXT: const double _t1 = b.data[i]; -// CHECK-NEXT: _d_res.data[i] = _d_a.data[i] * _t1 + _t0 * _d_b.data[i]; -// CHECK-NEXT: res.data[i] = _t0 * _t1; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: const double _t0 = a.data[i]; +// CHECK-NEXT: const double _t1 = b.data[i]; +// CHECK-NEXT: _d_res.data[i] = _d_a.data[i] * _t1 + _t0 * _d_b.data[i]; +// CHECK-NEXT: res.data[i] = _t0 * _t1; // CHECK-NEXT: } // CHECK-NEXT: return {res, _d_res}; // CHECK-NEXT: } @@ -1099,12 +1078,9 @@ int main() { // CHECK: clad::ValueAndPushforward, Tensor > operator_minus_pushforward(const Tensor &t, const Tensor &_d_t) { // CHECK-NEXT: Tensor _d_res; // CHECK-NEXT: Tensor res; -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_res.data[i] = -_d_t.data[i]; -// CHECK-NEXT: res.data[i] = -t.data[i]; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_res.data[i] = -_d_t.data[i]; +// CHECK-NEXT: res.data[i] = -t.data[i]; // CHECK-NEXT: } // CHECK-NEXT: return {res, _d_res}; // CHECK-NEXT: } @@ -1112,12 +1088,9 @@ int main() { // CHECK: clad::ValueAndPushforward, Tensor > operator_minus_pushforward(const Tensor &a, const Tensor &b, const Tensor &_d_a, const Tensor &_d_b) { // CHECK-NEXT: Tensor _d_res; // CHECK-NEXT: Tensor res; -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_res.data[i] = _d_a.data[i] - _d_b.data[i]; -// CHECK-NEXT: res.data[i] = a.data[i] - b.data[i]; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_res.data[i] = _d_a.data[i] - _d_b.data[i]; +// CHECK-NEXT: res.data[i] = a.data[i] - b.data[i]; // CHECK-NEXT: } // CHECK-NEXT: return {res, _d_res}; // CHECK-NEXT: } @@ -1125,25 +1098,19 @@ int main() { // CHECK: clad::ValueAndPushforward, Tensor > operator_slash_pushforward(const Tensor &a, const Tensor &b, const Tensor &_d_a, const Tensor &_d_b) { // CHECK-NEXT: Tensor _d_res; // CHECK-NEXT: Tensor res; -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: const double _t0 = a.data[i]; -// CHECK-NEXT: const double _t1 = b.data[i]; -// CHECK-NEXT: _d_res.data[i] = (_d_a.data[i] * _t1 - _t0 * _d_b.data[i]) / (_t1 * _t1); -// CHECK-NEXT: res.data[i] = _t0 / _t1; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: const double _t0 = a.data[i]; +// CHECK-NEXT: const double _t1 = b.data[i]; +// CHECK-NEXT: _d_res.data[i] = (_d_a.data[i] * _t1 - _t0 * _d_b.data[i]) / (_t1 * _t1); +// CHECK-NEXT: res.data[i] = _t0 / _t1; // CHECK-NEXT: } // CHECK-NEXT: return {res, _d_res}; // CHECK-NEXT: } // CHECK: clad::ValueAndPushforward &, Tensor &> operator_equal_pushforward(const Tensor &t, Tensor *_d_this, const Tensor &_d_t) { -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_this->data[i] = _d_t.data[i]; -// CHECK-NEXT: this->data[i] = t.data[i]; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_this->data[i] = _d_t.data[i]; +// CHECK-NEXT: this->data[i] = t.data[i]; // CHECK-NEXT: } // CHECK-NEXT: return {*this, *_d_this}; // CHECK-NEXT: } @@ -1151,13 +1118,10 @@ int main() { // CHECK: clad::ValueAndPushforward, Tensor > operator_caret_pushforward(const Tensor &a, const Tensor &b, const Tensor &_d_a, const Tensor &_d_b) { // CHECK-NEXT: Tensor _d_res; // CHECK-NEXT: Tensor res; -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: ValueAndPushforward _t0 = clad::custom_derivatives::pow_pushforward(a.data[i], b.data[i], _d_a.data[i], _d_b.data[i]); -// CHECK-NEXT: _d_res.data[i] = _t0.pushforward; -// CHECK-NEXT: res.data[i] = _t0.value; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: ValueAndPushforward _t0 = clad::custom_derivatives::pow_pushforward(a.data[i], b.data[i], _d_a.data[i], _d_b.data[i]); +// CHECK-NEXT: _d_res.data[i] = _t0.pushforward; +// CHECK-NEXT: res.data[i] = _t0.value; // CHECK-NEXT: } // CHECK-NEXT: return {res, _d_res}; // CHECK-NEXT: } @@ -1175,36 +1139,27 @@ int main() { // CHECK-NEXT: } // CHECK: clad::ValueAndPushforward &, Tensor &> operator_plus_plus_pushforward(Tensor *_d_this) { -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_this->data[i] += 0; -// CHECK-NEXT: this->data[i] += 1; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_this->data[i] += 0; +// CHECK-NEXT: this->data[i] += 1; // CHECK-NEXT: } // CHECK-NEXT: return {*this, *_d_this}; // CHECK-NEXT: } // CHECK: clad::ValueAndPushforward &, Tensor &> operator_minus_minus_pushforward(Tensor *_d_this) { -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_this->data[i] += 0; -// CHECK-NEXT: this->data[i] += 1; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_this->data[i] += 0; +// CHECK-NEXT: this->data[i] += 1; // CHECK-NEXT: } // CHECK-NEXT: return {*this, *_d_this}; // CHECK-NEXT: } -// CHECK: clad::ValueAndPushforward, Tensor > operator_plus_plus_pushforward(int param, Tensor *_d_this, int _d_param) { +// CHECK: clad::ValueAndPushforward, Tensor > operator_plus_plus_pushforward(int param, Tensor *_d_this) { // CHECK-NEXT: Tensor _d_temp; // CHECK-NEXT: Tensor temp; -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_temp.data[i] += 0; -// CHECK-NEXT: temp.data[i] += 1; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_temp.data[i] += 0; +// CHECK-NEXT: temp.data[i] += 1; // CHECK-NEXT: } // CHECK-NEXT: return {temp, _d_temp}; // CHECK-NEXT: } @@ -1232,14 +1187,11 @@ int main() { // CHECK-NEXT: double lsum, rsum; // CHECK-NEXT: _d_lsum = _d_rsum = 0; // CHECK-NEXT: lsum = rsum = 0; -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_lsum += _d_lhs.data[i]; -// CHECK-NEXT: lsum += lhs.data[i]; -// CHECK-NEXT: _d_rsum += _d_lhs.data[i]; -// CHECK-NEXT: rsum += lhs.data[i]; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_lsum += _d_lhs.data[i]; +// CHECK-NEXT: lsum += lhs.data[i]; +// CHECK-NEXT: _d_rsum += _d_lhs.data[i]; +// CHECK-NEXT: rsum += lhs.data[i]; // CHECK-NEXT: } // CHECK-NEXT: return {1, 0}; // CHECK-NEXT: } @@ -1249,14 +1201,11 @@ int main() { // CHECK-NEXT: double lsum, rsum; // CHECK-NEXT: _d_lsum = _d_rsum = 0; // CHECK-NEXT: lsum = rsum = 0; -// CHECK-NEXT: { -// CHECK-NEXT: unsigned int _d_i = 0; -// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { -// CHECK-NEXT: _d_lsum += _d_lhs.data[i]; -// CHECK-NEXT: lsum += lhs.data[i]; -// CHECK-NEXT: _d_rsum += _d_lhs.data[i]; -// CHECK-NEXT: rsum += lhs.data[i]; -// CHECK-NEXT: } +// CHECK-NEXT: for (unsigned int i = 0; i < 5U; ++i) { +// CHECK-NEXT: _d_lsum += _d_lhs.data[i]; +// CHECK-NEXT: lsum += lhs.data[i]; +// CHECK-NEXT: _d_rsum += _d_lhs.data[i]; +// CHECK-NEXT: rsum += lhs.data[i]; // CHECK-NEXT: } // CHECK-NEXT: return {1, 0}; // CHECK-NEXT: } diff --git a/test/ForwardMode/VectorMode.C b/test/ForwardMode/VectorMode.C index 4491ccd65..dd5306361 100644 --- a/test/ForwardMode/VectorMode.C +++ b/test/ForwardMode/VectorMode.C @@ -230,14 +230,14 @@ double weighted_array_squared_sum(const double* arr, double w, int n) { double f7(const double* arr, double w, int n) { return weighted_array_squared_sum(arr, w, n); } -// CHECK: clad::ValueAndPushforward > weighted_array_squared_sum_vector_pushforward(const double *arr, double w, int n, clad::matrix &_d_arr, clad::array _d_w, clad::array _d_n); +// CHECK: clad::ValueAndPushforward > weighted_array_squared_sum_vector_pushforward(const double *arr, double w, int n, clad::matrix &_d_arr, clad::array _d_w); // CHECK: void f7_dvec_0_1(const double *arr, double w, int n, clad::array_ref _d_arr, double *_d_w) { // CHECK-NEXT: unsigned {{int|long}} indepVarCount = _d_arr.size() + {{1U|1UL}}; // CHECK-NEXT: clad::matrix _d_vector_arr = clad::identity_matrix(_d_arr.size(), indepVarCount, {{0U|0UL}}); // CHECK-NEXT: clad::array _d_vector_w = clad::one_hot_vector(indepVarCount, _d_arr.size()); // CHECK-NEXT: clad::array _d_vector_n = clad::zero_vector(indepVarCount); -// CHECK-NEXT: clad::ValueAndPushforward > _t0 = weighted_array_squared_sum_vector_pushforward(arr, w, n, _d_vector_arr, _d_vector_w, _d_vector_n); +// CHECK-NEXT: clad::ValueAndPushforward > _t0 = weighted_array_squared_sum_vector_pushforward(arr, w, n, _d_vector_arr, _d_vector_w); // CHECK-NEXT: { // CHECK-NEXT: clad::array _d_vector_return(clad::array(indepVarCount, _t0.pushforward)); // CHECK-NEXT: _d_arr = _d_vector_return.slice({{0U|0UL}}, _d_arr.size()); @@ -253,7 +253,7 @@ void sum_ref(double& res, int n, const double* arr) { return; } -// CHECK: void sum_ref_vector_pushforward(double &res, int n, const double *arr, clad::array &_d_res, clad::array _d_n, clad::matrix &_d_arr); +// CHECK: void sum_ref_vector_pushforward(double &res, int n, const double *arr, clad::array &_d_res, clad::matrix &_d_arr); double f8(int n, const double* arr) { double res = 0; @@ -267,7 +267,7 @@ double f8(int n, const double* arr) { // CHECK-NEXT: clad::matrix _d_vector_arr = clad::identity_matrix(_d_arr.size(), indepVarCount, {{0U|0UL}}); // CHECK-NEXT: clad::array _d_vector_res(clad::array(indepVarCount, 0)); // CHECK-NEXT: double res = 0; -// CHECK-NEXT: sum_ref_vector_pushforward(res, n, arr, _d_vector_res, _d_vector_n, _d_vector_arr); +// CHECK-NEXT: sum_ref_vector_pushforward(res, n, arr, _d_vector_res, _d_vector_arr); // CHECK-NEXT: { // CHECK-NEXT: clad::array _d_vector_return(clad::array(indepVarCount, _d_vector_res)); // CHECK-NEXT: _d_arr = _d_vector_return.slice({{0U|0UL}}, _d_arr.size()); @@ -345,8 +345,8 @@ int main() { // CHECK-NEXT: return {z, _d_vector_z}; // CHECK-NEXT: } -// CHECK: clad::ValueAndPushforward > weighted_array_squared_sum_vector_pushforward(const double *arr, double w, int n, clad::matrix &_d_arr, clad::array _d_w, clad::array _d_n) { -// CHECK-NEXT: unsigned long indepVarCount = _d_n.size(); +// CHECK: clad::ValueAndPushforward > weighted_array_squared_sum_vector_pushforward(const double *arr, double w, int n, clad::matrix &_d_arr, clad::array _d_w) { +// CHECK-NEXT: unsigned long indepVarCount = _d_w.size(); // CHECK-NEXT: clad::array _d_vector_sum(clad::array(indepVarCount, 0)); // CHECK-NEXT: double sum = 0; // CHECK-NEXT: { @@ -361,7 +361,7 @@ int main() { // CHECK-NEXT: return {sum, _d_vector_sum}; // CHECK-NEXT: } -// CHECK: void sum_ref_vector_pushforward(double &res, int n, const double *arr, clad::array &_d_res, clad::array _d_n, clad::matrix &_d_arr) { +// CHECK: void sum_ref_vector_pushforward(double &res, int n, const double *arr, clad::array &_d_res, clad::matrix &_d_arr) { // CHECK-NEXT: unsigned long indepVarCount = _d_arr[0].size(); // CHECK-NEXT: { // CHECK-NEXT: clad::array _d_vector_i(clad::array(indepVarCount, 0)); diff --git a/test/NthDerivative/CustomDerivatives.C b/test/NthDerivative/CustomDerivatives.C index 676edbffc..fb18151b3 100644 --- a/test/NthDerivative/CustomDerivatives.C +++ b/test/NthDerivative/CustomDerivatives.C @@ -42,26 +42,20 @@ float test_trig(float x, float y, int a, int b) { // CHECK: float test_trig_d2arg0(float x, float y, int a, int b) { // CHECK-NEXT: float _d_x = 1; // CHECK-NEXT: float _d_y = 0; -// CHECK-NEXT: int _d_a = 0; -// CHECK-NEXT: int _d_b = 0; // CHECK-NEXT: float _d__d_x = 0; // CHECK-NEXT: float _d_x0 = 1; // CHECK-NEXT: float _d__d_y = 0; // CHECK-NEXT: float _d_y0 = 0; -// CHECK-NEXT: int _d__d_a = 0; -// CHECK-NEXT: int _d_a0 = 0; -// CHECK-NEXT: int _d__d_b = 0; -// CHECK-NEXT: int _d_b0 = 0; // CHECK-NEXT: clad::ValueAndPushforward, ValueAndPushforward > _t0 = sin_pushforward_pushforward(x * y, _d_x0 * y + x * _d_y0, _d_x * y + x * _d_y, _d__d_x * y + _d_x0 * _d_y + _d_x * _d_y0 + x * _d__d_y); // CHECK-NEXT: ValueAndPushforward _d__t0 = _t0.pushforward; // CHECK-NEXT: ValueAndPushforward _t00 = _t0.value; -// CHECK-NEXT: clad::ValueAndPushforward, ValueAndPushforward > _t1 = pow_pushforward_pushforward(_t00.value, a, _t00.pushforward, _d_a0, _d__t0.value, _d_a, _d__t0.pushforward, _d__d_a); +// CHECK-NEXT: clad::ValueAndPushforward, ValueAndPushforward > _t1 = pow_pushforward_pushforward(_t00.value, a, _t00.pushforward, 0, _d__t0.value, _d__t0.pushforward); // CHECK-NEXT: ValueAndPushforward _d__t1 = _t1.pushforward; // CHECK-NEXT: ValueAndPushforward _t10 = _t1.value; // CHECK-NEXT: clad::ValueAndPushforward, ValueAndPushforward > _t2 = cos_pushforward_pushforward(x * y, _d_x0 * y + x * _d_y0, _d_x * y + x * _d_y, _d__d_x * y + _d_x0 * _d_y + _d_x * _d_y0 + x * _d__d_y); // CHECK-NEXT: ValueAndPushforward _d__t2 = _t2.pushforward; // CHECK-NEXT: ValueAndPushforward _t20 = _t2.value; -// CHECK-NEXT: clad::ValueAndPushforward, ValueAndPushforward > _t3 = pow_pushforward_pushforward(_t20.value, b, _t20.pushforward, _d_b0, _d__t2.value, _d_b, _d__t2.pushforward, _d__d_b); +// CHECK-NEXT: clad::ValueAndPushforward, ValueAndPushforward > _t3 = pow_pushforward_pushforward(_t20.value, b, _t20.pushforward, 0, _d__t2.value, _d__t2.pushforward); // CHECK-NEXT: ValueAndPushforward _d__t3 = _t3.pushforward; // CHECK-NEXT: ValueAndPushforward _t30 = _t3.value; // CHECK-NEXT: double &_d__t4 = _d__t1.value; @@ -79,26 +73,20 @@ float test_trig(float x, float y, int a, int b) { // CHECK: float test_trig_d2arg1(float x, float y, int a, int b) { // CHECK-NEXT: float _d_x = 0; // CHECK-NEXT: float _d_y = 1; -// CHECK-NEXT: int _d_a = 0; -// CHECK-NEXT: int _d_b = 0; // CHECK-NEXT: float _d__d_x = 0; // CHECK-NEXT: float _d_x0 = 0; // CHECK-NEXT: float _d__d_y = 0; // CHECK-NEXT: float _d_y0 = 1; -// CHECK-NEXT: int _d__d_a = 0; -// CHECK-NEXT: int _d_a0 = 0; -// CHECK-NEXT: int _d__d_b = 0; -// CHECK-NEXT: int _d_b0 = 0; // CHECK-NEXT: clad::ValueAndPushforward, ValueAndPushforward > _t0 = sin_pushforward_pushforward(x * y, _d_x0 * y + x * _d_y0, _d_x * y + x * _d_y, _d__d_x * y + _d_x0 * _d_y + _d_x * _d_y0 + x * _d__d_y); // CHECK-NEXT: ValueAndPushforward _d__t0 = _t0.pushforward; // CHECK-NEXT: ValueAndPushforward _t00 = _t0.value; -// CHECK-NEXT: clad::ValueAndPushforward, ValueAndPushforward > _t1 = pow_pushforward_pushforward(_t00.value, a, _t00.pushforward, _d_a0, _d__t0.value, _d_a, _d__t0.pushforward, _d__d_a); +// CHECK-NEXT: clad::ValueAndPushforward, ValueAndPushforward > _t1 = pow_pushforward_pushforward(_t00.value, a, _t00.pushforward, 0, _d__t0.value, _d__t0.pushforward); // CHECK-NEXT: ValueAndPushforward _d__t1 = _t1.pushforward; // CHECK-NEXT: ValueAndPushforward _t10 = _t1.value; // CHECK-NEXT: clad::ValueAndPushforward, ValueAndPushforward > _t2 = cos_pushforward_pushforward(x * y, _d_x0 * y + x * _d_y0, _d_x * y + x * _d_y, _d__d_x * y + _d_x0 * _d_y + _d_x * _d_y0 + x * _d__d_y); // CHECK-NEXT: ValueAndPushforward _d__t2 = _t2.pushforward; // CHECK-NEXT: ValueAndPushforward _t20 = _t2.value; -// CHECK-NEXT: clad::ValueAndPushforward, ValueAndPushforward > _t3 = pow_pushforward_pushforward(_t20.value, b, _t20.pushforward, _d_b0, _d__t2.value, _d_b, _d__t2.pushforward, _d__d_b); +// CHECK-NEXT: clad::ValueAndPushforward, ValueAndPushforward > _t3 = pow_pushforward_pushforward(_t20.value, b, _t20.pushforward, 0, _d__t2.value, _d__t2.pushforward); // CHECK-NEXT: ValueAndPushforward _d__t3 = _t3.pushforward; // CHECK-NEXT: ValueAndPushforward _t30 = _t3.value; // CHECK-NEXT: double &_d__t4 = _d__t1.value;