diff --git a/demos/ErrorEstimation/FloatSum.cpp b/demos/ErrorEstimation/FloatSum.cpp index 8c039212c..418aad168 100644 --- a/demos/ErrorEstimation/FloatSum.cpp +++ b/demos/ErrorEstimation/FloatSum.cpp @@ -106,7 +106,7 @@ int main() { finalError = 0; unsigned int dn = 0; // First execute the derived function. - df.execute(x, n, &ret[0], &dn, finalError); + df.execute(x, n, &ret[0], &dn, &finalError); double kahanResult = kahanSum(x, n); double vanillaResult = vanillaSum(x, n); diff --git a/demos/ErrorEstimation/PrintModel/test.cpp b/demos/ErrorEstimation/PrintModel/test.cpp index 29f4b7d3e..0ac09a230 100644 --- a/demos/ErrorEstimation/PrintModel/test.cpp +++ b/demos/ErrorEstimation/PrintModel/test.cpp @@ -29,5 +29,5 @@ int main() { // Calculate the error float dx, dy; double error; - df.execute(2, 3, &dx, &dy, error); + df.execute(2, 3, &dx, &dy, &error); } diff --git a/include/clad/Differentiator/BaseForwardModeVisitor.h b/include/clad/Differentiator/BaseForwardModeVisitor.h index 9e0394c8a..8e12af090 100644 --- a/include/clad/Differentiator/BaseForwardModeVisitor.h +++ b/include/clad/Differentiator/BaseForwardModeVisitor.h @@ -47,8 +47,6 @@ class BaseForwardModeVisitor virtual void ExecuteInsidePushforwardFunctionBlock(); - static bool IsDifferentiableType(clang::QualType T); - virtual StmtDiff VisitArraySubscriptExpr(const clang::ArraySubscriptExpr* ASE); StmtDiff VisitBinaryOperator(const clang::BinaryOperator* BinOp); 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/include/clad/Differentiator/CladUtils.h b/include/clad/Differentiator/CladUtils.h index ae2d26a99..d51a5c253 100644 --- a/include/clad/Differentiator/CladUtils.h +++ b/include/clad/Differentiator/CladUtils.h @@ -333,6 +333,11 @@ namespace clad { bool IsMemoryFunction(const clang::FunctionDecl* FD); bool IsMemoryDeallocationFunction(const clang::FunctionDecl* FD); + + /// Removes the local const qualifiers from a QualType and returns a new + /// type. + clang::QualType getNonConstType(clang::QualType T, clang::ASTContext& C, + clang::Sema& S); } // namespace utils } // namespace clad diff --git a/include/clad/Differentiator/DerivativeBuilder.h b/include/clad/Differentiator/DerivativeBuilder.h index 202856c7d..5b6614893 100644 --- a/include/clad/Differentiator/DerivativeBuilder.h +++ b/include/clad/Differentiator/DerivativeBuilder.h @@ -101,26 +101,6 @@ namespace clad { clang::SourceLocation& noLoc, clang::DeclarationNameInfo name, clang::QualType functionType); - /// Looks for a suitable overload for a given function. - /// - /// \param[in] Name The identification information of the function - /// overload to be found. - /// \param[in] CallArgs The call args to be used to resolve to the - /// correct overload. - /// \param[in] forCustomDerv A flag to keep track of which - /// namespace we should look in for the overloads. - /// \param[in] namespaceShouldExist A flag to enforce assertion failure - /// if the overload function namespace was not found. If false and - /// the function containing namespace was not found, nullptr is returned. - /// - /// \returns The call expression if a suitable function overload was found, - /// null otherwise. - clang::Expr* BuildCallToCustomDerivativeOrNumericalDiff( - const std::string& Name, llvm::SmallVectorImpl& CallArgs, - clang::Scope* S, clang::DeclContext* originalFnDC, - bool forCustomDerv = true, bool namespaceShouldExist = true); - bool noOverloadExists(clang::Expr* UnresolvedLookup, - llvm::MutableArrayRef ARargs); /// Shorthand to issues a warning or error. template void diag(clang::DiagnosticsEngine::Level level, // Warning or Error diff --git a/include/clad/Differentiator/Differentiator.h b/include/clad/Differentiator/Differentiator.h index 4a089c095..3c36da9ba 100644 --- a/include/clad/Differentiator/Differentiator.h +++ b/include/clad/Differentiator/Differentiator.h @@ -495,14 +495,14 @@ inline CUDA_HOST_DEVICE unsigned int GetLength(const char* code) { template > - CladFunction __attribute__((annotate("E"))) + CladFunction, true> __attribute__(( + annotate("E"))) estimate_error(F f, ArgSpec args = "", DerivedFnType derivedFn = static_cast(nullptr), const char* code = "") { - assert(f && "Must pass in a non-0 argument"); - return CladFunction< - DerivedFnType>(derivedFn /* will be replaced by estimation code*/, - code); + assert(f && "Must pass in a non-0 argument"); + return CladFunction, true>( + derivedFn /* will be replaced by estimation code*/, code); } // Gradient Structure for Reverse Mode Enzyme diff --git a/include/clad/Differentiator/FunctionTraits.h b/include/clad/Differentiator/FunctionTraits.h index c15eeb270..d84ac50d7 100644 --- a/include/clad/Differentiator/FunctionTraits.h +++ b/include/clad/Differentiator/FunctionTraits.h @@ -482,8 +482,7 @@ namespace clad { // GradientDerivedEstFnTraits specializations for pure function pointer types template struct GradientDerivedEstFnTraits { - using type = void (*)(Args..., OutputParamType_t..., - double&); + using type = void (*)(Args..., OutputParamType_t..., void*); }; /// These macro expansions are used to cover all possible cases of @@ -498,8 +497,8 @@ namespace clad { #define GradientDerivedEstFnTraits_AddSPECS(var, cv, vol, ref, noex) \ template \ struct GradientDerivedEstFnTraits { \ - using type = void (C::*)(Args..., OutputParamType_t..., \ - double&) cv vol ref noex; \ + using type = void (C::*)(Args..., OutputParamType_t..., \ + void*) cv vol ref noex; \ }; #if __cpp_noexcept_function_type > 0 diff --git a/include/clad/Differentiator/ReverseModeVisitor.h b/include/clad/Differentiator/ReverseModeVisitor.h index eb234b610..eea971a37 100644 --- a/include/clad/Differentiator/ReverseModeVisitor.h +++ b/include/clad/Differentiator/ReverseModeVisitor.h @@ -80,14 +80,6 @@ namespace clad { return "_grad"; } - /// Removes the local const qualifiers from a QualType and returns a new - /// type. - static clang::QualType - getNonConstType(clang::QualType T, clang::ASTContext& C, clang::Sema& S) { - clang::Qualifiers quals(T.getQualifiers()); - quals.removeConst(); - return S.BuildQualifiedType(T.getUnqualifiedType(), noLoc, quals); - } // Function to Differentiate with Clad as Backend void DifferentiateWithClad(); @@ -197,8 +189,9 @@ namespace clad { clang::VarDecl::InitializationStyle IS = clang::VarDecl::InitializationStyle::CInit) { assert(E && "cannot infer type from null expression"); - return StoreAndRef(E, getNonConstType(E->getType(), m_Context, m_Sema), d, - prefix, forceDeclCreation, IS); + return StoreAndRef( + E, clad::utils::getNonConstType(E->getType(), m_Context, m_Sema), d, + prefix, forceDeclCreation, IS); } /// An overload allowing to specify the type for the variable. @@ -443,7 +436,9 @@ namespace clad { /// Builds an overload for the gradient function that has derived params for /// all the arguments of the requested function and it calls the original /// gradient function internally - clang::FunctionDecl* CreateGradientOverload(); + /// \param[in] numExtraParam The number of extra parameters requested by an + /// external source (e.g. the final error in error estimation). + clang::FunctionDecl* CreateGradientOverload(unsigned numExtraParam = 0); /// Returns the type that should be used to represent the derivative of a /// variable of type `yType` with respect to a parameter variable of type diff --git a/include/clad/Differentiator/VisitorBase.h b/include/clad/Differentiator/VisitorBase.h index 122231896..d38d3c089 100644 --- a/include/clad/Differentiator/VisitorBase.h +++ b/include/clad/Differentiator/VisitorBase.h @@ -13,6 +13,7 @@ namespace clad { #include "Compatibility.h" #include "DerivativeBuilder.h" +#include "clad/Differentiator/CladUtils.h" #include "clad/Differentiator/DiffMode.h" #include "clang/AST/RecursiveASTVisitor.h" @@ -207,6 +208,8 @@ namespace clad { return QT->isArrayType() || QT->isPointerType(); } + static bool IsDifferentiableType(clang::QualType T); + clang::CompoundStmt* MakeCompoundStmt(const Stmts& Stmts); /// Get the latest block of code (i.e. place for statements output). @@ -646,6 +649,27 @@ namespace clad { void ComputeEffectiveDOperands(StmtDiff& LDiff, StmtDiff& RDiff, clang::Expr*& derivedL, clang::Expr*& derivedR); + /// Looks for a suitable overload for a given function. + /// + /// \param[in] Name The identification information of the function + /// overload to be found. + /// \param[in] CallArgs The call args to be used to resolve to the + /// correct overload. + /// \param[in] forCustomDerv A flag to keep track of which + /// namespace we should look in for the overloads. + /// \param[in] namespaceShouldExist A flag to enforce assertion failure + /// if the overload function namespace was not found. If false and + /// the function containing namespace was not found, nullptr is returned. + /// + /// \returns The call expression if a suitable function overload was found, + /// null otherwise. + clang::Expr* BuildCallToCustomDerivativeOrNumericalDiff( + const std::string& Name, llvm::SmallVectorImpl& CallArgs, + clang::Scope* S, const clang::FunctionDecl* originalFD, + bool forCustomDerv = true, bool namespaceShouldExist = true, + llvm::SmallVectorImpl* block = nullptr); + bool noOverloadExists(clang::Expr* UnresolvedLookup, + llvm::MutableArrayRef ARargs); }; } // end namespace clad diff --git a/lib/Differentiator/BaseForwardModeVisitor.cpp b/lib/Differentiator/BaseForwardModeVisitor.cpp index 5beab0cb3..342ecbd84 100644 --- a/lib/Differentiator/BaseForwardModeVisitor.cpp +++ b/lib/Differentiator/BaseForwardModeVisitor.cpp @@ -38,21 +38,6 @@ BaseForwardModeVisitor::BaseForwardModeVisitor(DerivativeBuilder& builder) BaseForwardModeVisitor::~BaseForwardModeVisitor() {} -bool BaseForwardModeVisitor::IsDifferentiableType(QualType T) { - QualType origType = T; - // FIXME: arbitrary dimension array type as well. - while (utils::isArrayOrPointerType(T)) - T = utils::GetValueType(T); - T = T.getNonReferenceType(); - if (T->isEnumeralType()) - return false; - if (T->isRealType() || T->isStructureOrClassType()) - return true; - if (origType->isPointerType() && T->isVoidType()) - return true; - return false; -} - bool IsRealNonReferenceType(QualType T) { return T.getNonReferenceType()->isRealType(); } @@ -224,7 +209,7 @@ BaseForwardModeVisitor::Derive(const FunctionDecl* FD, // non-reference type for creating the derivatives. QualType dParamType = param->getType().getNonReferenceType(); // We do not create derived variable for array/pointer parameters. - if (!BaseForwardModeVisitor::IsDifferentiableType(dParamType) || + if (!IsDifferentiableType(dParamType) || utils::isArrayOrPointerType(dParamType)) continue; Expr* dParam = nullptr; @@ -420,7 +405,7 @@ BaseForwardModeVisitor::DerivePushforward(const FunctionDecl* FD, for (auto* PVD : m_Function->parameters()) { paramTypes.push_back(PVD->getType()); - if (BaseForwardModeVisitor::IsDifferentiableType(PVD->getType())) + if (IsDifferentiableType(PVD->getType())) derivedParamTypes.push_back(GetPushForwardDerivativeType(PVD->getType())); } @@ -485,7 +470,7 @@ BaseForwardModeVisitor::DerivePushforward(const FunctionDecl* FD, if (identifierMissing) m_DeclReplacements[PVD] = newPVD; - if (!BaseForwardModeVisitor::IsDifferentiableType(PVD->getType())) + if (!IsDifferentiableType(PVD->getType())) continue; auto derivedPVDName = "_d_" + std::string(PVDII->getName()); IdentifierInfo* derivedPVDII = CreateUniqueIdentifier(derivedPVDName); @@ -1069,7 +1054,7 @@ StmtDiff BaseForwardModeVisitor::VisitCallExpr(const CallExpr* CE) { } } CallArgs.push_back(argDiff.getExpr()); - if (BaseForwardModeVisitor::IsDifferentiableType(arg->getType())) { + if (IsDifferentiableType(arg->getType())) { Expr* dArg = argDiff.getExpr_dx(); // FIXME: What happens when dArg is nullptr? diffArgs.push_back(dArg); @@ -1094,9 +1079,8 @@ StmtDiff BaseForwardModeVisitor::VisitCallExpr(const CallExpr* CE) { // Try to find a user-defined overloaded derivative. std::string customPushforward = clad::utils::ComputeEffectiveFnName(FD) + GetPushForwardFunctionSuffix(); - Expr* callDiff = m_Builder.BuildCallToCustomDerivativeOrNumericalDiff( - customPushforward, customDerivativeArgs, getCurrentScope(), - const_cast(FD->getDeclContext())); + Expr* callDiff = BuildCallToCustomDerivativeOrNumericalDiff( + customPushforward, customDerivativeArgs, getCurrentScope(), FD); // Check if it is a recursive call. if (!callDiff && (FD == m_Function) && m_Mode == GetPushForwardMode()) { @@ -1188,7 +1172,6 @@ StmtDiff BaseForwardModeVisitor::VisitCallExpr(const CallExpr* CE) { } } } - // If clad failed to derive it, try finding its derivative using // numerical diff. if (!callDiff) { @@ -1314,9 +1297,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) { @@ -1393,10 +1379,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); } @@ -1458,7 +1447,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()) @@ -1597,7 +1587,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())); @@ -1676,7 +1666,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/CladUtils.cpp b/lib/Differentiator/CladUtils.cpp index c180d0b1a..d4a2ba0ee 100644 --- a/lib/Differentiator/CladUtils.cpp +++ b/lib/Differentiator/CladUtils.cpp @@ -684,5 +684,12 @@ namespace clad { return FD->getNameAsString() == "free"; #endif } + + clang::QualType getNonConstType(clang::QualType T, clang::ASTContext& C, + clang::Sema& S) { + clang::Qualifiers quals(T.getQualifiers()); + quals.removeConst(); + return S.BuildQualifiedType(T.getUnqualifiedType(), noLoc, quals); + } } // namespace utils } // namespace clad diff --git a/lib/Differentiator/DerivativeBuilder.cpp b/lib/Differentiator/DerivativeBuilder.cpp index 861f1dc60..8e493ff05 100644 --- a/lib/Differentiator/DerivativeBuilder.cpp +++ b/lib/Differentiator/DerivativeBuilder.cpp @@ -138,125 +138,6 @@ static void registerDerivative(FunctionDecl* derivedFD, Sema& semaRef) { return { returnedFD, enclosingNS }; } - // This method is derived from the source code of both - // buildOverloadedCallSet() in SemaOverload.cpp - // and ActOnCallExpr() in SemaExpr.cpp. - bool - DerivativeBuilder::noOverloadExists(Expr* UnresolvedLookup, - llvm::MutableArrayRef ARargs) { - if (UnresolvedLookup->getType() == m_Context.OverloadTy) { - OverloadExpr::FindResult find = OverloadExpr::find(UnresolvedLookup); - - if (!find.HasFormOfMemberPointer) { - OverloadExpr* ovl = find.Expression; - - if (isa(ovl)) { - ExprResult result; - SourceLocation Loc; - OverloadCandidateSet CandidateSet(Loc, - OverloadCandidateSet::CSK_Normal); - Scope* S = m_Sema.getScopeForContext(m_Sema.CurContext); - auto* ULE = cast(ovl); - // Populate CandidateSet. - m_Sema.buildOverloadedCallSet(S, UnresolvedLookup, ULE, ARargs, Loc, - &CandidateSet, &result); - OverloadCandidateSet::iterator Best = nullptr; - OverloadingResult OverloadResult = CandidateSet.BestViableFunction( - m_Sema, UnresolvedLookup->getBeginLoc(), Best); - if (OverloadResult != 0U) // No overloads were found. - return true; - } - } - } - return false; - } - - Expr* DerivativeBuilder::BuildCallToCustomDerivativeOrNumericalDiff( - const std::string& Name, llvm::SmallVectorImpl& CallArgs, - clang::Scope* S, clang::DeclContext* originalFnDC, - bool forCustomDerv /*=true*/, bool namespaceShouldExist /*=true*/) { - NamespaceDecl* NSD = nullptr; - std::string namespaceID; - if (forCustomDerv) { - namespaceID = "custom_derivatives"; - NamespaceDecl* cladNS = nullptr; - if (m_BuiltinDerivativesNSD) - NSD = m_BuiltinDerivativesNSD; - else { - cladNS = utils::LookupNSD(m_Sema, "clad", /*shouldExist=*/true); - NSD = - utils::LookupNSD(m_Sema, namespaceID, namespaceShouldExist, cladNS); - m_BuiltinDerivativesNSD = NSD; - } - } else { - NSD = m_NumericalDiffNSD; - namespaceID = "numerical_diff"; - } - if (!NSD) { - NSD = utils::LookupNSD(m_Sema, namespaceID, namespaceShouldExist); - if (!forCustomDerv && !NSD) { - diag(DiagnosticsEngine::Warning, noLoc, - "Numerical differentiation is diabled using the " - "-DCLAD_NO_NUM_DIFF " - "flag, this means that every try to numerically differentiate a " - "function will fail! Remove the flag to revert to default " - "behaviour."); - return nullptr; - } - } - CXXScopeSpec SS; - DeclContext* DC = NSD; - - // FIXME: Here `if` branch should be removed once we update - // numerical diff to use correct declaration context. - if (forCustomDerv) { - DeclContext* outermostDC = utils::GetOutermostDC(m_Sema, originalFnDC); - // FIXME: We should ideally construct nested name specifier from the - // found custom derivative function. Current way will compute incorrect - // nested name specifier in some cases. - if (outermostDC && - outermostDC->getPrimaryContext() == NSD->getPrimaryContext()) { - utils::BuildNNS(m_Sema, originalFnDC, SS); - DC = originalFnDC; - } else { - if (isa(originalFnDC)) - DC = utils::LookupNSD(m_Sema, "class_functions", - /*shouldExist=*/false, NSD); - else - DC = utils::FindDeclContext(m_Sema, NSD, originalFnDC); - if (DC) - utils::BuildNNS(m_Sema, DC, SS); - } - } else { - SS.Extend(m_Context, NSD, noLoc, noLoc); - } - IdentifierInfo* II = &m_Context.Idents.get(Name); - DeclarationName name(II); - DeclarationNameInfo DNInfo(name, utils::GetValidSLoc(m_Sema)); - - LookupResult R(m_Sema, DNInfo, Sema::LookupOrdinaryName); - if (DC) - m_Sema.LookupQualifiedName(R, DC); - Expr* OverloadedFn = nullptr; - if (!R.empty()) { - // FIXME: We should find a way to specify nested name specifier - // after finding the custom derivative. - Expr* UnresolvedLookup = - m_Sema.BuildDeclarationNameExpr(SS, R, /*ADL*/ false).get(); - - auto MARargs = llvm::MutableArrayRef(CallArgs); - - SourceLocation Loc; - - if (noOverloadExists(UnresolvedLookup, MARargs)) - return nullptr; - - OverloadedFn = - m_Sema.ActOnCallExpr(S, UnresolvedLookup, Loc, MARargs, Loc).get(); - } - return OverloadedFn; - } - void DerivativeBuilder::AddErrorEstimationModel( std::unique_ptr estModel) { m_EstModel.push_back(std::move(estModel)); diff --git a/lib/Differentiator/ErrorEstimator.cpp b/lib/Differentiator/ErrorEstimator.cpp index da3396dbc..040e54cde 100644 --- a/lib/Differentiator/ErrorEstimator.cpp +++ b/lib/Differentiator/ErrorEstimator.cpp @@ -285,7 +285,7 @@ void ErrorEstimationHandler::ActAfterCreatingDerivedFnParamTypes( // If we are performing error estimation, our gradient function // will have an extra argument which will hold the final error value paramTypes.push_back( - m_RMV->m_Context.getLValueReferenceType(m_RMV->m_Context.DoubleTy)); + m_RMV->m_Context.getPointerType(m_RMV->m_Context.DoubleTy)); } void ErrorEstimationHandler::ActAfterCreatingDerivedFnParams( @@ -307,7 +307,8 @@ void ErrorEstimationHandler::ActAfterCreatingDerivedFnParams( void ErrorEstimationHandler::ActBeforeCreatingDerivedFnBodyScope() { // Reference to the final error statement - SetFinalErrorExpr(m_RMV->BuildDeclRef(m_Params->back())); + DeclRefExpr* DRE = m_RMV->BuildDeclRef(m_Params->back()); + SetFinalErrorExpr(m_RMV->BuildOp(UO_Deref, DRE)); } void ErrorEstimationHandler::ActOnEndOfDerivedFnBody() { @@ -468,12 +469,13 @@ void ErrorEstimationHandler::ActBeforeFinalizingDifferentiateSingleExpr( void ErrorEstimationHandler::ActBeforeDifferentiatingCallExpr( llvm::SmallVectorImpl& pullbackArgs, llvm::SmallVectorImpl& ArgDecls, bool hasAssignee) { - auto errorRef = + VarDecl* errorRef = m_RMV->BuildVarDecl(m_RMV->m_Context.DoubleTy, "_t", m_RMV->getZeroInit(m_RMV->m_Context.DoubleTy)); ArgDecls.push_back(m_RMV->BuildDeclStmt(errorRef)); - auto finErr = m_RMV->BuildDeclRef(errorRef); - pullbackArgs.push_back(finErr); + Expr* finErr = m_RMV->BuildDeclRef(errorRef); + Expr* arg = m_RMV->BuildOp(UO_AddrOf, finErr); + pullbackArgs.push_back(arg); if (hasAssignee) { if (m_NestedFuncError) m_NestedFuncError = m_RMV->BuildOp(BO_Add, m_NestedFuncError, finErr); @@ -488,9 +490,13 @@ void ErrorEstimationHandler::ActBeforeFinalizingVisitDeclStmt( // For all dependent variables, we register them for estimation // here. for (size_t i = 0; i < decls.size(); i++) { - DeclDiff VDDiff(cast(decls[0]), - cast(declsDiff[0])); - EmitDeclErrorStmts(VDDiff, m_RMV->isInsideLoop); + auto found = m_RMV->m_Variables.find(cast(decls[i])); + if (found != m_RMV->m_Variables.end()) { + DeclDiff VDDiff( + cast(decls[i]), + cast(cast(found->second)->getDecl())); + EmitDeclErrorStmts(VDDiff, m_RMV->isInsideLoop); + } } } } // namespace clad diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index f9ec442d8..03847ec2b 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -70,8 +70,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, ReverseModeVisitor::MakeCladTapeFor(Expr* E, llvm::StringRef prefix) { assert(E && "must be provided"); E = E->IgnoreImplicit(); - QualType TapeType = - GetCladTapeOfType(getNonConstType(E->getType(), m_Context, m_Sema)); + QualType TapeType = GetCladTapeOfType( + utils::getNonConstType(E->getType(), m_Context, m_Sema)); LookupResult& Push = GetCladTapePush(); LookupResult& Pop = GetCladTapePop(); Expr* TapeRef = @@ -113,7 +113,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } } - FunctionDecl* ReverseModeVisitor::CreateGradientOverload() { + FunctionDecl* + ReverseModeVisitor::CreateGradientOverload(unsigned numExtraParam) { auto gradientParams = m_Derivative->parameters(); auto gradientNameInfo = m_Derivative->getNameInfo(); // Calculate the total number of parameters that would be required for @@ -121,8 +122,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // requested. // FIXME: Here we are assuming all function parameters are of differentiable // type. Ideally, we should not make any such assumption. - std::size_t totalDerivedParamsSize = m_Function->getNumParams() * 2; - std::size_t numOfDerivativeParams = m_Function->getNumParams(); + std::size_t totalDerivedParamsSize = + m_Function->getNumParams() * 2 + numExtraParam; + std::size_t numOfDerivativeParams = + m_Function->getNumParams() + numExtraParam; // Account for the this pointer. if (isa(m_Function) && !utils::IsStaticMethod(m_Function)) @@ -269,11 +272,16 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, if (request.Args) { DVI = request.DVI; for (const auto& dParam : DVI) - args.push_back(dParam.param); + // no need to create adjoints for non-differentiable parameters. + if (IsDifferentiableType(dParam.param->getType())) + args.push_back(dParam.param); } else std::copy(FD->param_begin(), FD->param_end(), std::back_inserter(args)); - if (args.empty()) + // If there are no parameters to differentiate with respect to, don't + // generate the gradient. However, if an external source is attached, the + // gradient function can another purpose. + if (args.empty() && !m_ExternalSource) return {}; if (m_ExternalSource) @@ -336,9 +344,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // If reverse mode differentiates only part of the arguments it needs to // generate an overload that can take in all the diff variables bool shouldCreateOverload = false; - // FIXME: Gradient overload doesn't know how to handle additional parameters - // added by the plugins yet. - if (!isVectorValued && numExtraParam == 0) + if (!isVectorValued) shouldCreateOverload = true; if (request.DerivedFDPrototype) // If the overload is already created, we don't need to create it again. @@ -452,8 +458,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, FunctionDecl* gradientOverloadFD = nullptr; if (shouldCreateOverload) { - gradientOverloadFD = - CreateGradientOverload(); + gradientOverloadFD = CreateGradientOverload(numExtraParam); } return DerivativeAndOverload{result.first, gradientOverloadFD}; @@ -596,6 +601,9 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // independent variables (args). for (std::size_t i = 0; i < m_Function->getNumParams(); ++i) { ParmVarDecl* param = paramsRef[i]; + // no need to create adjoints for non-differentiable variables. + if (!IsDifferentiableType(param->getType())) + continue; // derived variables are already created for independent variables. if (m_Variables.count(param)) continue; @@ -656,8 +664,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // Prepare Arguments and Parameters to enzyme_autodiff llvm::SmallVector enzymeArgs; llvm::SmallVector enzymeParams; - llvm::SmallVector enzymeRealParams; - llvm::SmallVector enzymeRealParamsDerived; + llvm::SmallVector enzymeRealParamsDerived; // First add the function itself as a parameter/argument enzymeArgs.push_back(BuildDeclRef(const_cast(m_Function))); @@ -668,23 +675,23 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // Add rest of the parameters/arguments for (unsigned i = 0; i < numParams; i++) { + ParmVarDecl* param = paramsRef[i]; // First Add the original parameter - enzymeArgs.push_back(BuildDeclRef(paramsRef[i])); + enzymeArgs.push_back(BuildDeclRef(param)); enzymeParams.push_back(m_Sema.BuildParmVarDeclForTypedef( - fdDeclContext, noLoc, paramsRef[i]->getType())); + fdDeclContext, noLoc, param->getType())); QualType paramType = origParams[i]->getOriginalType(); // If original parameter is of a differentiable real type(but not // array/pointer), then add it to the list of params whose gradient must // be extracted later from the EnzymeGradient structure if (paramType->isRealFloatingType()) { - enzymeRealParams.push_back(paramsRef[i]); - enzymeRealParamsDerived.push_back(paramsRef[numParams + i]); + enzymeRealParamsDerived.push_back(m_Variables[param]); } else if (utils::isArrayOrPointerType(paramType)) { // Add the corresponding array/pointer variable - enzymeArgs.push_back(BuildDeclRef(paramsRef[numParams + i])); + enzymeArgs.push_back(m_Variables[param]); enzymeParams.push_back(m_Sema.BuildParmVarDeclForTypedef( - fdDeclContext, noLoc, paramsRef[numParams + i]->getType())); + fdDeclContext, noLoc, m_Variables[param]->getType())); } } @@ -693,12 +700,12 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, enzymeParamsType.push_back(i->getType()); QualType QT; - if (!enzymeRealParams.empty()) { + if (!enzymeRealParamsDerived.empty()) { // Find the EnzymeGradient datastructure auto* gradDecl = LookupTemplateDeclInCladNamespace("EnzymeGradient"); TemplateArgumentListInfo TLI{}; - llvm::APSInt argValue(std::to_string(enzymeRealParams.size())); + llvm::APSInt argValue(std::to_string(enzymeRealParamsDerived.size())); TemplateArgument TA(m_Context, argValue, m_Context.UnsignedIntTy); TLI.addArgument(TemplateArgumentLoc(TA, TemplateArgumentLocInfo())); @@ -723,13 +730,12 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // Prepare the statements that assign the gradients to // non array/pointer type parameters of the original function - if (!enzymeRealParams.empty()) { + if (!enzymeRealParamsDerived.empty()) { auto* gradDeclStmt = BuildVarDecl(QT, "grad", enzymeCall, true); addToCurrentBlock(BuildDeclStmt(gradDeclStmt), direction::forward); - for (unsigned i = 0; i < enzymeRealParams.size(); i++) { - auto* LHSExpr = - BuildOp(UO_Deref, BuildDeclRef(enzymeRealParamsDerived[i])); + for (unsigned i = 0; i < enzymeRealParamsDerived.size(); i++) { + auto* LHSExpr = Clone(enzymeRealParamsDerived[i]); auto* ME = utils::BuildMemberExpr(m_Sema, getCurrentScope(), BuildDeclRef(gradDeclStmt), "d_arr"); @@ -746,7 +752,6 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } } else { // Add Function call to block - Expr* enzymeCall = BuildCallExprToFunction(enzymeCallFD, enzymeArgs); addToCurrentBlock(enzymeCall); } } @@ -1513,7 +1518,9 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // We do not need to create result arg for arguments passed by reference // because the derivatives of arguments passed by reference are directly // modified by the derived callee function. - if (utils::IsReferenceOrPointerArg(arg)) { + // Also, no need to create adjoint variables for non-differentiable types. + if (utils::IsReferenceOrPointerArg(arg) || + !IsDifferentiableType(arg->getType())) { argDiff = Visit(arg); CallArgDx.push_back(argDiff.getExpr_dx()); } else { @@ -1523,7 +1530,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // is done to reduce cloning complexity and only clone once. The type is // same as the call expression as it is the type used to declare the // _gradX array - QualType dArgTy = getNonConstType(arg->getType(), m_Context, m_Sema); + QualType dArgTy = + utils::getNonConstType(arg->getType(), m_Context, m_Sema); VarDecl* dArgDecl = BuildVarDecl(dArgTy, "_r", getZeroInit(dArgTy)); PreCallStmts.push_back(BuildDeclStmt(dArgDecl)); CallArgDx.push_back(BuildDeclRef(dArgDecl)); @@ -1640,10 +1648,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, auto pushforwardCallArgs = DerivedCallArgs; pushforwardCallArgs.push_back(ConstantFolder::synthesizeLiteral( DerivedCallArgs.front()->getType(), m_Context, 1)); - OverloadedDerivedFn = - m_Builder.BuildCallToCustomDerivativeOrNumericalDiff( - customPushforward, pushforwardCallArgs, getCurrentScope(), - const_cast(FD->getDeclContext())); + OverloadedDerivedFn = BuildCallToCustomDerivativeOrNumericalDiff( + customPushforward, pushforwardCallArgs, getCurrentScope(), FD); if (OverloadedDerivedFn) asGrad = false; } @@ -1698,12 +1704,14 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, for (auto* argDerivative : CallArgDx) { Expr* gradArgExpr = nullptr; const Expr* arg = CE->getArg(idx); - if (utils::isArrayOrPointerType(arg->getType()) || - isCladArrayType(argDerivative->getType())) - gradArgExpr = argDerivative; - else - gradArgExpr = - BuildOp(UO_AddrOf, argDerivative, m_Function->getLocation()); + if (argDerivative) { + if (utils::isArrayOrPointerType(arg->getType()) || + isCladArrayType(argDerivative->getType())) + gradArgExpr = argDerivative; + else if (argDerivative->isLValue()) + gradArgExpr = + BuildOp(UO_AddrOf, argDerivative, m_Function->getLocation()); + } DerivedCallOutputArgs.push_back(gradArgExpr); idx++; } @@ -1735,10 +1743,11 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, BuildOp(UnaryOperatorKind::UO_AddrOf, baseDiff.getExpr())); std::string customPullback = clad::utils::ComputeEffectiveFnName(FD) + "_pullback"; - OverloadedDerivedFn = - m_Builder.BuildCallToCustomDerivativeOrNumericalDiff( - customPullback, pullbackCallArgs, getCurrentScope(), - const_cast(FD->getDeclContext())); + OverloadedDerivedFn = BuildCallToCustomDerivativeOrNumericalDiff( + customPullback, pullbackCallArgs, getCurrentScope(), FD, + /*forCustomDerv=*/true, + /*namespaceShouldExist=*/true, + /*block=*/&PreCallStmts); if (baseDiff.getExpr()) pullbackCallArgs.erase(pullbackCallArgs.begin()); } @@ -1815,7 +1824,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, /*numArgs=*/1, DerivedCallArgs); asGrad = !OverloadedDerivedFn; } else { - auto CEType = getNonConstType(CE->getType(), m_Context, m_Sema); + auto CEType = + utils::getNonConstType(CE->getType(), m_Context, m_Sema); OverloadedDerivedFn = GetMultiArgCentralDiffCall( Clone(CE->getCallee()), CEType.getCanonicalType(), CE->getNumArgs(), dfdx(), PreCallStmts, PostCallStmts, @@ -2015,8 +2025,11 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, NumDiffArgs.push_back(args[i]); } std::string Name = "central_difference"; - return m_Builder.BuildCallToCustomDerivativeOrNumericalDiff( - Name, NumDiffArgs, getCurrentScope(), /*OriginalFnDC=*/nullptr, + const FunctionDecl* FD = nullptr; + if (auto* DRE = dyn_cast(targetFuncCall->IgnoreImplicit())) + FD = dyn_cast(DRE->getDecl()); + return BuildCallToCustomDerivativeOrNumericalDiff( + Name, NumDiffArgs, getCurrentScope(), /*OriginalFD=*/FD, /*forCustomDerv=*/false, /*namespaceShouldExist=*/false); } @@ -2319,6 +2332,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, addToCurrentBlock(Reverse, direction::reverse); for (Stmt* S : cast(ReturnDiff.getStmt())->body()) addToCurrentBlock(S, direction::forward); + return BuildOp(opCode, Clone(L), ReturnResult.second.getExpr()); } } } @@ -2346,24 +2360,6 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } Expr* LCloned = Ldiff.getExpr(); - // For x, AssignedDiff is _d_x, for x[i] its _d_x[i], for reference exprs - // like (x = y) it propagates recursively, so _d_x is also returned. - Expr* AssignedDiff = Ldiff.getExpr_dx(); - if (!AssignedDiff) { - // If either LHS or RHS is a declaration reference, visit it to avoid - // naming collision - auto* LDRE = dyn_cast(L); - auto* RDRE = dyn_cast(R); - - if (!LDRE && !RDRE) - return Clone(BinOp); - - Expr* LExpr = LDRE ? Visit(L).getExpr() : L; - Expr* RExpr = RDRE ? Visit(R).getExpr() : R; - - return BuildOp(opCode, LExpr, RExpr); - } - ResultRef = AssignedDiff; // If assigned expr is dependent, first update its derivative; auto Lblock_begin = Lblock->body_rbegin(); auto Lblock_end = Lblock->body_rend(); @@ -2382,6 +2378,15 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, if (m_ExternalSource) m_ExternalSource->ActAfterCloningLHSOfAssignOp(LCloned, R, opCode); + // For x, AssignedDiff is _d_x, for x[i] its _d_x[i], for reference exprs + // like (x = y) it propagates recursively, so _d_x is also returned. + Expr* AssignedDiff = Ldiff.getExpr_dx(); + // If the LHS is non-differentiable, differentiate the RHS + // and clone the operation + if (!AssignedDiff) + return BuildOp(opCode, Ldiff.getExpr(), Visit(R).getExpr()); + ResultRef = AssignedDiff; + // Save old value for the derivative of LHS, to avoid problems with cases // like x = x. clang::Expr* oldValue = nullptr; @@ -2553,6 +2558,26 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, if (isPointerType && VD->getInit() && isa(VD->getInit())) isInitializedByNewExpr = true; + // Integer types are not differentiable, + // no need to construct an adjoint. + if (!IsDifferentiableType(VD->getType())) { + Expr* init = nullptr; + if (VD->getInit()) + init = Visit(VD->getInit()).getExpr(); + // If a ref-type declaration is promoted to function global scope, + // it's replaced with a pointer and should be initialized with the + // address of the cloned init. e.g. + // double& ref = x; + // -> + // double* ref; + // ref = &x; + if (isDerivativeOfRefType && promoteToFnScope) + init = BuildOp(UnaryOperatorKind::UO_AddrOf, init); + return BuildGlobalVarDecl(VDCloneType, VD->getNameAsString(), init, + VD->isDirectInit(), nullptr, + VD->getInitStyle()); + } + // VDDerivedInit now serves two purposes -- as the initial derivative value // or the size of the derivative array -- depending on the primal type. if (const auto* AT = dyn_cast(VD->getType())) { @@ -2616,7 +2641,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // Computation of hessian requires this code to be correctly // differentiated. if (specialThisDiffCase && VD->getNameAsString() == "_d_this") { - VDDerivedType = getNonConstType(VDDerivedType, m_Context, m_Sema); + VDDerivedType = + utils::getNonConstType(VDDerivedType, m_Context, m_Sema); initDiff = Visit(VD->getInit()); if (initDiff.getExpr_dx()) VDDerivedInit = initDiff.getExpr_dx(); @@ -2624,7 +2650,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // if VD is a pointer type, then the initial value is set to the derived // expression of the corresponding pointer type. else if (isPointerType && VD->getInit()) { - VDDerivedType = getNonConstType(VDDerivedType, m_Context, m_Sema); + VDDerivedType = + utils::getNonConstType(VDDerivedType, m_Context, m_Sema); // If it's a pointer to a constant type, then remove the constness. if (VD->getType()->getPointeeType().isConstQualified()) { // first extract the pointee type @@ -2864,10 +2891,12 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, } decls.push_back(VDDiff.getDecl()); - if (isa(VD->getType())) - localDeclsDiff.push_back(VDDiff.getDecl_dx()); - else - declsDiff.push_back(VDDiff.getDecl_dx()); + if (VDDiff.getDecl_dx()) { + if (isa(VD->getType())) + localDeclsDiff.push_back(VDDiff.getDecl_dx()); + else + declsDiff.push_back(VDDiff.getDecl_dx()); + } } else if (auto* SAD = dyn_cast(D)) { DeclDiff SADDiff = DifferentiateStaticAssertDecl(SAD); if (SADDiff.getDecl()) @@ -3090,7 +3119,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, bool force) { assert(E && "cannot infer type"); return GlobalStoreAndRef( - E, getNonConstType(E->getType(), m_Context, m_Sema), prefix, force); + E, utils::getNonConstType(E->getType(), m_Context, m_Sema), prefix, + force); } StmtDiff ReverseModeVisitor::BuildPushPop(clang::Expr* E, @@ -3114,7 +3144,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, StmtDiff ReverseModeVisitor::StoreAndRestore(clang::Expr* E, llvm::StringRef prefix, bool force) { - auto Type = getNonConstType(E->getType(), m_Context, m_Sema); + auto Type = utils::getNonConstType(E->getType(), m_Context, m_Sema); if (!force && !UsefulToStoreGlobal(E)) return {}; @@ -3180,7 +3210,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, /*isInsideLoop*/ true, /*pNeedsUpdate=*/true}; } Expr* Ref = BuildDeclRef(GlobalStoreImpl( - getNonConstType(E->getType(), m_Context, m_Sema), prefix)); + utils::getNonConstType(E->getType(), m_Context, m_Sema), prefix)); // Return reference to the declaration instead of original expression. return DelayedStoreResult{*this, StmtDiff{Ref, nullptr, nullptr, Ref}, /*isConstant*/ false, diff --git a/lib/Differentiator/VisitorBase.cpp b/lib/Differentiator/VisitorBase.cpp index 18eb303fb..4994b7647 100644 --- a/lib/Differentiator/VisitorBase.cpp +++ b/lib/Differentiator/VisitorBase.cpp @@ -8,7 +8,6 @@ #include "ConstantFolder.h" -#include "clad/Differentiator/CladUtils.h" #include "clad/Differentiator/DiffPlanner.h" #include "clad/Differentiator/ErrorEstimator.h" #include "clad/Differentiator/Sins.h" @@ -731,8 +730,11 @@ namespace clad { NumDiffArgs.insert(NumDiffArgs.end(), args.begin(), args.begin() + numArgs); // Return the found overload. std::string Name = "forward_central_difference"; - return m_Builder.BuildCallToCustomDerivativeOrNumericalDiff( - Name, NumDiffArgs, getCurrentScope(), /*OriginalFnDC=*/nullptr, + const FunctionDecl* FD = nullptr; + if (auto* DRE = dyn_cast(targetFuncCall->IgnoreImplicit())) + FD = dyn_cast(DRE->getDecl()); + return BuildCallToCustomDerivativeOrNumericalDiff( + Name, NumDiffArgs, getCurrentScope(), /*OriginalFD=*/FD, /*forCustomDerv=*/false, /*namespaceShouldExist=*/false); } @@ -812,4 +814,186 @@ namespace clad { return m_Sema.ActOnCallExpr(getCurrentScope(), pushDRE, noLoc, args, noLoc) .get(); } + + Expr* VisitorBase::BuildCallToCustomDerivativeOrNumericalDiff( + const std::string& Name, llvm::SmallVectorImpl& CallArgs, + clang::Scope* S, const clang::FunctionDecl* originalFD, + bool forCustomDerv /*=true*/, bool namespaceShouldExist /*=true*/, + llvm::SmallVectorImpl* block /*=nullptr*/) { + DeclContext* originalFnDC = nullptr; + if (originalFD) + originalFnDC = const_cast(originalFD->getDeclContext()); + NamespaceDecl* NSD = nullptr; + std::string namespaceID; + if (forCustomDerv) { + namespaceID = "custom_derivatives"; + NamespaceDecl* cladNS = nullptr; + if (m_Builder.m_BuiltinDerivativesNSD) + NSD = m_Builder.m_BuiltinDerivativesNSD; + else { + cladNS = utils::LookupNSD(m_Sema, "clad", /*shouldExist=*/true); + NSD = + utils::LookupNSD(m_Sema, namespaceID, namespaceShouldExist, cladNS); + m_Builder.m_BuiltinDerivativesNSD = NSD; + } + } else { + NSD = m_Builder.m_NumericalDiffNSD; + namespaceID = "numerical_diff"; + } + if (!NSD) { + NSD = utils::LookupNSD(m_Sema, namespaceID, namespaceShouldExist); + if (!forCustomDerv && !NSD) { + diag(DiagnosticsEngine::Warning, noLoc, + "Numerical differentiation is disabled using the " + "-DCLAD_NO_NUM_DIFF " + "flag, this means that every try to numerically differentiate a " + "function will fail! Remove the flag to revert to default " + "behaviour."); + return nullptr; + } + } + CXXScopeSpec SS; + DeclContext* DC = NSD; + + // FIXME: Here `if` branch should be removed once we update + // numerical diff to use correct declaration context. + if (forCustomDerv) { + DeclContext* outermostDC = utils::GetOutermostDC(m_Sema, originalFnDC); + // FIXME: We should ideally construct nested name specifier from the + // found custom derivative function. Current way will compute incorrect + // nested name specifier in some cases. + if (outermostDC && + outermostDC->getPrimaryContext() == NSD->getPrimaryContext()) { + utils::BuildNNS(m_Sema, originalFnDC, SS); + DC = originalFnDC; + } else { + if (isa(originalFnDC)) + DC = utils::LookupNSD(m_Sema, "class_functions", + /*shouldExist=*/false, NSD); + else + DC = utils::FindDeclContext(m_Sema, NSD, originalFnDC); + if (DC) + utils::BuildNNS(m_Sema, DC, SS); + } + } else { + SS.Extend(m_Context, NSD, noLoc, noLoc); + } + IdentifierInfo* II = &m_Context.Idents.get(Name); + DeclarationName name(II); + DeclarationNameInfo DNInfo(name, utils::GetValidSLoc(m_Sema)); + + LookupResult R(m_Sema, DNInfo, Sema::LookupOrdinaryName); + if (DC) + m_Sema.LookupQualifiedName(R, DC); + Expr* OverloadedFn = nullptr; + if (!R.empty()) { + // FIXME: We should find a way to specify nested name specifier + // after finding the custom derivative. + Expr* UnresolvedLookup = + m_Sema.BuildDeclarationNameExpr(SS, R, /*ADL*/ false).get(); + + llvm::SmallVector ExtendedCallArgs; + llvm::SmallVector DeclStmts; + 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)); + } + } + 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) + .get(); + if (!DeclStmts.empty()) { + if (!block) + block = &getCurrentBlock(); + for (Stmt* decl : DeclStmts) + block->push_back(decl); + } + } + return OverloadedFn; + } + + // This method is derived from the source code of both + // buildOverloadedCallSet() in SemaOverload.cpp + // and ActOnCallExpr() in SemaExpr.cpp. + bool VisitorBase::noOverloadExists(Expr* UnresolvedLookup, + llvm::MutableArrayRef ARargs) { + if (UnresolvedLookup->getType() == m_Context.OverloadTy) { + OverloadExpr::FindResult find = OverloadExpr::find(UnresolvedLookup); + + if (!find.HasFormOfMemberPointer) { + OverloadExpr* ovl = find.Expression; + + if (isa(ovl)) { + ExprResult result; + SourceLocation Loc; + OverloadCandidateSet CandidateSet(Loc, + OverloadCandidateSet::CSK_Normal); + Scope* S = m_Sema.getScopeForContext(m_Sema.CurContext); + auto* ULE = cast(ovl); + // Populate CandidateSet. + m_Sema.buildOverloadedCallSet(S, UnresolvedLookup, ULE, ARargs, Loc, + &CandidateSet, &result); + OverloadCandidateSet::iterator Best = nullptr; + OverloadingResult OverloadResult = CandidateSet.BestViableFunction( + m_Sema, UnresolvedLookup->getBeginLoc(), Best); + if (OverloadResult != 0U) // No overloads were found. + return true; + } + } + return false; + } + if (const auto* DRE = dyn_cast(UnresolvedLookup)) { + const auto* FD = cast(DRE->getDecl()); + return FD->getNumParams() != ARargs.size(); + } + return false; + } + + bool VisitorBase::IsDifferentiableType(QualType T) { + QualType origType = T; + // FIXME: arbitrary dimension array type as well. + while (utils::isArrayOrPointerType(T)) + T = utils::GetValueType(T); + T = T.getNonReferenceType(); + if (T->isEnumeralType()) + return false; + if (T->isFloatingType() || T->isStructureOrClassType()) + return true; + if (origType->isPointerType() && T->isVoidType()) + return true; + return false; + } } // end namespace clad 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/ArrayInputsReverseMode.C b/test/Arrays/ArrayInputsReverseMode.C index 91931c51d..6f1336476 100644 --- a/test/Arrays/ArrayInputsReverseMode.C +++ b/test/Arrays/ArrayInputsReverseMode.C @@ -15,19 +15,16 @@ double addArr(const double *arr, int n) { return ret; } -//CHECK: void addArr_pullback(const double *arr, int n, double _d_y, double *_d_arr, int *_d_n); +//CHECK: void addArr_pullback(const double *arr, int n, double _d_y, double *_d_arr); double f(double *arr) { return addArr(arr, 3); } //CHECK: void f_grad(double *arr, double *_d_arr) { -//CHECK-NEXT: goto _label0; -//CHECK-NEXT: _label0: -//CHECK-NEXT: { -//CHECK-NEXT: int _r0 = 0; -//CHECK-NEXT: addArr_pullback(arr, 3, 1, _d_arr, &_r0); -//CHECK-NEXT: } +//CHECK-NEXT: goto _label0; +//CHECK-NEXT: _label0: +//CHECK-NEXT: addArr_pullback(arr, 3, 1, _d_arr); //CHECK-NEXT: } float func(float* a, float* b) { @@ -42,7 +39,6 @@ float func(float* a, float* b) { //CHECK: void func_grad(float *a, float *b, float *_d_a, float *_d_b) { //CHECK-NEXT: float _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _t2 = {}; @@ -91,7 +87,6 @@ float func2(float* a) { //CHECK: void func2_grad(float *a, float *_d_a) { //CHECK-NEXT: float _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: float sum = 0; @@ -124,7 +119,6 @@ float func3(float* a, float* b) { //CHECK: void func3_grad(float *a, float *b, float *_d_a, float *_d_b) { //CHECK-NEXT: float _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _t2 = {}; @@ -163,7 +157,6 @@ double func4(double x) { //CHECK-NEXT: double _d_arr[3] = {0}; //CHECK-NEXT: double _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double arr[3] = {x, 2 * x, x * x}; @@ -182,8 +175,7 @@ double func4(double x) { //CHECK-NEXT: { //CHECK-NEXT: sum = clad::pop(_t1); //CHECK-NEXT: double _r_d0 = _d_sum; -//CHECK-NEXT: int _r0 = 0; -//CHECK-NEXT: addArr_pullback(arr, 3, _r_d0, _d_arr, &_r0); +//CHECK-NEXT: addArr_pullback(arr, 3, _r_d0, _d_arr); //CHECK-NEXT: } //CHECK-NEXT: } //CHECK-NEXT: { @@ -194,7 +186,7 @@ double func4(double x) { //CHECK-NEXT: } //CHECK-NEXT: } -double func5(int k) { +double func5(float k) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunknown-warning-option" #pragma clang diagnostic ignored "-Wvla-cxx-extension" @@ -211,15 +203,12 @@ double func5(int k) { return sum; } -//CHECK: void func5_grad(int k, int *_d_k) { -//CHECK-NEXT: int _d_n = 0; +//CHECK: void func5_grad(float k, float *_d_k) { //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t2; -//CHECK-NEXT: int _d_i0 = 0; //CHECK-NEXT: int i0 = 0; //CHECK-NEXT: clad::tape _t3 = {}; //CHECK-NEXT: int n = k; @@ -247,9 +236,7 @@ double func5(int k) { //CHECK-NEXT: { //CHECK-NEXT: sum = clad::pop(_t3); //CHECK-NEXT: double _r_d1 = _d_sum; -//CHECK-NEXT: int _r0 = 0; -//CHECK-NEXT: addArr_pullback(arr, n, _r_d1, _d_arr, &_r0); -//CHECK-NEXT: _d_n += _r0; +//CHECK-NEXT: addArr_pullback(arr, n, _r_d1, _d_arr); //CHECK-NEXT: } //CHECK-NEXT: } //CHECK-NEXT: for (; _t0; _t0--) { @@ -261,7 +248,6 @@ double func5(int k) { //CHECK-NEXT: *_d_k += _r_d0; //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: *_d_k += _d_n; //CHECK-NEXT: } double func6(double seed) { @@ -276,7 +262,6 @@ double func6(double seed) { //CHECK: void func6_grad(double seed, double *_d_seed) { //CHECK-NEXT: double _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape > _t1 = {}; //CHECK-NEXT: double _d_arr[3] = {0}; @@ -298,15 +283,12 @@ double func6(double seed) { //CHECK-NEXT: { //CHECK-NEXT: sum = clad::pop(_t2); //CHECK-NEXT: double _r_d0 = _d_sum; -//CHECK-NEXT: int _r0 = 0; -//CHECK-NEXT: addArr_pullback(arr, 3, _r_d0, _d_arr, &_r0); +//CHECK-NEXT: addArr_pullback(arr, 3, _r_d0, _d_arr); //CHECK-NEXT: } //CHECK-NEXT: { //CHECK-NEXT: *_d_seed += _d_arr[0]; //CHECK-NEXT: *_d_seed += _d_arr[1] * i; -//CHECK-NEXT: _d_i += seed * _d_arr[1]; //CHECK-NEXT: *_d_seed += _d_arr[2]; -//CHECK-NEXT: _d_i += _d_arr[2]; //CHECK-NEXT: clad::zero_init(_d_arr); //CHECK-NEXT: arr = clad::pop(_t1); //CHECK-NEXT: } @@ -331,7 +313,6 @@ double func7(double *params) { //CHECK: void func7_grad(double *params, double *_d_params) { //CHECK-NEXT: double _d_out = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: std::size_t _d_i = 0; //CHECK-NEXT: std::size_t i = 0; //CHECK-NEXT: clad::tape > _t1 = {}; //CHECK-NEXT: double _d_paramsPrime[1] = {0}; @@ -369,7 +350,7 @@ double helper2(double i, double *arr, int n) { return arr[0]*i; } -//CHECK: void helper2_pullback(double i, double *arr, int n, double _d_y, double *_d_i, double *_d_arr, int *_d_n); +//CHECK: void helper2_pullback(double i, double *arr, int n, double _d_y, double *_d_i, double *_d_arr); double func8(double i, double *arr, int n) { double res = 0; @@ -379,7 +360,7 @@ double func8(double i, double *arr, int n) { return res; } -//CHECK: void func8_grad(double i, double *arr, int n, double *_d_i, double *_d_arr, int *_d_n) { +//CHECK: void func8_grad_0_1(double i, double *arr, int n, double *_d_i, double *_d_arr) { //CHECK-NEXT: double _d_res = 0; //CHECK-NEXT: double _t0; //CHECK-NEXT: double _t1; @@ -404,10 +385,8 @@ double func8(double i, double *arr, int n) { //CHECK-NEXT: double _r_d1 = _d_res; //CHECK-NEXT: _d_res -= _r_d1; //CHECK-NEXT: double _r0 = 0; -//CHECK-NEXT: int _r1 = 0; -//CHECK-NEXT: helper2_pullback(i, arr, n, _r_d1, &_r0, _d_arr, &_r1); +//CHECK-NEXT: helper2_pullback(i, arr, n, _r_d1, &_r0, _d_arr); //CHECK-NEXT: *_d_i += _r0; -//CHECK-NEXT: *_d_n += _r1; //CHECK-NEXT: } //CHECK-NEXT: { //CHECK-NEXT: arr[0] = _t0; @@ -434,7 +413,6 @@ double func9(double i, double j) { //CHECK: void func9_grad(double i, double j, double *_d_i, double *_d_j) { //CHECK-NEXT: double _d_arr[5] = {0}; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_idx = 0; //CHECK-NEXT: int idx = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double arr[5] = {}; @@ -481,10 +459,8 @@ double func10(double *arr, int n) { } //CHECK: void func10_grad_0(double *arr, int n, double *_d_arr) { -//CHECK-NEXT: int _d_n = 0; //CHECK-NEXT: double _d_res = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _t2 = {}; @@ -541,10 +517,10 @@ int main() { printf("Result = {%.2f}\n", _dx); // CHECK-EXEC: Result = {15.00} auto df = clad::gradient(func5); - int dk = 0; + float dk = 0; // Should evaluate to k*3 df.execute(10, &dk); - printf("Result = {%.2d}\n", dk); // CHECK-EXEC: Result = {30} + printf("Result = {%.2f}\n", dk); // CHECK-EXEC: Result = {30.00} auto localArray = clad::gradient(func6); double dseed = 0; @@ -560,8 +536,8 @@ int main() { auto func8grad = clad::gradient(func8); double arr2[5] = {1, 2, 3, 4, 5}; double _d_arr2[5] = {}; - double d_i = 0, d_n = 0; - func8grad.execute(3, arr, 5, &d_i, _d_arr2, &d_n); + double d_i = 0; + func8grad.execute(3, arr, 5, &d_i, _d_arr2); printf("Result = {%.2f}\n", d_i); // CHECK-EXEC: Result = {1.00} auto func9grad = clad::gradient(func9); @@ -570,17 +546,16 @@ int main() { func9grad.execute(3, 5, &d_i, &d_j); printf("Result = {%.2f}\n", d_i); // CHECK-EXEC: Result = {5.00} - auto func10grad = clad::gradient(func10, "arr"); + auto func10grad = clad::gradient(func10); double arr3[5] = {1, 2, 3, 4, 5}; double _d_arr3[5] = {}; func10grad.execute(arr3, 5, _d_arr3); printf("Result (arr) = {%.2f, %.2f, %.2f, %.2f, %.2f}\n", _d_arr3[0], _d_arr3[1], _d_arr3[2], _d_arr3[3], _d_arr3[4]); // CHECK-EXEC: Result (arr) = {2.00, 4.00, 6.00, 8.00, 10.00} } -//CHECK: void addArr_pullback(const double *arr, int n, double _d_y, double *_d_arr, int *_d_n) { +//CHECK: void addArr_pullback(const double *arr, int n, double _d_y, double *_d_arr) { //CHECK-NEXT: double _d_ret = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double ret = 0; @@ -621,7 +596,7 @@ int main() { //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK: void helper2_pullback(double i, double *arr, int n, double _d_y, double *_d_i, double *_d_arr, int *_d_n) { +//CHECK: void helper2_pullback(double i, double *arr, int n, double _d_y, double *_d_i, double *_d_arr) { //CHECK-NEXT: goto _label0; //CHECK-NEXT: _label0: //CHECK-NEXT: { 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/CUDA/ForwardMode.cu b/test/CUDA/ForwardMode.cu index aeaeac3a6..f9407ec5c 100644 --- a/test/CUDA/ForwardMode.cu +++ b/test/CUDA/ForwardMode.cu @@ -17,8 +17,7 @@ __global__ void add(double *a, double *b, double *c, int n) { c[idx] = a[idx] + b[idx]; } -// CHECK: void add_pushforward(double *a, double *b, double *c, int n, double *_d_a, double *_d_b, double *_d_c, int _d_n) __attribute__((global)) { -// CHECK-NEXT: int _d_idx = 0; +// CHECK: void add_pushforward(double *a, double *b, double *c, int n, double *_d_a, double *_d_b, double *_d_c) __attribute__((global)) { // CHECK-NEXT: int idx = threadIdx.x; // CHECK-NEXT: if (idx < n) { // CHECK-NEXT: _d_c[idx] = _d_a[idx] + _d_b[idx]; @@ -71,16 +70,12 @@ double fn1(double i, double j) { // CHECK-NEXT: double b[500] = {}; // CHECK-NEXT: double _d_c[500] = {}; // CHECK-NEXT: double c[500] = {}; -// CHECK-NEXT: int _d_n = 0; // CHECK-NEXT: int n = 500; -// CHECK-NEXT: { -// CHECK-NEXT: int _d_idx = 0; -// CHECK-NEXT: for (int idx = 0; idx < 500; ++idx) { -// CHECK-NEXT: _d_a[idx] = 0; -// CHECK-NEXT: a[idx] = 7; -// CHECK-NEXT: _d_b[idx] = 0; -// CHECK-NEXT: b[idx] = 9; -// CHECK-NEXT: } +// CHECK-NEXT: for (int idx = 0; idx < 500; ++idx) { +// CHECK-NEXT: _d_a[idx] = 0; +// CHECK-NEXT: a[idx] = 7; +// CHECK-NEXT: _d_b[idx] = 0; +// CHECK-NEXT: b[idx] = 9; // CHECK-NEXT: } // CHECK-NEXT: double *_d_device_a = nullptr; // CHECK-NEXT: double *device_a = nullptr; @@ -89,29 +84,26 @@ double fn1(double i, double j) { // CHECK-NEXT: double *_d_device_c = nullptr; // CHECK-NEXT: double *device_c = nullptr; // CHECK-NEXT: unsigned long _t0 = sizeof(double); -// CHECK-NEXT: ValueAndPushforward _t1 = clad::custom_derivatives::cudaMalloc_pushforward(&device_a, n * _t0, &_d_device_a, _d_n * _t0 + n * sizeof(double)); +// CHECK-NEXT: ValueAndPushforward _t1 = clad::custom_derivatives::cudaMalloc_pushforward(&device_a, n * _t0, &_d_device_a); // CHECK-NEXT: unsigned long _t2 = sizeof(double); -// CHECK-NEXT: ValueAndPushforward _t3 = clad::custom_derivatives::cudaMalloc_pushforward(&device_b, n * _t2, &_d_device_b, _d_n * _t2 + n * sizeof(double)); +// CHECK-NEXT: ValueAndPushforward _t3 = clad::custom_derivatives::cudaMalloc_pushforward(&device_b, n * _t2, &_d_device_b); // CHECK-NEXT: unsigned long _t4 = sizeof(double); -// CHECK-NEXT: ValueAndPushforward _t5 = clad::custom_derivatives::cudaMalloc_pushforward(&device_c, n * _t4, &_d_device_c, _d_n * _t4 + n * sizeof(double)); +// CHECK-NEXT: ValueAndPushforward _t5 = clad::custom_derivatives::cudaMalloc_pushforward(&device_c, n * _t4, &_d_device_c); // CHECK-NEXT: unsigned long _t6 = sizeof(double); -// CHECK-NEXT: ValueAndPushforward _t7 = clad::custom_derivatives::cudaMemcpy_pushforward(device_a, a, n * _t6, cudaMemcpyHostToDevice, _d_device_a, _d_a, _d_n * _t6 + n * sizeof(double)); +// CHECK-NEXT: ValueAndPushforward _t7 = clad::custom_derivatives::cudaMemcpy_pushforward(device_a, a, n * _t6, cudaMemcpyHostToDevice, _d_device_a, _d_a); // CHECK-NEXT: unsigned long _t8 = sizeof(double); -// CHECK-NEXT: ValueAndPushforward _t9 = clad::custom_derivatives::cudaMemcpy_pushforward(device_b, b, n * _t8, cudaMemcpyHostToDevice, _d_device_b, _d_b, _d_n * _t8 + n * sizeof(double)); +// CHECK-NEXT: ValueAndPushforward _t9 = clad::custom_derivatives::cudaMemcpy_pushforward(device_b, b, n * _t8, cudaMemcpyHostToDevice, _d_device_b, _d_b); // CHECK-NEXT: unsigned long _t10 = sizeof(double); -// CHECK-NEXT: ValueAndPushforward _t11 = clad::custom_derivatives::cudaMemcpy_pushforward(device_c, c, n * _t10, cudaMemcpyHostToDevice, _d_device_c, _d_c, _d_n * _t10 + n * sizeof(double)); -// CHECK-NEXT: add_pushforward<<<1, 700>>>(device_a, device_b, device_c, n, _d_device_a, _d_device_b, _d_device_c, _d_n); +// CHECK-NEXT: ValueAndPushforward _t11 = clad::custom_derivatives::cudaMemcpy_pushforward(device_c, c, n * _t10, cudaMemcpyHostToDevice, _d_device_c, _d_c); +// CHECK-NEXT: add_pushforward<<<1, 700>>>(device_a, device_b, device_c, n, _d_device_a, _d_device_b, _d_device_c); // CHECK-NEXT: ValueAndPushforward _t12 = clad::custom_derivatives::cudaDeviceSynchronize_pushforward(); // CHECK-NEXT: unsigned long _t13 = sizeof(double); -// CHECK-NEXT: ValueAndPushforward _t14 = clad::custom_derivatives::cudaMemcpy_pushforward(c, device_c, n * _t13, cudaMemcpyDeviceToHost, _d_c, _d_device_c, _d_n * _t13 + n * sizeof(double)); +// CHECK-NEXT: ValueAndPushforward _t14 = clad::custom_derivatives::cudaMemcpy_pushforward(c, device_c, n * _t13, cudaMemcpyDeviceToHost, _d_c, _d_device_c); // CHECK-NEXT: double _d_sum = 0; // CHECK-NEXT: double sum = 0; -// CHECK-NEXT: { -// CHECK-NEXT: int _d_idx = 0; -// CHECK-NEXT: for (int idx = 0; idx < n; ++idx) { -// CHECK-NEXT: _d_sum += _d_c[idx]; -// CHECK-NEXT: sum += c[idx]; -// CHECK-NEXT: } +// CHECK-NEXT: for (int idx = 0; idx < n; ++idx) { +// CHECK-NEXT: _d_sum += _d_c[idx]; +// CHECK-NEXT: sum += c[idx]; // CHECK-NEXT: } // CHECK-NEXT: double _t15 = 2 * sum; // CHECK-NEXT: return _d_sum * i + sum * _d_i + (0 * sum + 2 * _d_sum) * j + _t15 * _d_j; diff --git a/test/CUDA/GradientCuda.cu b/test/CUDA/GradientCuda.cu index 404bfe9c7..7c8d6011b 100644 --- a/test/CUDA/GradientCuda.cu +++ b/test/CUDA/GradientCuda.cu @@ -30,10 +30,8 @@ __device__ __host__ double gauss(double* x, double* p, double sigma, int dim) { // CHECK: void gauss_grad_1(double *x, double *p, double sigma, int dim, double *_d_p) __attribute__((device)) __attribute__((host)) { //CHECK-NEXT: double _d_sigma = 0; -//CHECK-NEXT: int _d_dim = 0; //CHECK-NEXT: double _d_t = 0; //CHECK-NEXT: unsigned long _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double _t2; @@ -60,7 +58,6 @@ __device__ __host__ double gauss(double* x, double* p, double sigma, int dim) { //CHECK-NEXT: double _r1 = 0; //CHECK-NEXT: double _r2 = 0; //CHECK-NEXT: clad::custom_derivatives{{(::std)?}}::pow_pullback(2 * 3.1415926535897931, -dim / 2., 1 * _t4 * _t5, &_r1, &_r2); -//CHECK-NEXT: _d_dim += -_r2 / 2.; //CHECK-NEXT: double _r3 = 0; //CHECK-NEXT: double _r4 = 0; //CHECK-NEXT: clad::custom_derivatives{{(::std)?}}::pow_pullback(sigma, -0.5, _t6 * 1 * _t4, &_r3, &_r4); diff --git a/test/Enzyme/FunctionPrototypesReverseMode.C b/test/Enzyme/FunctionPrototypesReverseMode.C index 0407b9fd5..7bc9d684b 100644 --- a/test/Enzyme/FunctionPrototypesReverseMode.C +++ b/test/Enzyme/FunctionPrototypesReverseMode.C @@ -30,7 +30,7 @@ double f3(double* arr, int n){ return sum; } -// CHECK: void f3_grad_enzyme(double *arr, int n, double *_d_arr, int *_d_n) { +// CHECK: void f3_grad_enzyme_0(double *arr, int n, double *_d_arr) { // CHECK-NEXT: __enzyme_autodiff_f3(f3, arr, _d_arr, n); // CHECK-NEXT: } @@ -45,7 +45,7 @@ double f4(double* arr1, int n, double* arr2, int m){ return sum; } -// CHECK: void f4_grad_enzyme(double *arr1, int n, double *arr2, int m, double *_d_arr1, int *_d_n, double *_d_arr2, int *_d_m) { +// CHECK: void f4_grad_enzyme_0_2(double *arr1, int n, double *arr2, int m, double *_d_arr1, double *_d_arr2) { // CHECK-NEXT: __enzyme_autodiff_f4(f4, arr1, _d_arr1, n, arr2, _d_arr2, m); // CHECK-NEXT: } @@ -57,7 +57,7 @@ double f5(double arr[], double x,int n,double y){ return res; } -// CHECK: void f5_grad_enzyme(double arr[], double x, int n, double y, double *_d_arr, double *_d_x, int *_d_n, double *_d_y) { +// CHECK: void f5_grad_enzyme_0_1_3(double arr[], double x, int n, double y, double *_d_arr, double *_d_x, double *_d_y) { // CHECK-NEXT: clad::EnzymeGradient<2> grad = __enzyme_autodiff_f5(f5, arr, _d_arr, x, n, y); // CHECK-NEXT: *_d_x = grad.d_arr[0U]; // CHECK-NEXT: *_d_y = grad.d_arr[1U]; @@ -82,30 +82,27 @@ int main() { auto f3_grad=clad::gradient(f3); double f3_list[3]={3,4,5}; double f3_res[3]={0}; - int f3_dn=0; - f3_grad.execute(f3_list,3,f3_res,&f3_dn); - printf("d_x1 = %.2f, d_x2 = %.2f, d_x3 = %.2f, d_n = %d\n",f3_res[0],f3_res[1],f3_res[2],f3_dn); - //CHECK-EXEC: d_x1 = 6.00, d_x2 = 8.00, d_x3 = 10.00, d_n = 0 + f3_grad.execute(f3_list,3,f3_res); + printf("d_x1 = %.2f, d_x2 = %.2f, d_x3 = %.2f\n",f3_res[0],f3_res[1],f3_res[2]); + //CHECK-EXEC: d_x1 = 6.00, d_x2 = 8.00, d_x3 = 10.00 auto f4_grad=clad::gradient(f4); double f4_list1[3]={3,4,5}; double f4_list2[2]={1,2}; double f4_res1[3]={0}; double f4_res2[2]={0}; - int f4_dn1=0,f4_dn2=0; - f4_grad.execute(f4_list1,3,f4_list2,2,f4_res1,&f4_dn1,f4_res2,&f4_dn2); - printf("d_x1 = %.2f, d_x2 = %.2f, d_x3 = %.2f, d_n1 = %d\n",f4_res1[0],f4_res1[1],f4_res1[2],f4_dn1); - //CHECK-EXEC: d_x1 = 6.00, d_x2 = 8.00, d_x3 = 10.00, d_n1 = 0 - printf("d_y1 = %.2f, d_y2 = %.2f, d_n2 = %d\n",f4_res2[0],f4_res2[1],f4_dn2); - //CHECK-EXEC: d_y1 = 2.00, d_y2 = 4.00, d_n2 = 0 + f4_grad.execute(f4_list1,3,f4_list2,2,f4_res1,f4_res2); + printf("d_x1 = %.2f, d_x2 = %.2f, d_x3 = %.2f\n",f4_res1[0],f4_res1[1],f4_res1[2]); + //CHECK-EXEC: d_x1 = 6.00, d_x2 = 8.00, d_x3 = 10.00 + printf("d_y1 = %.2f, d_y2 = %.2f\n",f4_res2[0],f4_res2[1]); + //CHECK-EXEC: d_y1 = 2.00, d_y2 = 4.00 auto f5_grad=clad::gradient(f5); double f5_list[3]={3,4,5}; double f5_res[3]={0}; double f5_x=10.0,f5_dx=0,f5_y=5,f5_dy; - int f5_dn=0; - f5_grad.execute(f5_list,f5_x,3,f5_y,f5_res,&f5_dx,&f5_dn,&f5_dy); - printf("d_x1 = %.2f, d_x2 = %.2f, d_x3 = %.2f, d_n1 = %d, d_x = %.2f, d_y = %.2f\n",f5_res[0],f5_res[1],f5_res[2],f5_dn, f5_dx, f5_dy); - //CHECK-EXEC: d_x1 = 50.00, d_x2 = 50.00, d_x3 = 50.00, d_n1 = 0, d_x = 60.00, d_y = 120.00 + f5_grad.execute(f5_list,f5_x,3,f5_y,f5_res,&f5_dx,&f5_dy); + printf("d_x1 = %.2f, d_x2 = %.2f, d_x3 = %.2f, d_x = %.2f, d_y = %.2f\n",f5_res[0],f5_res[1],f5_res[2],f5_dx, f5_dy); + //CHECK-EXEC: d_x1 = 50.00, d_x2 = 50.00, d_x3 = 50.00, d_x = 60.00, d_y = 120.00 } diff --git a/test/ErrorEstimation/Assignments.C b/test/ErrorEstimation/Assignments.C index 7c758ef53..4f003d364 100644 --- a/test/ErrorEstimation/Assignments.C +++ b/test/ErrorEstimation/Assignments.C @@ -12,7 +12,7 @@ float func(float x, float y) { return y; } -//CHECK: void func_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: float _t1; //CHECK-NEXT: _t0 = x; @@ -29,15 +29,15 @@ float func(float x, float y) { //CHECK-NEXT: *_d_x += _r_d1; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; //CHECK-NEXT: *_d_x += _r_d0; //CHECK-NEXT: *_d_y += _r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } float func2(float x, int y) { @@ -45,7 +45,7 @@ float func2(float x, int y) { return x; } -//CHECK: void func2_grad(float x, int y, float *_d_x, int *_d_y, double &_final_error) { +//CHECK: void func2_grad_0(float x, int y, float *_d_x, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: _t0 = x; //CHECK-NEXT: x = y * x + x * x; @@ -53,16 +53,15 @@ float func2(float x, int y) { //CHECK-NEXT: _label0: //CHECK-NEXT: *_d_x += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; -//CHECK-NEXT: *_d_y += _r_d0 * x; //CHECK-NEXT: *_d_x += y * _r_d0; //CHECK-NEXT: *_d_x += _r_d0 * x; //CHECK-NEXT: *_d_x += x * _r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: } float func3(int x, int y) { @@ -70,19 +69,14 @@ float func3(int x, int y) { return y; } -//CHECK: void func3_grad(int x, int y, int *_d_x, int *_d_y, double &_final_error) { +//CHECK: void func3_grad(int x, int y, double *_final_error) { //CHECK-NEXT: int _t0; //CHECK-NEXT: _t0 = x; //CHECK-NEXT: x = y; //CHECK-NEXT: goto _label0; //CHECK-NEXT: _label0: -//CHECK-NEXT: *_d_y += 1; -//CHECK-NEXT: { -//CHECK-NEXT: x = _t0; -//CHECK-NEXT: int _r_d0 = *_d_x; -//CHECK-NEXT: *_d_x -= _r_d0; -//CHECK-NEXT: *_d_y += _r_d0; -//CHECK-NEXT: } +//CHECK-NEXT: ; +//CHECK-NEXT: x = _t0; //CHECK-NEXT: } float func4(float x, float y) { @@ -91,7 +85,7 @@ float func4(float x, float y) { return x; } -//CHECK: void func4_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func4_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: double _d_z = 0; //CHECK-NEXT: float _t0; //CHECK-NEXT: double z = y; @@ -101,7 +95,7 @@ float func4(float x, float y) { //CHECK-NEXT: _label0: //CHECK-NEXT: *_d_x += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; @@ -109,8 +103,8 @@ float func4(float x, float y) { //CHECK-NEXT: *_d_y += _r_d0; //CHECK-NEXT: } //CHECK-NEXT: *_d_y += _d_z; -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } float func5(float x, float y) { @@ -119,8 +113,7 @@ float func5(float x, float y) { return x; } -//CHECK: void func5_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { -//CHECK-NEXT: int _d_z = 0; +//CHECK: void func5_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: int z = 56; //CHECK-NEXT: _t0 = x; @@ -129,29 +122,28 @@ float func5(float x, float y) { //CHECK-NEXT: _label0: //CHECK-NEXT: *_d_x += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; -//CHECK-NEXT: _d_z += _r_d0; //CHECK-NEXT: *_d_y += _r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } float func6(float x) { return x; } -//CHECK: void func6_grad(float x, float *_d_x, double &_final_error) { +//CHECK: void func6_grad(float x, float *_d_x, double *_final_error) { //CHECK-NEXT: goto _label0; //CHECK-NEXT: _label0: //CHECK-NEXT: *_d_x += 1; -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: } float func7(float x, float y) { return (x * y); } -//CHECK: void func7_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func7_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: _ret_value0 = (x * y); //CHECK-NEXT: goto _label0; @@ -160,9 +152,9 @@ float func7(float x, float y) { return (x * y); } //CHECK-NEXT: *_d_x += 1 * y; //CHECK-NEXT: *_d_y += x * 1; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } float func8(int x, int y) { @@ -170,20 +162,14 @@ float func8(int x, int y) { return x; } -//CHECK: void func8_grad(int x, int y, int *_d_x, int *_d_y, double &_final_error) { +//CHECK: void func8_grad(int x, int y, double *_final_error) { //CHECK-NEXT: int _t0; //CHECK-NEXT: _t0 = x; //CHECK-NEXT: x = y * y; //CHECK-NEXT: goto _label0; //CHECK-NEXT: _label0: -//CHECK-NEXT: *_d_x += 1; -//CHECK-NEXT: { -//CHECK-NEXT: x = _t0; -//CHECK-NEXT: int _r_d0 = *_d_x; -//CHECK-NEXT: *_d_x -= _r_d0; -//CHECK-NEXT: *_d_y += _r_d0 * y; -//CHECK-NEXT: *_d_y += y * _r_d0; -//CHECK-NEXT: } +//CHECK-NEXT: ; +//CHECK-NEXT: x = _t0; //CHECK-NEXT: } int main() { diff --git a/test/ErrorEstimation/BasicOps.C b/test/ErrorEstimation/BasicOps.C index 3048bab3d..91252283a 100644 --- a/test/ErrorEstimation/BasicOps.C +++ b/test/ErrorEstimation/BasicOps.C @@ -13,7 +13,7 @@ float func(float x, float y) { return z; } -//CHECK: void func_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: float _t1; //CHECK-NEXT: float _d_z = 0; @@ -26,13 +26,13 @@ float func(float x, float y) { //CHECK-NEXT: _label0: //CHECK-NEXT: _d_z += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_z * z * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_z * z * {{.+}}); //CHECK-NEXT: *_d_y += _d_z * x; //CHECK-NEXT: *_d_x += y * _d_z; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: y = _t1; //CHECK-NEXT: float _r_d1 = *_d_y; //CHECK-NEXT: *_d_y -= _r_d1; @@ -42,15 +42,15 @@ float func(float x, float y) { //CHECK-NEXT: *_d_y += _r_d1; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; //CHECK-NEXT: *_d_x += _r_d0; //CHECK-NEXT: *_d_y += _r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } // This function may evaluate incorrectly due to absence of usage of @@ -61,7 +61,7 @@ float func2(float x, float y) { return z; } -//CHECK: void func2_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func2_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: _t0 = x; @@ -71,13 +71,13 @@ float func2(float x, float y) { //CHECK-NEXT: _label0: //CHECK-NEXT: _d_z += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_z * z * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_z * z * {{.+}}); //CHECK-NEXT: *_d_y += _d_z / x; //CHECK-NEXT: float _r0 = _d_z * -(y / (x * x)); //CHECK-NEXT: *_d_x += _r0; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; @@ -86,8 +86,8 @@ float func2(float x, float y) { //CHECK-NEXT: *_d_y += -_r_d0 * y; //CHECK-NEXT: *_d_y += y * -_r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } @@ -99,7 +99,7 @@ float func3(float x, float y) { return t; } -//CHECK: void func3_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func3_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: float _t1; @@ -115,8 +115,8 @@ float func3(float x, float y) { //CHECK-NEXT: _label0: //CHECK-NEXT: _d_t += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_t * t * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_t * t * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: *_d_x += _d_t * _t1 * z; //CHECK-NEXT: _d_z += x * _d_t * _t1; //CHECK-NEXT: *_d_y += x * z * _d_t; @@ -128,7 +128,7 @@ float func3(float x, float y) { //CHECK-NEXT: } //CHECK-NEXT: *_d_y += _d_z; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d0; @@ -137,14 +137,14 @@ float func3(float x, float y) { //CHECK-NEXT: *_d_y += -_r_d0 * y; //CHECK-NEXT: *_d_y += y * -_r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } // Function call custom derivative exists but no assign expr float func4(float x, float y) { return std::pow(x, y); } -//CHECK: void func4_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func4_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: _ret_value0 = std::pow(x, y); //CHECK-NEXT: goto _label0; @@ -156,9 +156,9 @@ float func4(float x, float y) { return std::pow(x, y); } //CHECK-NEXT: *_d_x += _r0; //CHECK-NEXT: *_d_y += _r1; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } // Function call custom derivative exists and is assigned @@ -167,7 +167,7 @@ float func5(float x, float y) { return y * y; } -//CHECK: void func5_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func5_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t0; //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: _t0 = y; @@ -180,7 +180,7 @@ float func5(float x, float y) { //CHECK-NEXT: *_d_y += y * 1; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: y = _t0; //CHECK-NEXT: float _r_d0 = *_d_y; //CHECK-NEXT: *_d_y -= _r_d0; @@ -188,15 +188,15 @@ float func5(float x, float y) { //CHECK-NEXT: _r0 += _r_d0 * clad::custom_derivatives{{(::std)?}}::sin_pushforward(x, 1.F).pushforward; //CHECK-NEXT: *_d_x += _r0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } // Function call non custom derivative double helper(double x, double y) { return x * y; } -//CHECK: void helper_pullback(double x, double y, double _d_y0, double *_d_x, double *_d_y, double &_final_error) { +//CHECK: void helper_pullback(double x, double y, double _d_y0, double *_d_x, double *_d_y, double *_final_error) { //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: _ret_value0 = x * y; //CHECK-NEXT: goto _label0; @@ -205,9 +205,9 @@ double helper(double x, double y) { return x * y; } //CHECK-NEXT: *_d_x += _d_y0 * y; //CHECK-NEXT: *_d_y += x * _d_y0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } float func6(float x, float y) { @@ -215,7 +215,7 @@ float func6(float x, float y) { return z * z; } -//CHECK: void func6_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func6_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: float z = helper(x, y); @@ -230,38 +230,33 @@ float func6(float x, float y) { //CHECK-NEXT: double _r0 = 0; //CHECK-NEXT: double _r1 = 0; //CHECK-NEXT: double _t0 = 0; -//CHECK-NEXT: helper_pullback(x, y, _d_z, &_r0, &_r1, _t0); +//CHECK-NEXT: helper_pullback(x, y, _d_z, &_r0, &_r1, &_t0); //CHECK-NEXT: *_d_x += _r0; //CHECK-NEXT: *_d_y += _r1; -//CHECK-NEXT: _final_error += _t0; +//CHECK-NEXT: *_final_error += _t0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } float func7(float x) { - int z = x; // expected-warning {{Lossy assignment from 'float' to 'int'}} + int z = x; return z + z; } -//CHECK: void func7_grad(float x, float *_d_x, double &_final_error) { -//CHECK-NEXT: int _d_z = 0; +//CHECK: void func7_grad(float x, float *_d_x, double *_final_error) { //CHECK-NEXT: int z = x; //CHECK-NEXT: goto _label0; //CHECK-NEXT: _label0: -//CHECK-NEXT: { -//CHECK-NEXT: _d_z += 1; -//CHECK-NEXT: _d_z += 1; -//CHECK-NEXT: } -//CHECK-NEXT: *_d_x += _d_z; -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: ; +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: } double helper2(float& x) { return x * x; } -//CHECK: void helper2_pullback(float &x, double _d_y, float *_d_x, double &_final_error) { +//CHECK: void helper2_pullback(float &x, double _d_y, float *_d_x, double *_final_error) { //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: _ret_value0 = x * x; //CHECK-NEXT: goto _label0; @@ -270,7 +265,7 @@ double helper2(float& x) { return x * x; } //CHECK-NEXT: *_d_x += _d_y * x; //CHECK-NEXT: *_d_x += x * _d_y; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } float func8(float x, float y) { @@ -279,7 +274,7 @@ float func8(float x, float y) { return z; } -//CHECK: void func8_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func8_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: float _t0; //CHECK-NEXT: float _t1; @@ -297,12 +292,12 @@ float func8(float x, float y) { //CHECK-NEXT: *_d_y += _r_d0; //CHECK-NEXT: x = _t1; //CHECK-NEXT: double _t2 = 0; -//CHECK-NEXT: helper2_pullback(_t1, _r_d0, &*_d_x, _t2); -//CHECK-NEXT: _final_error += _t2; -//CHECK-NEXT: _final_error += std::abs(*_d_x * _t1 * {{.+}}); +//CHECK-NEXT: helper2_pullback(_t1, _r_d0, &*_d_x, &_t2); +//CHECK-NEXT: *_final_error += _t2; +//CHECK-NEXT: *_final_error += std::abs(*_d_x * _t1 * {{.+}}); //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } float func9(float x, float y) { @@ -311,7 +306,7 @@ float func9(float x, float y) { return z; } -//CHECK: void func9_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func9_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _t1; //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: float _t3; @@ -335,29 +330,29 @@ float func9(float x, float y) { //CHECK-NEXT: float _r_d0 = _d_z; //CHECK-NEXT: x = _t5; //CHECK-NEXT: double _t6 = 0; -//CHECK-NEXT: helper2_pullback(_t5, _r_d0 * _t4, &*_d_x, _t6); +//CHECK-NEXT: helper2_pullback(_t5, _r_d0 * _t4, &*_d_x, &_t6); //CHECK-NEXT: y = _t8; //CHECK-NEXT: double _t9 = 0; -//CHECK-NEXT: helper2_pullback(_t8, _t7 * _r_d0, &*_d_y, _t9); -//CHECK-NEXT: _final_error += _t6 + _t9; -//CHECK-NEXT: _final_error += std::abs(*_d_y * _t8 * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_x * _t5 * {{.+}}); +//CHECK-NEXT: helper2_pullback(_t8, _t7 * _r_d0, &*_d_y, &_t9); +//CHECK-NEXT: *_final_error += _t6 + _t9; +//CHECK-NEXT: *_final_error += std::abs(*_d_y * _t8 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * _t5 * {{.+}}); //CHECK-NEXT: } //CHECK-NEXT: { //CHECK-NEXT: double _r0 = 0; //CHECK-NEXT: double _r1 = 0; //CHECK-NEXT: double _t0 = 0; -//CHECK-NEXT: helper_pullback(x, y, _d_z, &_r0, &_r1, _t0); +//CHECK-NEXT: helper_pullback(x, y, _d_z, &_r0, &_r1, &_t0); //CHECK-NEXT: *_d_x += _r0; //CHECK-NEXT: *_d_y += _r1; //CHECK-NEXT: x = _t1; //CHECK-NEXT: double _t2 = 0; -//CHECK-NEXT: helper2_pullback(_t1, _d_z, &*_d_x, _t2); -//CHECK-NEXT: _final_error += _t0 + _t2; -//CHECK-NEXT: _final_error += std::abs(*_d_x * _t1 * {{.+}}); +//CHECK-NEXT: helper2_pullback(_t1, _d_z, &*_d_x, &_t2); +//CHECK-NEXT: *_final_error += _t0 + _t2; +//CHECK-NEXT: *_final_error += std::abs(*_d_x * _t1 * {{.+}}); //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } int main() { diff --git a/test/ErrorEstimation/ConditonalStatements.C b/test/ErrorEstimation/ConditonalStatements.C index db91578fd..880fcd128 100644 --- a/test/ErrorEstimation/ConditonalStatements.C +++ b/test/ErrorEstimation/ConditonalStatements.C @@ -17,7 +17,7 @@ float func(float x, float y) { return x + y; } -//CHECK: void func_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: bool _cond0; //CHECK-NEXT: float _t0; //CHECK-NEXT: float _d_temp = 0; @@ -47,7 +47,7 @@ float func(float x, float y) { //CHECK-NEXT: } //CHECK-NEXT: if (_cond0) { //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: y = _t0; //CHECK-NEXT: float _r_d0 = *_d_y; //CHECK-NEXT: *_d_y -= _r_d0; @@ -62,7 +62,7 @@ float func(float x, float y) { //CHECK-NEXT: *_d_y += _r_d2; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_temp * temp * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_temp * temp * {{.+}}); //CHECK-NEXT: temp = _t1; //CHECK-NEXT: float _r_d1 = _d_temp; //CHECK-NEXT: _d_temp -= _r_d1; @@ -70,13 +70,13 @@ float func(float x, float y) { //CHECK-NEXT: *_d_y += y * _r_d1; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_temp * temp * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_temp * temp * {{.+}}); //CHECK-NEXT: *_d_y += _d_temp; //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } // Single return statement if/else @@ -88,7 +88,7 @@ float func2(float x) { return x * x; } -//CHECK: void func2_grad(float x, float *_d_x, double &_final_error) { +//CHECK: void func2_grad(float x, float *_d_x, double *_final_error) { //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: bool _cond0; //CHECK-NEXT: double _ret_value0 = 0; @@ -116,17 +116,17 @@ float func2(float x) { //CHECK-NEXT: *_d_x += x * 1; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_z * z * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_z * z * {{.+}}); //CHECK-NEXT: *_d_x += _d_z * x; //CHECK-NEXT: *_d_x += x * _d_z; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } float func3(float x, float y) { return x > 30 ? x * y : x + y; } -//CHECK: void func3_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func3_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: bool _cond0; //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: _cond0 = x > 30; @@ -140,9 +140,9 @@ float func3(float x, float y) { return x > 30 ? x * y : x + y; } //CHECK-NEXT: *_d_x += 1; //CHECK-NEXT: *_d_y += 1; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } float func4(float x, float y) { @@ -150,7 +150,7 @@ float func4(float x, float y) { return y / x; } -//CHECK: void func4_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func4_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: bool _cond0; //CHECK-NEXT: float _t0; //CHECK-NEXT: float _t1; @@ -170,20 +170,20 @@ float func4(float x, float y) { //CHECK-NEXT: *_d_x += _r0; //CHECK-NEXT: } //CHECK-NEXT: if (_cond0) { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t0; //CHECK-NEXT: float _r_d0 = *_d_x; //CHECK-NEXT: } else { -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: x = _t1; //CHECK-NEXT: float _r_d1 = *_d_x; //CHECK-NEXT: *_d_x -= _r_d1; //CHECK-NEXT: *_d_x += _r_d1 * x; //CHECK-NEXT: *_d_x += x * _r_d1; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } int main() { diff --git a/test/ErrorEstimation/LoopsAndArrays.C b/test/ErrorEstimation/LoopsAndArrays.C index 80c1e38f3..21d169580 100644 --- a/test/ErrorEstimation/LoopsAndArrays.C +++ b/test/ErrorEstimation/LoopsAndArrays.C @@ -14,10 +14,9 @@ float func(float* p, int n) { return sum; } -//CHECK: void func_grad(float *p, int n, float *_d_p, int *_d_n, double &_final_error) { +//CHECK: void func_grad_0(float *p, int n, float *_d_p, double *_final_error) { //CHECK-NEXT: float _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: unsigned {{int|long}} p_size = 0; @@ -34,17 +33,17 @@ float func(float* p, int n) { //CHECK-NEXT: for (; _t0; _t0--) { //CHECK-NEXT: i--; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: sum = clad::pop(_t1); //CHECK-NEXT: float _r_d0 = _d_sum; //CHECK-NEXT: _d_p[i] += _r_d0; //CHECK-NEXT: p_size = std::max(p_size, i); //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: int i0 = 0; //CHECK-NEXT: for (; i0 <= p_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_p[i0] * p[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_p[i0] * p[i0] * {{.+}}); //CHECK-NEXT: } @@ -57,10 +56,9 @@ float func2(float x) { return z; } -//CHECK: void func2_grad(float x, float *_d_x, double &_final_error) { +//CHECK: void func2_grad(float x, float *_d_x, double *_final_error) { //CHECK-NEXT: float _d_z = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: float _d_m = 0; @@ -80,7 +78,7 @@ float func2(float x) { //CHECK-NEXT: for (; _t0; _t0--) { //CHECK-NEXT: i--; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_z * z * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_z * z * {{.+}}); //CHECK-NEXT: z = clad::pop(_t2); //CHECK-NEXT: float _r_d0 = _d_z; //CHECK-NEXT: _d_z -= _r_d0; @@ -88,14 +86,14 @@ float func2(float x) { //CHECK-NEXT: _d_m += _r_d0; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_m * m * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_m * m * {{.+}}); //CHECK-NEXT: *_d_x += _d_m * x; //CHECK-NEXT: *_d_x += x * _d_m; //CHECK-NEXT: _d_m = 0; //CHECK-NEXT: m = clad::pop(_t1); //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); //CHECK-NEXT: } float func3(float x, float y) { @@ -106,7 +104,7 @@ float func3(float x, float y) { return arr[2]; } -//CHECK: void func3_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func3_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: double _d_arr[3] = {0}; //CHECK-NEXT: double _t0; //CHECK-NEXT: double _t1; @@ -122,7 +120,7 @@ float func3(float x, float y) { //CHECK-NEXT: _label0: //CHECK-NEXT: _d_arr[2] += 1; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_arr[2] * arr[2] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_arr[2] * arr[2] * {{.+}}); //CHECK-NEXT: arr[2] = _t2; //CHECK-NEXT: double _r_d2 = _d_arr[2]; //CHECK-NEXT: _d_arr[2] -= _r_d2; @@ -130,7 +128,7 @@ float func3(float x, float y) { //CHECK-NEXT: _d_arr[1] += _r_d2; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_arr[1] * arr[1] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_arr[1] * arr[1] * {{.+}}); //CHECK-NEXT: arr[1] = _t1; //CHECK-NEXT: double _r_d1 = _d_arr[1]; //CHECK-NEXT: _d_arr[1] -= _r_d1; @@ -138,15 +136,15 @@ float func3(float x, float y) { //CHECK-NEXT: *_d_x += x * _r_d1; //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_arr[0] * arr[0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_arr[0] * arr[0] * {{.+}}); //CHECK-NEXT: arr[0] = _t0; //CHECK-NEXT: double _r_d0 = _d_arr[0]; //CHECK-NEXT: _d_arr[0] -= _r_d0; //CHECK-NEXT: *_d_x += _r_d0; //CHECK-NEXT: *_d_y += _r_d0; //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(*_d_x * x * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(*_d_y * y * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_x * x * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(*_d_y * y * {{.+}}); //CHECK-NEXT: } float func4(float x[10], float y[10]) { @@ -158,10 +156,9 @@ float func4(float x[10], float y[10]) { return sum; } -//CHECK: void func4_grad(float x[10], float y[10], float *_d_x, float *_d_y, double &_final_error) { +//CHECK: void func4_grad(float x[10], float y[10], float *_d_x, float *_d_y, double *_final_error) { //CHECK-NEXT: float _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: unsigned {{int|long}} x_size = 0; //CHECK-NEXT: clad::tape _t1 = {}; @@ -182,14 +179,14 @@ float func4(float x[10], float y[10]) { //CHECK-NEXT: for (; _t0; _t0--) { //CHECK-NEXT: i--; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: sum = clad::pop(_t2); //CHECK-NEXT: float _r_d1 = _d_sum; //CHECK-NEXT: _d_x[i] += _r_d1; //CHECK-NEXT: x_size = std::max(x_size, i); //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_x[i] * x[i] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_x[i] * x[i] * {{.+}}); //CHECK-NEXT: x[i] = clad::pop(_t1); //CHECK-NEXT: float _r_d0 = _d_x[i]; //CHECK-NEXT: _d_y[i] += _r_d0; @@ -197,13 +194,13 @@ float func4(float x[10], float y[10]) { //CHECK-NEXT: x_size = std::max(x_size, i); //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: int i0 = 0; //CHECK-NEXT: for (; i0 <= x_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_x[i0] * x[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_x[i0] * x[i0] * {{.+}}); //CHECK-NEXT: i0 = 0; //CHECK-NEXT: for (; i0 <= y_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_y[i0] * y[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_y[i0] * y[i0] * {{.+}}); //CHECK-NEXT: } @@ -214,7 +211,7 @@ double func5(double* x, double* y, double* output) { return output[0] + output[1] + output[2]; } -//CHECK: void func5_grad(double *x, double *y, double *output, double *_d_x, double *_d_y, double *_d_output, double &_final_error) { +//CHECK: void func5_grad(double *x, double *y, double *output, double *_d_x, double *_d_y, double *_d_output, double *_final_error) { //CHECK-NEXT: unsigned {{int|long}} output_size = 0; //CHECK-NEXT: double _t0; //CHECK-NEXT: unsigned {{int|long}} x_size = 0; @@ -240,7 +237,7 @@ double func5(double* x, double* y, double* output) { //CHECK-NEXT: output_size = std::max(output_size, 2); //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_output[2] * output[2] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_output[2] * output[2] * {{.+}}); //CHECK-NEXT: output[2] = _t2; //CHECK-NEXT: double _r_d2 = _d_output[2]; //CHECK-NEXT: _d_output[2] -= _r_d2; @@ -255,7 +252,7 @@ double func5(double* x, double* y, double* output) { //CHECK-NEXT: output_size = std::max(output_size, 2); //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_output[1] * output[1] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_output[1] * output[1] * {{.+}}); //CHECK-NEXT: output[1] = _t1; //CHECK-NEXT: double _r_d1 = _d_output[1]; //CHECK-NEXT: _d_output[1] -= _r_d1; @@ -270,7 +267,7 @@ double func5(double* x, double* y, double* output) { //CHECK-NEXT: output_size = std::max(output_size, 1); //CHECK-NEXT: } //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_output[0] * output[0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_output[0] * output[0] * {{.+}}); //CHECK-NEXT: output[0] = _t0; //CHECK-NEXT: double _r_d0 = _d_output[0]; //CHECK-NEXT: _d_output[0] -= _r_d0; @@ -286,14 +283,14 @@ double func5(double* x, double* y, double* output) { //CHECK-NEXT: } //CHECK-NEXT: int i = 0; //CHECK-NEXT: for (; i <= x_size; i++) -//CHECK-NEXT: _final_error += std::abs(_d_x[i] * x[i] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_x[i] * x[i] * {{.+}}); //CHECK-NEXT: i = 0; //CHECK-NEXT: for (; i <= y_size; i++) -//CHECK-NEXT: _final_error += std::abs(_d_y[i] * y[i] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_y[i] * y[i] * {{.+}}); //CHECK-NEXT: i = 0; //CHECK-NEXT: for (; i <= output_size; i++) -//CHECK-NEXT: _final_error += std::abs(_d_output[i] * output[i] * {{.+}}); -//CHECK-NEXT: _final_error += std::abs(1. * _ret_value0 * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_output[i] * output[i] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(1. * _ret_value0 * {{.+}}); //CHECK-NEXT: } int main() { diff --git a/test/ErrorEstimation/LoopsAndArraysExec.C b/test/ErrorEstimation/LoopsAndArraysExec.C index 6b7ad6f4f..fedb8161b 100644 --- a/test/ErrorEstimation/LoopsAndArraysExec.C +++ b/test/ErrorEstimation/LoopsAndArraysExec.C @@ -15,10 +15,9 @@ double runningSum(float* f, int n) { return sum; } -//CHECK: void runningSum_grad(float *f, int n, float *_d_f, int *_d_n, double &_final_error) { +//CHECK: void runningSum_grad_0(float *f, int n, float *_d_f, double *_final_error) { //CHECK-NEXT: double _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: unsigned {{int|long}} f_size = 0; @@ -35,7 +34,7 @@ double runningSum(float* f, int n) { //CHECK-NEXT: for (; _t0; _t0--) { //CHECK-NEXT: i--; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: sum = clad::pop(_t1); //CHECK-NEXT: double _r_d0 = _d_sum; //CHECK-NEXT: _d_f[i] += _r_d0; @@ -44,10 +43,10 @@ double runningSum(float* f, int n) { //CHECK-NEXT: f_size = std::max(f_size, i - 1); //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: int i0 = 0; //CHECK-NEXT: for (; i0 <= f_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_f[i0] * f[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_f[i0] * f[i0] * {{.+}}); //CHECK-NEXT: } double mulSum(float* a, float* b, int n) { @@ -59,14 +58,12 @@ double mulSum(float* a, float* b, int n) { return sum; } -//CHECK: void mulSum_grad(float *a, float *b, int n, float *_d_a, float *_d_b, int *_d_n, double &_final_error) { +//CHECK: void mulSum_grad_0_1(float *a, float *b, int n, float *_d_a, float *_d_b, double *_final_error) { //CHECK-NEXT: double _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _t2 = {}; -//CHECK-NEXT: int _d_j = 0; //CHECK-NEXT: int j = 0; //CHECK-NEXT: clad::tape _t3 = {}; //CHECK-NEXT: unsigned {{int|long}} a_size = 0; @@ -90,7 +87,7 @@ double mulSum(float* a, float* b, int n) { //CHECK-NEXT: { //CHECK-NEXT: for (; clad::back(_t1); clad::back(_t1)--) { //CHECK-NEXT: j--; -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: sum = clad::pop(_t3); //CHECK-NEXT: double _r_d0 = _d_sum; //CHECK-NEXT: _d_a[i] += _r_d0 * b[j]; @@ -98,20 +95,17 @@ double mulSum(float* a, float* b, int n) { //CHECK-NEXT: _d_b[j] += a[i] * _r_d0; //CHECK-NEXT: b_size = std::max(b_size, j); //CHECK-NEXT: } -//CHECK-NEXT: { -//CHECK-NEXT: _d_j = 0; -//CHECK-NEXT: j = clad::pop(_t2); -//CHECK-NEXT: } +//CHECK-NEXT: j = clad::pop(_t2); //CHECK-NEXT: clad::pop(_t1); //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: int i0 = 0; //CHECK-NEXT: for (; i0 <= a_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_a[i0] * a[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_a[i0] * a[i0] * {{.+}}); //CHECK-NEXT: i0 = 0; //CHECK-NEXT: for (; i0 <= b_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_b[i0] * b[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_b[i0] * b[i0] * {{.+}}); //CHECK-NEXT: } double divSum(float* a, float* b, int n) { @@ -122,10 +116,9 @@ double divSum(float* a, float* b, int n) { return sum; } -//CHECK: void divSum_grad(float *a, float *b, int n, float *_d_a, float *_d_b, int *_d_n, double &_final_error) { +//CHECK: void divSum_grad_0_1(float *a, float *b, int n, float *_d_a, float *_d_b, double *_final_error) { //CHECK-NEXT: double _d_sum = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: unsigned {{int|long}} b_size = 0; @@ -143,7 +136,7 @@ double divSum(float* a, float* b, int n) { //CHECK-NEXT: for (; _t0; _t0--) { //CHECK-NEXT: i--; //CHECK-NEXT: { -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: sum = clad::pop(_t1); //CHECK-NEXT: double _r_d0 = _d_sum; //CHECK-NEXT: b_size = std::max(b_size, i); @@ -154,13 +147,13 @@ double divSum(float* a, float* b, int n) { //CHECK-NEXT: b_size = std::max(b_size, i); //CHECK-NEXT: } //CHECK-NEXT: } -//CHECK-NEXT: _final_error += std::abs(_d_sum * sum * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_sum * sum * {{.+}}); //CHECK-NEXT: int i0 = 0; //CHECK-NEXT: for (; i0 <= a_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_a[i0] * a[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_a[i0] * a[i0] * {{.+}}); //CHECK-NEXT: i0 = 0; //CHECK-NEXT: for (; i0 <= b_size; i0++) -//CHECK-NEXT: _final_error += std::abs(_d_b[i0] * b[i0] * {{.+}}); +//CHECK-NEXT: *_final_error += std::abs(_d_b[i0] * b[i0] * {{.+}}); //CHECK-NEXT: } int main() { @@ -168,17 +161,15 @@ int main() { float arrf[3] = {0.456, 0.77, 0.95}; double finalError = 0; float darr[3] = {0, 0, 0}; - int dn = 0; - df.execute(arrf, 3, darr, &dn, finalError); + df.execute(arrf, 3, darr, &finalError); printf("Result (RS) = {%.2f, %.2f, %.2f} error = %.5f\n", darr[0], darr[1], darr[2], finalError); // CHECK-EXEC: Result (RS) = {1.00, 2.00, 1.00} error = 0.00000 finalError = 0; darr[0] = darr[1] = darr[2] = 0; - dn = 0; float darr2[3] = {0, 0, 0}; auto df2 = clad::estimate_error(mulSum); - df2.execute(arrf, arrf, 3, darr, darr2, &dn, finalError); + df2.execute(arrf, arrf, 3, darr, darr2, &finalError); printf("Result (MS) = {%.2f, %.2f, %.2f}, {%.2f, %.2f, %.2f} error = %.5f\n", darr[0], darr[1], darr[2], darr2[0], darr2[1], darr2[2], finalError); // CHECK-EXEC: Result (MS) = {2.18, 2.18, 2.18}, {2.18, 2.18, 2.18} error = 0.00000 @@ -186,9 +177,8 @@ int main() { finalError = 0; darr[0] = darr[1] = darr[2] = 0; darr2[0] = darr2[1] = darr2[2] = 0; - dn = 0; auto df3 = clad::estimate_error(divSum); - df3.execute(arrf, arrf, 3, darr, darr2, &dn, finalError); + df3.execute(arrf, arrf, 3, darr, darr2, &finalError); printf("Result (DS) = {%.2f, %.2f, %.2f}, {%.2f, %.2f, %.2f} error = %.5f\n", darr[0], darr[1], darr[2], darr2[0], darr2[1], darr2[2], finalError); // CHECK-EXEC: Result (DS) = {2.19, 1.30, 1.05}, {-2.19, -1.30, -1.05} error = 0.00000 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 f291253ce..eb441cc51 100644 --- a/test/FirstDerivative/BuiltinDerivatives.C +++ b/test/FirstDerivative/BuiltinDerivatives.C @@ -166,14 +166,13 @@ 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: } -void f10_grad(float x, int y, float *_d_x, int *_d_y); +void f10_grad_0(float x, int y, float *_d_x); -// CHECK: void f10_grad(float x, int y, float *_d_x, int *_d_y) { +// CHECK: void f10_grad_0(float x, int y, float *_d_x) { // CHECK-NEXT: goto _label0; // CHECK-NEXT: _label0: // CHECK-NEXT: { @@ -181,7 +180,6 @@ void f10_grad(float x, int y, float *_d_x, int *_d_y); // CHECK-NEXT: int _r1 = 0; // CHECK-NEXT: {{(clad::)?}}custom_derivatives{{(::std)?}}::pow_pullback(x, y, 1, &_r0, &_r1); // CHECK-NEXT: *_d_x += _r0; -// CHECK-NEXT: *_d_y += _r1; // CHECK-NEXT: } // CHECK-NEXT: } @@ -222,7 +220,6 @@ double f12(double a, double b) { return std::fma(a, b, b); } int main () { //expected-no-diagnostics float f_result[2]; double d_result[2]; - int i_result[1]; auto f1_darg0 = clad::differentiate(f1, 0); printf("Result is = %f\n", f1_darg0.execute(60)); // CHECK-EXEC: Result is = -0.952413 @@ -276,10 +273,9 @@ int main () { //expected-no-diagnostics printf("Result is = %f\n", f10_darg0.execute(3, 4)); //CHECK-EXEC: Result is = 108.000000 f_result[0] = f_result[1] = 0; - i_result[0] = 0; clad::gradient(f10); - f10_grad(3, 4, &f_result[0], &i_result[0]); - printf("Result is = {%f, %d}\n", f_result[0], i_result[0]); //CHECK-EXEC: Result is = {108.000000, 88} + f10_grad_0(3, 4, &f_result[0]); + printf("Result is = {%f}\n", f_result[0]); //CHECK-EXEC: Result is = {108.000000} INIT_GRADIENT(f11); diff --git a/test/FirstDerivative/ClassMethodCall.C b/test/FirstDerivative/ClassMethodCall.C index 76992bca2..370d9b4e7 100644 --- a/test/FirstDerivative/ClassMethodCall.C +++ b/test/FirstDerivative/ClassMethodCall.C @@ -11,60 +11,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 107b9d688..4ff55837e 100644 --- a/test/FirstDerivative/UnsupportedOpsWarn.C +++ b/test/FirstDerivative/UnsupportedOpsWarn.C @@ -5,37 +5,40 @@ //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){ +float binOpWarn_1(int x, double y){ return x ^ 1; // expected-warning {{attempt to differentiate unsupported operator, ignored.}} } -// CHECK: void binOpWarn_1_grad(int x, int *_d_x) { +// CHECK: void binOpWarn_1_grad_1(int x, double y, double *_d_y) { // CHECK-NEXT: goto _label0; // CHECK-NEXT: _label0: // 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/Gradient/FunctionCalls.C b/test/Gradient/FunctionCalls.C index cffff026d..7adde2c30 100644 --- a/test/Gradient/FunctionCalls.C +++ b/test/Gradient/FunctionCalls.C @@ -142,7 +142,7 @@ float sum(double* arr, int n) { return res; } -// CHECK: void sum_pullback(double *arr, int n, float _d_y, double *_d_arr, int *_d_n); +// CHECK: void sum_pullback(double *arr, int n, float _d_y, double *_d_arr); void twice(double& d) { d = 2*d; @@ -160,11 +160,10 @@ double fn4(double* arr, int n) { return res; } -// CHECK: void fn4_grad(double *arr, int n, double *_d_arr, int *_d_n) { +// CHECK: void fn4_grad_0(double *arr, int n, double *_d_arr) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: double _t0; // CHECK-NEXT: unsigned {{int|long}} _t1; -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: clad::tape _t3 = {}; @@ -190,17 +189,15 @@ double fn4(double* arr, int n) { // CHECK-NEXT: _d_arr[i] += _r_d1; // CHECK-NEXT: } // CHECK-NEXT: { -// CHECK-NEXT: double _r1 = clad::pop(_t2); -// CHECK-NEXT: arr[i] = _r1; -// CHECK-NEXT: twice_pullback(_r1, &_d_arr[i]); +// CHECK-NEXT: double _r0 = clad::pop(_t2); +// CHECK-NEXT: arr[i] = _r0; +// CHECK-NEXT: twice_pullback(_r0, &_d_arr[i]); // CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: { // CHECK-NEXT: res = _t0; // CHECK-NEXT: double _r_d0 = _d_res; -// CHECK-NEXT: int _r0 = 0; -// CHECK-NEXT: sum_pullback(arr, n, _r_d0, _d_arr, &_r0); -// CHECK-NEXT: *_d_n += _r0; +// CHECK-NEXT: sum_pullback(arr, n, _r_d0, _d_arr); // CHECK-NEXT: } // CHECK-NEXT: } @@ -216,7 +213,7 @@ double fn5(double* arr, int n) { return arr[0]; } -// CHECK: void fn5_grad(double *arr, int n, double *_d_arr, int *_d_n) { +// CHECK: void fn5_grad_0(double *arr, int n, double *_d_arr) { // CHECK-NEXT: double _d_temp = 0; // CHECK-NEXT: double temp = modify2(arr); // CHECK-NEXT: goto _label0; @@ -312,7 +309,7 @@ double check_and_return(double x, char c, const char* s) { return 1; } -// CHECK: void check_and_return_pullback(double x, char c, const char *s, double _d_y, double *_d_x, char *_d_c, char *_d_s); +// CHECK: void check_and_return_pullback(double x, char c, const char *s, double _d_y, double *_d_x, char *_d_s); double fn8(double x, double y) { return check_and_return(x, 'a', "aa") * y * std::tanh(1.0) * std::max(1.0, 2.0); // expected-warning {{ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]}} @@ -329,8 +326,7 @@ double fn8(double x, double y) { // CHECK-NEXT: _label0: // CHECK-NEXT: { // CHECK-NEXT: double _r0 = 0; -// CHECK-NEXT: char _r1 = 0; -// CHECK-NEXT: check_and_return_pullback(x, 'a', "aa", 1 * _t0 * _t1 * y, &_r0, &_r1, ""); +// CHECK-NEXT: check_and_return_pullback(x, 'a', "aa", 1 * _t0 * _t1 * y, &_r0, ""); // CHECK-NEXT: *_d_x += _r0; // CHECK-NEXT: *_d_y += _t2 * 1 * _t0 * _t1; // CHECK-NEXT: } @@ -490,7 +486,6 @@ double fn13(double* x, const double* w) { // CHECK: void fn13_grad_0(double *x, const double *w, double *_d_x) { // CHECK-NEXT: double _d_wCopy[2] = {0}; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: std::size_t _d_i = 0; // CHECK-NEXT: std::size_t i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double wCopy[2]; @@ -826,10 +821,9 @@ double sq_defined_later(double x) { // CHECK-NEXT: } // CHECK-NEXT: } -// CHECK: void sum_pullback(double *arr, int n, float _d_y, double *_d_arr, int *_d_n) { +// CHECK: void sum_pullback(double *arr, int n, float _d_y, double *_d_arr) { // CHECK-NEXT: float _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double _t2; @@ -913,7 +907,7 @@ double sq_defined_later(double x) { // CHECK-NEXT: return {i, *_d_i}; // CHECK-NEXT: } -// CHECK: void check_and_return_pullback(double x, char c, const char *s, double _d_y, double *_d_x, char *_d_c, char *_d_s) { +// CHECK: void check_and_return_pullback(double x, char c, const char *s, double _d_y, double *_d_x, char *_d_s) { // CHECK-NEXT: bool _cond0; // CHECK-NEXT: { // CHECK-NEXT: _cond0 = c == 'a' && s[0] == 'a'; diff --git a/test/Gradient/Gradients.C b/test/Gradient/Gradients.C index fc374912b..316d68366 100644 --- a/test/Gradient/Gradients.C +++ b/test/Gradient/Gradients.C @@ -291,7 +291,6 @@ double f_cond4(double x, double y) { } //CHECK: void f_cond4_grad(double x, double y, double *_d_x, double *_d_y) { -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: double _d_arr[2] = {0}; //CHECK-NEXT: bool _cond0; //CHECK-NEXT: double _t0; @@ -492,17 +491,15 @@ unsigned f_types(int x, float y, double z) { return x + y + z; } -void f_types_grad(int x, +void f_types_grad_1_2(int x, float y, double z, - int *_d_x, float *_d_y, double *_d_z); -//CHECK: void f_types_grad(int x, float y, double z, int *_d_x, float *_d_y, double *_d_z) { +//CHECK: void f_types_grad_1_2(int x, float y, double z, float *_d_y, double *_d_z) { //CHECK-NEXT: goto _label0; //CHECK-NEXT: _label0: //CHECK-NEXT: { -//CHECK-NEXT: *_d_x += 1; //CHECK-NEXT: *_d_y += 1; //CHECK-NEXT: *_d_z += 1; //CHECK-NEXT: } @@ -701,9 +698,8 @@ float running_sum(float* p, int n) { return p[n - 1]; } -// CHECK: void running_sum_grad(float *p, int n, float *_d_p, int *_d_n) { +// CHECK: void running_sum_grad_0(float *p, int n, float *_d_p) { // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: _t0 = 0; @@ -772,17 +768,13 @@ double fn_template_non_type(double x) { } // CHECK: void fn_template_non_type_grad(double x, double *_d_x) { -// CHECK-NEXT: size_t _d_maxN = 0; // CHECK-NEXT: bool _cond0; -// CHECK-NEXT: size_t _d_m = 0; // CHECK-NEXT: const size_t maxN = 53; // CHECK-NEXT: _cond0 = maxN < {{15U|15UL}}; // CHECK-NEXT: const size_t m = _cond0 ? maxN : {{15U|15UL}}; // CHECK-NEXT: goto _label0; // CHECK-NEXT: _label0: // CHECK-NEXT: *_d_x += 1 * m; -// CHECK-NEXT: if (_cond0) -// CHECK-NEXT: _d_maxN += _d_m; // CHECK-NEXT: } double fn_div(double x) { diff --git a/test/Gradient/Loops.C b/test/Gradient/Loops.C index 0c3690e64..8803c439b 100644 --- a/test/Gradient/Loops.C +++ b/test/Gradient/Loops.C @@ -19,7 +19,6 @@ double f1(double x) { //CHECK: void f1_grad(double x, double *_d_x) { //CHECK-NEXT: double _d_t = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double t = 1; @@ -53,11 +52,9 @@ double f2(double x) { //CHECK: void f2_grad(double x, double *_d_x) { //CHECK-NEXT: double _d_t = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _t2 = {}; -//CHECK-NEXT: int _d_j = 0; //CHECK-NEXT: int j = 0; //CHECK-NEXT: clad::tape _t3 = {}; //CHECK-NEXT: double t = 1; @@ -84,10 +81,7 @@ double f2(double x) { //CHECK-NEXT: _d_t += _r_d0 * x; //CHECK-NEXT: *_d_x += t * _r_d0; //CHECK-NEXT: } -//CHECK-NEXT: { -//CHECK-NEXT: _d_j = 0; -//CHECK-NEXT: j = clad::pop(_t2); -//CHECK-NEXT: } +//CHECK-NEXT: j = clad::pop(_t2); //CHECK-NEXT: clad::pop(_t1); //CHECK-NEXT: } //CHECK-NEXT: } @@ -105,7 +99,6 @@ double f3(double x) { //CHECK: void f3_grad(double x, double *_d_x) { //CHECK-NEXT: double _d_t = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: clad::tape _t3 = {}; @@ -150,7 +143,6 @@ double f4(double x) { //CHECK: void f4_grad(double x, double *_d_x) { //CHECK-NEXT: double _d_t = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double t = 1; @@ -182,7 +174,6 @@ double f5(double x){ //CHECK: void f5_grad(double x, double *_d_x) { //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: _t0 = 0; //CHECK-NEXT: for (i = 0; i < 10; i++) { @@ -210,7 +201,6 @@ double f_const_local(double x) { //CHECK: void f_const_local_grad(double x, double *_d_x) { //CHECK-NEXT: double _d_res = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double _d_n = 0; @@ -237,7 +227,6 @@ double f_const_local(double x) { //CHECK-NEXT: } //CHECK-NEXT: { //CHECK-NEXT: *_d_x += _d_n; -//CHECK-NEXT: _d_i += _d_n; //CHECK-NEXT: _d_n = 0; //CHECK-NEXT: n = clad::pop(_t1); //CHECK-NEXT: } @@ -252,10 +241,8 @@ double f_sum(double *p, int n) { } //CHECK: void f_sum_grad_0(double *p, int n, double *_d_p) { -//CHECK-NEXT: int _d_n = 0; //CHECK-NEXT: double _d_s = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double s = 0; @@ -287,10 +274,8 @@ double f_sum_squares(double *p, int n) { } //CHECK: void f_sum_squares_grad_0(double *p, int n, double *_d_p) { -//CHECK-NEXT: int _d_n = 0; //CHECK-NEXT: double _d_s = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double s = 0; @@ -327,7 +312,6 @@ double f_log_gaus(double* x, double* p /*means*/, double n, double sigma) { //CHECK-NEXT: double _d_sigma = 0; //CHECK-NEXT: double _d_power = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: clad::tape _t1 = {}; //CHECK-NEXT: double _t2; @@ -393,9 +377,9 @@ double f_log_gaus(double* x, double* p /*means*/, double n, double sigma) { //CHECK-NEXT: } double f_const(const double a, const double b) { - int r = 0; + float r = 0; for (int i = 0; i < a; i++) { - int sq = b * b; + float sq = b * b; r += sq; } return r; @@ -403,15 +387,14 @@ double f_const(const double a, const double b) { void f_const_grad(const double, const double, double*, double*); //CHECK: void f_const_grad(const double a, const double b, double *_d_a, double *_d_b) { -//CHECK-NEXT: int _d_r = 0; +//CHECK-NEXT: float _d_r = 0; //CHECK-NEXT: unsigned {{int|long}} _t0; -//CHECK-NEXT: int _d_i = 0; //CHECK-NEXT: int i = 0; -//CHECK-NEXT: clad::tape _t1 = {}; -//CHECK-NEXT: int _d_sq = 0; -//CHECK-NEXT: int sq0 = 0; -//CHECK-NEXT: clad::tape _t2 = {}; -//CHECK-NEXT: int r = 0; +//CHECK-NEXT: clad::tape _t1 = {}; +//CHECK-NEXT: float _d_sq = 0; +//CHECK-NEXT: float sq0 = 0; +//CHECK-NEXT: clad::tape _t2 = {}; +//CHECK-NEXT: float r = 0; //CHECK-NEXT: _t0 = 0; //CHECK-NEXT: for (i = 0; i < a; i++) { //CHECK-NEXT: _t0++; @@ -426,7 +409,7 @@ void f_const_grad(const double, const double, double*, double*); //CHECK-NEXT: i--; //CHECK-NEXT: { //CHECK-NEXT: r = clad::pop(_t2); -//CHECK-NEXT: int _r_d0 = _d_r; +//CHECK-NEXT: float _r_d0 = _d_r; //CHECK-NEXT: _d_sq += _r_d0; //CHECK-NEXT: } //CHECK-NEXT: { @@ -452,7 +435,6 @@ double f6 (double i, double j) { // CHECK: void f6_grad(double i, double j, double *_d_i, double *_d_j) { // CHECK-NEXT: double _d_a = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: int counter = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double _d_b = 0; @@ -515,7 +497,6 @@ double fn7(double i, double j) { // CHECK: void fn7_grad(double i, double j, double *_d_i, double *_d_j) { // CHECK-NEXT: double _d_a = 0; -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double a = 0; @@ -555,7 +536,6 @@ double fn8(double i, double j) { // CHECK: void fn8_grad(double i, double j, double *_d_i, double *_d_j) { // CHECK-NEXT: double _d_a = 0; -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: clad::tape _t2 = {}; @@ -610,7 +590,6 @@ double fn9(double i, double j) { } // CHECK: void fn9_grad(double i, double j, double *_d_i, double *_d_j) { -// CHECK-NEXT: int _d_counter = 0, _d_counter_again = 0; // CHECK-NEXT: int _t0; // CHECK-NEXT: int _t1; // CHECK-NEXT: double _d_a = 0; @@ -649,39 +628,30 @@ double fn9(double i, double j) { // CHECK-NEXT: { // CHECK-NEXT: { // CHECK-NEXT: a = clad::pop(_t5); -// CHECK-NEXT: double _r_d3 = _d_a; -// CHECK-NEXT: *_d_i += _r_d3 * i; -// CHECK-NEXT: *_d_i += i * _r_d3; -// CHECK-NEXT: *_d_j += _r_d3; +// CHECK-NEXT: double _r_d0 = _d_a; +// CHECK-NEXT: *_d_i += _r_d0 * i; +// CHECK-NEXT: *_d_i += i * _r_d0; +// CHECK-NEXT: *_d_j += _r_d0; // CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: clad::back(_t4)--; // CHECK-NEXT: } // CHECK-NEXT: clad::pop(_t4); // CHECK-NEXT: } -// CHECK-NEXT: { -// CHECK-NEXT: counter_again = clad::pop(_t3); -// CHECK-NEXT: int _r_d2 = _d_counter_again; -// CHECK-NEXT: _d_counter_again -= _r_d2; -// CHECK-NEXT: } +// CHECK-NEXT: counter_again = clad::pop(_t3); // CHECK-NEXT: } // CHECK-NEXT: _t2--; // CHECK-NEXT: } // CHECK-NEXT: { // CHECK-NEXT: counter = _t0; -// CHECK-NEXT: int _r_d0 = _d_counter; -// CHECK-NEXT: _d_counter -= _r_d0; -// CHECK-NEXT: _d_counter_again += _r_d0; // CHECK-NEXT: counter_again = _t1; -// CHECK-NEXT: int _r_d1 = _d_counter_again; -// CHECK-NEXT: _d_counter_again -= _r_d1; // CHECK-NEXT: } // CHECK-NEXT: } double fn10(double i, double j) { double a = 0; int counter = 3; - while (int b = counter) { + while (float b = counter) { b += i*i + j; a += b; counter -= 1; @@ -691,12 +661,11 @@ double fn10(double i, double j) { // CHECK: void fn10_grad(double i, double j, double *_d_i, double *_d_j) { // CHECK-NEXT: double _d_a = 0; -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: clad::tape _t1 = {}; -// CHECK-NEXT: int _d_b = 0; -// CHECK-NEXT: int b = 0; -// CHECK-NEXT: clad::tape _t2 = {}; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: float _d_b = 0; +// CHECK-NEXT: float b = 0; +// CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: clad::tape _t3 = {}; // CHECK-NEXT: clad::tape _t4 = {}; // CHECK-NEXT: double a = 0; @@ -718,10 +687,7 @@ double fn10(double i, double j) { // CHECK-NEXT: while (_t0) // CHECK-NEXT: { // CHECK-NEXT: { -// CHECK-NEXT: { -// CHECK-NEXT: counter = clad::pop(_t4); -// CHECK-NEXT: int _r_d2 = _d_counter; -// CHECK-NEXT: } +// CHECK-NEXT: counter = clad::pop(_t4); // CHECK-NEXT: { // CHECK-NEXT: a = clad::pop(_t3); // CHECK-NEXT: double _r_d1 = _d_a; @@ -729,14 +695,13 @@ double fn10(double i, double j) { // CHECK-NEXT: } // CHECK-NEXT: { // CHECK-NEXT: b = clad::pop(_t2); -// CHECK-NEXT: int _r_d0 = _d_b; +// CHECK-NEXT: float _r_d0 = _d_b; // CHECK-NEXT: *_d_i += _r_d0 * i; // CHECK-NEXT: *_d_i += i * _r_d0; // CHECK-NEXT: *_d_j += _r_d0; // CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: { -// CHECK-NEXT: _d_counter += _d_b; // CHECK-NEXT: _d_b = 0; // CHECK-NEXT: b = clad::pop(_t1); // CHECK-NEXT: } @@ -755,7 +720,6 @@ double fn11(double i, double j) { } // CHECK: void fn11_grad(double i, double j, double *_d_i, double *_d_j) { -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: double _d_a = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; // CHECK-NEXT: clad::tape _t1 = {}; @@ -775,10 +739,7 @@ double fn11(double i, double j) { // CHECK-NEXT: _d_a += 1; // CHECK-NEXT: do { // CHECK-NEXT: { -// CHECK-NEXT: { -// CHECK-NEXT: counter = clad::pop(_t2); -// CHECK-NEXT: int _r_d1 = _d_counter; -// CHECK-NEXT: } +// CHECK-NEXT: counter = clad::pop(_t2); // CHECK-NEXT: { // CHECK-NEXT: a = clad::pop(_t1); // CHECK-NEXT: double _r_d0 = _d_a; @@ -809,11 +770,9 @@ double fn12(double i, double j) { } // CHECK: void fn12_grad(double i, double j, double *_d_i, double *_d_j) { -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: double _d_a = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; // CHECK-NEXT: clad::tape _t1 = {}; -// CHECK-NEXT: int _d_counter_again = 0; // CHECK-NEXT: int counter_again = 0; // CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: clad::tape _t3 = {}; @@ -849,10 +808,7 @@ double fn12(double i, double j) { // CHECK-NEXT: _d_a += 1; // CHECK-NEXT: do { // CHECK-NEXT: { -// CHECK-NEXT: { -// CHECK-NEXT: counter = clad::pop(_t7); -// CHECK-NEXT: int _r_d3 = _d_counter; -// CHECK-NEXT: } +// CHECK-NEXT: counter = clad::pop(_t7); // CHECK-NEXT: { // CHECK-NEXT: do { // CHECK-NEXT: { @@ -860,17 +816,14 @@ double fn12(double i, double j) { // CHECK-NEXT: do { // CHECK-NEXT: { // CHECK-NEXT: a = clad::pop(_t6); -// CHECK-NEXT: double _r_d2 = _d_a; -// CHECK-NEXT: *_d_j += _r_d2; +// CHECK-NEXT: double _r_d1 = _d_a; +// CHECK-NEXT: *_d_j += _r_d1; // CHECK-NEXT: } // CHECK-NEXT: clad::back(_t5)--; // CHECK-NEXT: } while (clad::back(_t5)); // CHECK-NEXT: clad::pop(_t5); // CHECK-NEXT: } -// CHECK-NEXT: { -// CHECK-NEXT: counter_again = clad::pop(_t4); -// CHECK-NEXT: int _r_d1 = _d_counter_again; -// CHECK-NEXT: } +// CHECK-NEXT: counter_again = clad::pop(_t4); // CHECK-NEXT: { // CHECK-NEXT: a = clad::pop(_t3); // CHECK-NEXT: double _r_d0 = _d_a; @@ -883,10 +836,7 @@ double fn12(double i, double j) { // CHECK-NEXT: } while (clad::back(_t2)); // CHECK-NEXT: clad::pop(_t2); // CHECK-NEXT: } -// CHECK-NEXT: { -// CHECK-NEXT: _d_counter_again = 0; -// CHECK-NEXT: counter_again = clad::pop(_t1); -// CHECK-NEXT: } +// CHECK-NEXT: counter_again = clad::pop(_t1); // CHECK-NEXT: } // CHECK-NEXT: _t0--; // CHECK-NEXT: } while (_t0); @@ -895,7 +845,7 @@ double fn12(double i, double j) { double fn13(double i, double j) { double res = 0; int counter = 3; - for (; int k = counter; counter-=1) { + for (; float k = counter; counter-=1) { k += i + 2*j; double temp = k; res += temp; @@ -905,13 +855,12 @@ double fn13(double i, double j) { // CHECK: void fn13_grad(double i, double j, double *_d_i, double *_d_j) { // CHECK-NEXT: double _d_res = 0; -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: clad::tape _t1 = {}; -// CHECK-NEXT: int _d_k = 0; -// CHECK-NEXT: int k = 0; +// CHECK-NEXT: clad::tape _t1 = {}; +// CHECK-NEXT: float _d_k = 0; +// CHECK-NEXT: float k = 0; // CHECK-NEXT: clad::tape _t2 = {}; -// CHECK-NEXT: clad::tape _t3 = {}; +// CHECK-NEXT: clad::tape _t3 = {}; // CHECK-NEXT: clad::tape _t4 = {}; // CHECK-NEXT: double _d_temp = 0; // CHECK-NEXT: double temp = 0; @@ -932,14 +881,11 @@ double fn13(double i, double j) { // CHECK-NEXT: _d_res += 1; // CHECK-NEXT: for (; _t0; _t0--) { // CHECK-NEXT: { -// CHECK-NEXT: { -// CHECK-NEXT: counter = clad::pop(_t2); -// CHECK-NEXT: int _r_d0 = _d_counter; -// CHECK-NEXT: } +// CHECK-NEXT: counter = clad::pop(_t2); // CHECK-NEXT: { // CHECK-NEXT: res = clad::pop(_t5); -// CHECK-NEXT: double _r_d2 = _d_res; -// CHECK-NEXT: _d_temp += _r_d2; +// CHECK-NEXT: double _r_d1 = _d_res; +// CHECK-NEXT: _d_temp += _r_d1; // CHECK-NEXT: } // CHECK-NEXT: { // CHECK-NEXT: _d_k += _d_temp; @@ -948,13 +894,12 @@ double fn13(double i, double j) { // CHECK-NEXT: } // CHECK-NEXT: { // CHECK-NEXT: k = clad::pop(_t3); -// CHECK-NEXT: int _r_d1 = _d_k; -// CHECK-NEXT: *_d_i += _r_d1; -// CHECK-NEXT: *_d_j += 2 * _r_d1; +// CHECK-NEXT: float _r_d0 = _d_k; +// CHECK-NEXT: *_d_i += _r_d0; +// CHECK-NEXT: *_d_j += 2 * _r_d0; // CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: { -// CHECK-NEXT: _d_counter += _d_k; // CHECK-NEXT: _d_k = 0; // CHECK-NEXT: k = clad::pop(_t1); // CHECK-NEXT: } @@ -983,7 +928,6 @@ double fn14(double i, double j) { } // CHECK: void fn14_grad(double i, double j, double *_d_i, double *_d_j) { -// CHECK-NEXT: int _d_choice = 0; // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; // CHECK-NEXT: clad::tape _t2 = {}; @@ -1099,13 +1043,11 @@ double fn15(double i, double j) { } // CHECK: void fn15_grad(double i, double j, double *_d_i, double *_d_j) { -// CHECK-NEXT: int _d_choice = 0; // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; // CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: clad::tape _t3 = {}; // CHECK-NEXT: clad::tape _t4 = {}; -// CHECK-NEXT: int _d_another_choice = 0; // CHECK-NEXT: int another_choice = 0; // CHECK-NEXT: clad::tape _t5 = {}; // CHECK-NEXT: clad::tape _t7 = {}; @@ -1191,10 +1133,7 @@ double fn15(double i, double j) { // CHECK-NEXT: } // CHECK-NEXT: clad::pop(_t5); // CHECK-NEXT: } -// CHECK-NEXT: { -// CHECK-NEXT: _d_another_choice = 0; -// CHECK-NEXT: another_choice = clad::pop(_t4); -// CHECK-NEXT: } +// CHECK-NEXT: another_choice = clad::pop(_t4); // CHECK-NEXT: if (clad::pop(_t2)) // CHECK-NEXT: case {{1U|1UL}}: // CHECK-NEXT: ; @@ -1221,10 +1160,8 @@ double fn16(double i, double j) { } // CHECK: void fn16_grad(double i, double j, double *_d_i, double *_d_j) { -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_ii = 0; // CHECK-NEXT: int ii = 0; // CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: clad::tape _t3 = {}; @@ -1322,13 +1259,10 @@ double fn17(double i, double j) { } // CHECK: void fn17_grad(double i, double j, double *_d_i, double *_d_j) { -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_ii = 0; // CHECK-NEXT: int ii = 0; // CHECK-NEXT: clad::tape _t1 = {}; -// CHECK-NEXT: int _d_jj = 0; // CHECK-NEXT: int jj = 0; // CHECK-NEXT: clad::tape _t3 = {}; // CHECK-NEXT: clad::tape _t4 = {}; @@ -1421,11 +1355,7 @@ double fn17(double i, double j) { // CHECK-NEXT: if (clad::pop(_t3)) // CHECK-NEXT: case {{1U|1UL}}: // CHECK-NEXT: ; -// CHECK-NEXT: { -// CHECK-NEXT: _d_ii += _d_jj; -// CHECK-NEXT: _d_jj = 0; -// CHECK-NEXT: jj = clad::pop(_t1); -// CHECK-NEXT: } +// CHECK-NEXT: jj = clad::pop(_t1); // CHECK-NEXT: } // CHECK-NEXT: } @@ -1445,10 +1375,8 @@ double fn18(double i, double j) { } // CHECK: void fn18_grad(double i, double j, double *_d_i, double *_d_j) { -// CHECK-NEXT: int _d_choice = 0; // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: int counter = 0; // CHECK-NEXT: clad::tape _t2 = {}; // CHECK-NEXT: clad::tape _t3 = {}; @@ -1523,10 +1451,8 @@ double fn19(double* arr, int n) { } // CHECK: void fn19_grad_0(double *arr, int n, double *_d_arr) { -// CHECK-NEXT: int _d_n = 0; // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: clad::tape _t2 = {}; @@ -1623,10 +1549,8 @@ double fn20(double *arr, int n) { } // CHECK: void fn20_grad_0(double *arr, int n, double *_d_arr) { -// CHECK-NEXT: int _d_n = 0; // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: clad::tape _t2 = {}; @@ -1668,7 +1592,6 @@ double fn21(double x) { // CHECK: void fn21_grad(double x, double *_d_x) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape > _t1 = {}; // CHECK-NEXT: double _d_arr[3] = {0}; @@ -1729,12 +1652,12 @@ int main() { double p[] = { 1, 2, 3, 4, 5 }; for (int i = 0; i < 5; i++) result[i] = 0; - auto f_sum_grad = clad::gradient(f_sum, "p"); + auto f_sum_grad = clad::gradient(f_sum); f_sum_grad.execute(p, 5, result); printf("{%.2f, %.2f, %.2f, %.2f, %.2f}\n", result[0], result[1], result[2], result[3], result[4]); // CHECK-EXEC: {1.00, 1.00, 1.00, 1.00, 1.00} for (int i = 0; i < 5; i++) result[i] = 0; - auto f_sum_squares_grad = clad::gradient(f_sum_squares, "p"); + auto f_sum_squares_grad = clad::gradient(f_sum_squares); f_sum_squares_grad.execute(p, 5, result); printf("{%.2f, %.2f, %.2f, %.2f, %.2f}\n", result[0], result[1], result[2], result[3], result[4]); // CHECK-EXEC: {2.00, 4.00, 6.00, 8.00, 10.00} @@ -1759,7 +1682,7 @@ int main() { TEST_2(fn17, 3, 5); // CHECK-EXEC: {15.00, 9.00} TEST_2(fn18, 3, 5); // CHECK-EXEC: {4.00, 4.00} - INIT_GRADIENT(fn19, "arr"); + INIT_GRADIENT(fn19); double arr[5] = {}; double d_arr[5] = {}; @@ -1768,7 +1691,7 @@ int main() { TEST_2(f_loop_init_var, 1, 2); // CHECK-EXEC: {-1.00, 4.00} for (int i = 0; i < 5; i++) result[i] = 0; - auto d_fn20 = clad::gradient(fn20, "arr"); + auto d_fn20 = clad::gradient(fn20); d_fn20.execute(x, 5, result); printf("{%.2f, %.2f, %.2f, %.2f, %.2f}\n", result[0], result[1], result[2], result[3], result[4]); // CHECK-EXEC: {5.00, 5.00, 5.00, 5.00, 5.00} diff --git a/test/Gradient/Pointers.C b/test/Gradient/Pointers.C index 5c594ca18..8f9cbfd57 100644 --- a/test/Gradient/Pointers.C +++ b/test/Gradient/Pointers.C @@ -168,29 +168,23 @@ double pointerParam(const double* arr, size_t n) { } // CHECK: void pointerParam_grad_0(const double *arr, size_t n, double *_d_arr) { -// CHECK-NEXT: size_t _d_n = 0; // CHECK-NEXT: double _d_sum = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: size_t _d_i = 0; // CHECK-NEXT: size_t i = 0; // CHECK-NEXT: clad::tape _t1 = {}; -// CHECK-NEXT: clad::tape _t3 = {}; -// CHECK-NEXT: size_t *_d_j = 0; // CHECK-NEXT: size_t *j = 0; -// CHECK-NEXT: clad::tape _t4 = {}; -// CHECK-NEXT: clad::tape _t5 = {}; -// CHECK-NEXT: clad::tape _t6 = {}; +// CHECK-NEXT: clad::tape _t2 = {}; +// CHECK-NEXT: clad::tape _t3 = {}; +// CHECK-NEXT: clad::tape _t4 = {}; // CHECK-NEXT: double sum = 0; // CHECK-NEXT: _t0 = 0; // CHECK-NEXT: for (i = 0; i < n; ++i) { // CHECK-NEXT: _t0++; -// CHECK-NEXT: _d_j = &_d_i; -// CHECK-NEXT: clad::push(_t1, _d_j); -// CHECK-NEXT: clad::push(_t3, j) , j = &i; -// CHECK-NEXT: clad::push(_t4, sum); +// CHECK-NEXT: clad::push(_t1, j) , j = &i; +// CHECK-NEXT: clad::push(_t2, sum); // CHECK-NEXT: sum += arr[0] * (*j); -// CHECK-NEXT: clad::push(_t5, arr); -// CHECK-NEXT: clad::push(_t6, _d_arr); +// CHECK-NEXT: clad::push(_t3, arr); +// CHECK-NEXT: clad::push(_t4, _d_arr); // CHECK-NEXT: _d_arr = _d_arr + 1; // CHECK-NEXT: arr = arr + 1; // CHECK-NEXT: } @@ -199,18 +193,16 @@ double pointerParam(const double* arr, size_t n) { // CHECK-NEXT: _d_sum += 1; // CHECK-NEXT: for (; _t0; _t0--) { // CHECK-NEXT: --i; -// CHECK-NEXT: size_t *_t2 = clad::pop(_t1); // CHECK-NEXT: { -// CHECK-NEXT: arr = clad::pop(_t5); -// CHECK-NEXT: _d_arr = clad::pop(_t6); +// CHECK-NEXT: arr = clad::pop(_t3); +// CHECK-NEXT: _d_arr = clad::pop(_t4); // CHECK-NEXT: } // CHECK-NEXT: { -// CHECK-NEXT: sum = clad::pop(_t4); +// CHECK-NEXT: sum = clad::pop(_t2); // CHECK-NEXT: double _r_d0 = _d_sum; // CHECK-NEXT: _d_arr[0] += _r_d0 * (*j); -// CHECK-NEXT: *_t2 += arr[0] * _r_d0; // CHECK-NEXT: } -// CHECK-NEXT: j = clad::pop(_t3); +// CHECK-NEXT: j = clad::pop(_t1); // CHECK-NEXT: } // CHECK-NEXT: } @@ -443,7 +435,6 @@ double cStyleMemoryAlloc(double x, size_t n) { } // CHECK: void cStyleMemoryAlloc_grad_0(double x, size_t n, double *_d_x) { -// CHECK-NEXT: size_t _d_n = 0; // CHECK-NEXT: T *_d_t = 0; // CHECK-NEXT: double _t0; // CHECK-NEXT: double *_d_p = 0; @@ -592,7 +583,7 @@ int main() { d_arrayPointer.execute(arr, d_arr); printf("%.2f %.2f %.2f %.2f %.2f\n", d_arr[0], d_arr[1], d_arr[2], d_arr[3], d_arr[4]); // CHECK-EXEC: 5.00 1.00 2.00 4.00 3.00 - auto d_pointerParam = clad::gradient(pointerParam, "arr"); + auto d_pointerParam = clad::gradient(pointerParam); d_arr[0] = d_arr[1] = d_arr[2] = d_arr[3] = d_arr[4] = 0; d_pointerParam.execute(arr, 5, d_arr); printf("%.2f %.2f %.2f %.2f %.2f\n", d_arr[0], d_arr[1], d_arr[2], d_arr[3], d_arr[4]); // CHECK-EXEC: 0.00 1.00 2.00 3.00 4.00 @@ -615,7 +606,7 @@ int main() { d_structPointer.execute(5, &d_x); printf("%.2f\n", d_x); // CHECK-EXEC: 1.00 - auto d_cStyleMemoryAlloc = clad::gradient(cStyleMemoryAlloc, "x"); + auto d_cStyleMemoryAlloc = clad::gradient(cStyleMemoryAlloc); d_x = 0; d_cStyleMemoryAlloc.execute(5, 7, &d_x); printf("%.2f\n", d_x); // CHECK-EXEC: 4.00 diff --git a/test/Gradient/Switch.C b/test/Gradient/Switch.C index d8a1d24e0..e7e5e2ca3 100644 --- a/test/Gradient/Switch.C +++ b/test/Gradient/Switch.C @@ -20,7 +20,6 @@ double fn1(double i, double j) { // CHECK: void fn1_grad(double i, double j, double *_d_i, double *_d_j) { // CHECK-NEXT: double _d_res = 0; -// CHECK-NEXT: int _d_count = 0; // CHECK-NEXT: int _cond0; // CHECK-NEXT: double _t0; // CHECK-NEXT: clad::tape _t1 = {}; @@ -133,7 +132,6 @@ double fn2(double i, double j) { // CHECK: void fn2_grad(double i, double j, double *_d_i, double *_d_j) { // CHECK-NEXT: double _d_res = 0; -// CHECK-NEXT: int _d_count = 0; // CHECK-NEXT: int count = 0; // CHECK-NEXT: int _cond0; // CHECK-NEXT: double _t0; @@ -267,7 +265,6 @@ double fn3(double i, double j) { // CHECK: void fn3_grad(double i, double j, double *_d_i, double *_d_j) { // CHECK-NEXT: double _d_res = 0; -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; // CHECK-NEXT: clad::tape _cond0 = {}; // CHECK-NEXT: clad::tape _t1 = {}; @@ -395,7 +392,6 @@ double fn4(double i, double j) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: double _t0; // CHECK-NEXT: clad::tape _t1 = {}; -// CHECK-NEXT: int _d_counter = 0; // CHECK-NEXT: int counter = 0; // CHECK-NEXT: unsigned {{int|long}} _t2; // CHECK-NEXT: clad::tape _t3 = {}; @@ -482,7 +478,6 @@ double fn5(double i, double j) { // CHECK: void fn5_grad(double i, double j, double *_d_i, double *_d_j) { // CHECK-NEXT: double _d_res = 0; -// CHECK-NEXT: int _d_count = 0; // CHECK-NEXT: int count = 0; // CHECK-NEXT: int _cond0; // CHECK-NEXT: double _t0; @@ -518,9 +513,10 @@ double fn5(double i, double j) { // CHECK-NEXT: } double fn6(double u, double v) { - int res = 0; + float res = 0; + int count; double temp = 0; - switch(res = u * v) { + switch(count = res = u * v) { default: temp = 1; } @@ -528,37 +524,40 @@ double fn6(double u, double v) { } // CHECK: void fn6_grad(double u, double v, double *_d_u, double *_d_v) { -// CHECK-NEXT: int _d_res = 0; +// CHECK-NEXT: float _d_res = 0; // CHECK-NEXT: double _d_temp = 0; // CHECK-NEXT: int _t0; +// CHECK-NEXT: float _t1; // CHECK-NEXT: int _cond0; -// CHECK-NEXT: double _t1; -// CHECK-NEXT: clad::tape _t2 = {}; -// CHECK-NEXT: int res = 0; +// CHECK-NEXT: double _t2; +// CHECK-NEXT: clad::tape _t3 = {}; +// CHECK-NEXT: float res = 0; +// CHECK-NEXT: int count; // CHECK-NEXT: double temp = 0; // CHECK-NEXT: { -// CHECK-NEXT: _t0 = res; -// CHECK-NEXT: res = u * v; -// CHECK-NEXT: _cond0 = res = u * v; +// CHECK-NEXT: _t0 = count; +// CHECK-NEXT: _t1 = res; +// CHECK-NEXT: count = res = u * v; +// CHECK-NEXT: _cond0 = count = res = u * v; // CHECK-NEXT: switch (_cond0) { // CHECK-NEXT: { // CHECK-NEXT: default: // CHECK-NEXT: temp = 1; -// CHECK-NEXT: _t1 = temp; +// CHECK-NEXT: _t2 = temp; // CHECK-NEXT: } -// CHECK-NEXT: clad::push(_t2, {{1U|1UL}}); +// CHECK-NEXT: clad::push(_t3, {{1U|1UL}}); // CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: goto _label0; // CHECK-NEXT: _label0: // CHECK-NEXT: _d_res += 1; // CHECK-NEXT: { -// CHECK-NEXT: switch (clad::pop(_t2)) { +// CHECK-NEXT: switch (clad::pop(_t3)) { // CHECK-NEXT: case {{1U|1UL}}: // CHECK-NEXT: ; // CHECK-NEXT: { // CHECK-NEXT: { -// CHECK-NEXT: temp = _t1; +// CHECK-NEXT: temp = _t2; // CHECK-NEXT: double _r_d1 = _d_temp; // CHECK-NEXT: _d_temp -= _r_d1; // CHECK-NEXT: } @@ -567,8 +566,9 @@ double fn6(double u, double v) { // CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: { -// CHECK-NEXT: res = _t0; -// CHECK-NEXT: int _r_d0 = _d_res; +// CHECK-NEXT: count = _t0; +// CHECK-NEXT: res = _t1; +// CHECK-NEXT: float _r_d0 = _d_res; // CHECK-NEXT: _d_res -= _r_d0; // CHECK-NEXT: *_d_u += _r_d0 * v; // CHECK-NEXT: *_d_v += u * _r_d0; @@ -597,7 +597,6 @@ double fn7(double u, double v) { // CHECK: void fn7_grad(double u, double v, double *_d_u, double *_d_v) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _cond0 = {}; // CHECK-NEXT: clad::tape _t1 = {}; diff --git a/test/Gradient/SwitchInit.C b/test/Gradient/SwitchInit.C index e75fe84c0..fd14b4706 100644 --- a/test/Gradient/SwitchInit.C +++ b/test/Gradient/SwitchInit.C @@ -18,7 +18,6 @@ double fn1(double i, double j) { // CHECK: void fn1_grad(double i, double j, double *_d_i, double *_d_j) { // CHECK-NEXT: double _d_res = 0; -// CHECK-NEXT: int _d_count = 0; // CHECK-NEXT: int count = 0; // CHECK-NEXT: int _cond0; // CHECK-NEXT: double _t0; diff --git a/test/Gradient/TestTypeConversion.C b/test/Gradient/TestTypeConversion.C index 716bf97e7..ce7b7365c 100644 --- a/test/Gradient/TestTypeConversion.C +++ b/test/Gradient/TestTypeConversion.C @@ -10,17 +10,16 @@ #include "../TestUtils.h" -float fn_type_conversion(float z, int a) { +float fn_type_conversion(float z, double a) { for (int i = 1; i < a; i++){ z = z * a; } return z; } -void fn_type_conversion_grad(float z, int a, float *_d_z, int *_d_a); -// CHECK: void fn_type_conversion_grad(float z, int a, float *_d_z, int *_d_a) { +void fn_type_conversion_grad(float z, double a, float *_d_z, double *_d_a); +// CHECK: void fn_type_conversion_grad(float z, double a, float *_d_z, double *_d_a) { // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: _t0 = 0; @@ -55,7 +54,7 @@ void fn_type_conversion_grad(float z, int a, float *_d_z, int *_d_a); int main() { float result_0; - int result_1; + double result_1; INIT_GRADIENT(fn_type_conversion); - TEST_GRADIENT(fn_type_conversion, /*numOfDerivativeArgs=*/2, 4, 3, &result_0, &result_1); // CHECK-EXEC: {9.00, 24} + TEST_GRADIENT(fn_type_conversion, /*numOfDerivativeArgs=*/2, 4, 3, &result_0, &result_1); // CHECK-EXEC: {9.00, 24.00} } diff --git a/test/Gradient/UserDefinedTypes.C b/test/Gradient/UserDefinedTypes.C index 37ac0bb37..b9722672f 100644 --- a/test/Gradient/UserDefinedTypes.C +++ b/test/Gradient/UserDefinedTypes.C @@ -322,7 +322,6 @@ double fn9(Tangent t, dcomplex c) { // CHECK: void fn9_grad(Tangent t, dcomplex c, Tangent *_d_t, dcomplex *_d_c) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: clad::tape _t2 = {}; @@ -407,7 +406,6 @@ int main() { // CHECK: void sum_pullback(Tangent &t, double _d_y, Tangent *_d_t) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double res = 0; @@ -431,7 +429,6 @@ int main() { // CHECK: void sum_pullback(double *data, double _d_y, double *_d_data) { // CHECK-NEXT: double _d_res = 0; // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: double res = 0; @@ -490,7 +487,6 @@ int main() { // CHECK: void updateTo_pullback(double d, Tangent *_d_this, double *_d_d) { // CHECK-NEXT: unsigned {{int|long}} _t0; -// CHECK-NEXT: int _d_i = 0; // CHECK-NEXT: int i = 0; // CHECK-NEXT: clad::tape _t1 = {}; // CHECK-NEXT: _t0 = 0; diff --git a/test/Jacobian/Functors.C b/test/Jacobian/Functors.C index 001ac66ce..a3b29c5d4 100644 --- a/test/Jacobian/Functors.C +++ b/test/Jacobian/Functors.C @@ -75,9 +75,9 @@ struct ExperimentVolatile { // CHECK-NEXT: double _t0; // CHECK-NEXT: double _t1; // CHECK-NEXT: _t0 = this->x * i; - // CHECK-NEXT: output[0] = this->x * i * i * j; + // CHECK-NEXT: output[0] = _t0 * i * j; // CHECK-NEXT: _t1 = this->y * i; - // CHECK-NEXT: output[1] = this->y * i * j * j; + // CHECK-NEXT: output[1] = _t1 * j * j; // CHECK-NEXT: { // CHECK-NEXT: jacobianMatrix[{{2U|2UL}}] += this->y * 1 * j * j; // CHECK-NEXT: jacobianMatrix[{{3U|3UL}}] += _t1 * 1 * j; @@ -106,9 +106,9 @@ struct ExperimentConstVolatile { // CHECK-NEXT: double _t0; // CHECK-NEXT: double _t1; // CHECK-NEXT: _t0 = this->x * i; - // CHECK-NEXT: output[0] = this->x * i * i * j; + // CHECK-NEXT: output[0] = _t0 * i * j; // CHECK-NEXT: _t1 = this->y * i; - // CHECK-NEXT: output[1] = this->y * i * j * j; + // CHECK-NEXT: output[1] = _t1 * j * j; // CHECK-NEXT: { // CHECK-NEXT: jacobianMatrix[{{2U|2UL}}] += this->y * 1 * j * j; // CHECK-NEXT: jacobianMatrix[{{3U|3UL}}] += _t1 * 1 * j; diff --git a/test/Jacobian/Jacobian.C b/test/Jacobian/Jacobian.C index ffe52060c..526231a8f 100644 --- a/test/Jacobian/Jacobian.C +++ b/test/Jacobian/Jacobian.C @@ -57,11 +57,11 @@ void f_3_jac(double x, double y, double z, double *_result, double *jacobianMatr //CHECK-NEXT: double _t2; //CHECK-NEXT: double constant = 42; //CHECK-NEXT: _t0 = sin(x); -//CHECK-NEXT: _result[0] = sin(x) * constant; +//CHECK-NEXT: _result[0] = _t0 * constant; //CHECK-NEXT: _t1 = sin(y); -//CHECK-NEXT: _result[1] = sin(y) * constant; +//CHECK-NEXT: _result[1] = _t1 * constant; //CHECK-NEXT: _t2 = sin(z); -//CHECK-NEXT: _result[2] = sin(z) * constant; +//CHECK-NEXT: _result[2] = _t2 * constant; //CHECK-NEXT: { //CHECK-NEXT: double _r2 = 0; //CHECK-NEXT: _r2 += 1 * constant * clad::custom_derivatives::sin_pushforward(z, 1.).pushforward; @@ -98,11 +98,11 @@ void f_4_jac(double x, double y, double z, double *_result, double *jacobianMatr //CHECK-NEXT: double _t2; //CHECK-NEXT: double constant = 42; //CHECK-NEXT: _t0 = multiply(x, y); -//CHECK-NEXT: _result[0] = multiply(x, y) * constant; +//CHECK-NEXT: _result[0] = _t0 * constant; //CHECK-NEXT: _t1 = multiply(y, z); -//CHECK-NEXT: _result[1] = multiply(y, z) * constant; +//CHECK-NEXT: _result[1] = _t1 * constant; //CHECK-NEXT: _t2 = multiply(z, x); -//CHECK-NEXT: _result[2] = multiply(z, x) * constant; +//CHECK-NEXT: _result[2] = _t2 * constant; //CHECK-NEXT: { //CHECK-NEXT: double _r4 = 0; //CHECK-NEXT: double _r5 = 0; diff --git a/test/Misc/RunDemos.C b/test/Misc/RunDemos.C index d92406659..5320533c1 100644 --- a/test/Misc/RunDemos.C +++ b/test/Misc/RunDemos.C @@ -106,10 +106,9 @@ // RUN: %cladclang %S/../../demos/ErrorEstimation/FloatSum.cpp -I%S/../../include 2>&1 | FileCheck -check-prefix CHECK_FLOAT_SUM %s //CHECK_FLOAT_SUM-NOT: {{.*error|warning|note:.*}} -//CHECK_FLOAT_SUM: void vanillaSum_grad(float x, unsigned int n, float *_d_x, unsigned int *_d_n, double &_final_error) { +//CHECK_FLOAT_SUM: void vanillaSum_grad_0(float x, unsigned int n, float *_d_x, double *_final_error) { //CHECK_FLOAT_SUM: float _d_sum = 0; //CHECK_FLOAT_SUM: unsigned {{int|long}} _t0; -//CHECK_FLOAT_SUM: unsigned int _d_i = 0; //CHECK_FLOAT_SUM: unsigned int i = 0; //CHECK_FLOAT_SUM: clad::tape _t1 = {}; //CHECK_FLOAT_SUM: float sum = 0.; @@ -125,7 +124,7 @@ //CHECK_FLOAT_SUM: for (; _t0; _t0--) { //CHECK_FLOAT_SUM: i--; //CHECK_FLOAT_SUM: { -//CHECK_FLOAT_SUM: _final_error += std::abs(_d_sum * sum * 1.1920928955078125E-7); +//CHECK_FLOAT_SUM: *_final_error += std::abs(_d_sum * sum * 1.1920928955078125E-7); //CHECK_FLOAT_SUM: sum = clad::pop(_t1); //CHECK_FLOAT_SUM: float _r_d0 = _d_sum; //CHECK_FLOAT_SUM: _d_sum -= _r_d0; @@ -133,8 +132,8 @@ //CHECK_FLOAT_SUM: *_d_x += _r_d0; //CHECK_FLOAT_SUM: } //CHECK_FLOAT_SUM: } -//CHECK_FLOAT_SUM: _final_error += std::abs(_d_sum * sum * 1.1920928955078125E-7); -//CHECK_FLOAT_SUM: _final_error += std::abs(*_d_x * x * 1.1920928955078125E-7); +//CHECK_FLOAT_SUM: *_final_error += std::abs(_d_sum * sum * 1.1920928955078125E-7); +//CHECK_FLOAT_SUM: *_final_error += std::abs(*_d_x * x * 1.1920928955078125E-7); //CHECK_FLOAT_SUM: } //-----------------------------------------------------------------------------/ @@ -150,7 +149,7 @@ // RUN: ./CustomModelTest.out | FileCheck -check-prefix CHECK_CUSTOM_MODEL_EXEC %s // CHECK_CUSTOM_MODEL_EXEC-NOT:{{.*error|warning|note:.*}} // CHECK_CUSTOM_MODEL_EXEC: The code is: -// CHECK_CUSTOM_MODEL_EXEC-NEXT: void func_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +// CHECK_CUSTOM_MODEL_EXEC-NEXT: void func_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { // CHECK_CUSTOM_MODEL_EXEC-NEXT: float _d_z = 0; // CHECK_CUSTOM_MODEL_EXEC-NEXT: float _t0; // CHECK_CUSTOM_MODEL_EXEC-NEXT: float z; @@ -160,15 +159,15 @@ // CHECK_CUSTOM_MODEL_EXEC-NEXT: _label0: // CHECK_CUSTOM_MODEL_EXEC-NEXT: _d_z += 1; // CHECK_CUSTOM_MODEL_EXEC-NEXT: { -// CHECK_CUSTOM_MODEL_EXEC-NEXT: _final_error += _d_z * z; +// CHECK_CUSTOM_MODEL_EXEC-NEXT: *_final_error += _d_z * z; // CHECK_CUSTOM_MODEL_EXEC-NEXT: z = _t0; // CHECK_CUSTOM_MODEL_EXEC-NEXT: float _r_d0 = _d_z; // CHECK_CUSTOM_MODEL_EXEC-NEXT: _d_z -= _r_d0; // CHECK_CUSTOM_MODEL_EXEC-NEXT: *_d_x += _r_d0; // CHECK_CUSTOM_MODEL_EXEC-NEXT: *_d_y += _r_d0; // CHECK_CUSTOM_MODEL_EXEC-NEXT: } -// CHECK_CUSTOM_MODEL_EXEC-NEXT: _final_error += *_d_x * x; -// CHECK_CUSTOM_MODEL_EXEC-NEXT: _final_error += *_d_y * y; +// CHECK_CUSTOM_MODEL_EXEC-NEXT: *_final_error += *_d_x * x; +// CHECK_CUSTOM_MODEL_EXEC-NEXT: *_final_error += *_d_y * y; // CHECK_CUSTOM_MODEL_EXEC-NEXT: } //-----------------------------------------------------------------------------/ @@ -184,7 +183,7 @@ // RUN: ./PrintModelTest.out | FileCheck -check-prefix CHECK_PRINT_MODEL_EXEC %s // CHECK_PRINT_MODEL_EXEC-NOT:{{.*error|warning|note:.*}} // CHECK_PRINT_MODEL_EXEC: The code is: -// CHECK_PRINT_MODEL_EXEC-NEXT: void func_grad(float x, float y, float *_d_x, float *_d_y, double &_final_error) { +// CHECK_PRINT_MODEL_EXEC-NEXT: void func_grad(float x, float y, float *_d_x, float *_d_y, double *_final_error) { // CHECK_PRINT_MODEL_EXEC-NEXT: float _d_z = 0; // CHECK_PRINT_MODEL_EXEC-NEXT: float _t0; // CHECK_PRINT_MODEL_EXEC-NEXT: float z; @@ -194,15 +193,15 @@ // CHECK_PRINT_MODEL_EXEC-NEXT: _label0: // CHECK_PRINT_MODEL_EXEC-NEXT: _d_z += 1; // CHECK_PRINT_MODEL_EXEC-NEXT: { -// CHECK_PRINT_MODEL_EXEC-NEXT: _final_error += clad::getErrorVal(_d_z, z, "z"); +// CHECK_PRINT_MODEL_EXEC-NEXT: *_final_error += clad::getErrorVal(_d_z, z, "z"); // CHECK_PRINT_MODEL_EXEC-NEXT: z = _t0; // CHECK_PRINT_MODEL_EXEC-NEXT: float _r_d0 = _d_z; // CHECK_PRINT_MODEL_EXEC-NEXT: _d_z -= _r_d0; // CHECK_PRINT_MODEL_EXEC-NEXT: *_d_x += _r_d0; // CHECK_PRINT_MODEL_EXEC-NEXT: *_d_y += _r_d0; // CHECK_PRINT_MODEL_EXEC-NEXT: } -// CHECK_PRINT_MODEL_EXEC-NEXT: _final_error += clad::getErrorVal(*_d_x, x, "x"); -// CHECK_PRINT_MODEL_EXEC-NEXT: _final_error += clad::getErrorVal(*_d_y, y, "y"); +// CHECK_PRINT_MODEL_EXEC-NEXT: *_final_error += clad::getErrorVal(*_d_x, x, "x"); +// CHECK_PRINT_MODEL_EXEC-NEXT: *_final_error += clad::getErrorVal(*_d_y, y, "y"); // CHECK_PRINT_MODEL_EXEC-NEXT: } // CHECK_PRINT_MODEL_EXEC: Error in z : {{.+}} // CHECK_PRINT_MODEL_EXEC-NEXT: Error in x : {{.+}} 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; diff --git a/test/NumericalDiff/NoNumDiff.C b/test/NumericalDiff/NoNumDiff.C index d958c23e1..cc83baecc 100644 --- a/test/NumericalDiff/NoNumDiff.C +++ b/test/NumericalDiff/NoNumDiff.C @@ -8,8 +8,8 @@ double func(double x) { return std::tanh(x); } -//CHECK: warning: Numerical differentiation is diabled using the -DCLAD_NO_NUM_DIFF flag, this means that every try to numerically differentiate a function will fail! Remove the flag to revert to default behaviour. -//CHECK: warning: Numerical differentiation is diabled using the -DCLAD_NO_NUM_DIFF flag, this means that every try to numerically differentiate a function will fail! Remove the flag to revert to default behaviour. +//CHECK: warning: Numerical differentiation is disabled using the -DCLAD_NO_NUM_DIFF flag, this means that every try to numerically differentiate a function will fail! Remove the flag to revert to default behaviour. +//CHECK: warning: Numerical differentiation is disabled using the -DCLAD_NO_NUM_DIFF flag, this means that every try to numerically differentiate a function will fail! Remove the flag to revert to default behaviour. //CHECK: double func_darg0(double x) { //CHECK-NEXT: double _d_x = 1; //CHECK-NEXT: return 0;